Skip to content

Commit

Permalink
add isvalidkeyword
Browse files Browse the repository at this point in the history
  • Loading branch information
pzinn committed Nov 30, 2024
1 parent 1af84da commit 8df20ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion M2/Macaulay2/d/actors5.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export makeKeywordFun(e:Expr):Expr := (
is b1:Boolean do
when seq.3
is b2:Boolean do (
if !isvalidkeyword(s.v) then buildErrorPacket("invalid keyword") else (
u:=errorunary;
t:=errorbinary;
prec:=toInt(p);
Expand All @@ -42,7 +43,7 @@ export makeKeywordFun(e:Expr):Expr := (
else (
install(s.v,w); -- TODO check whether install is really needed (for mathematical symbols as opposed to words)
Expr(makeKeyword(w)))
)
))
else WrongArg(4,"a boolean")
else WrongArg(3,"a boolean")
else WrongArg(2,"an integer")
Expand Down
19 changes: 19 additions & 0 deletions M2/Macaulay2/d/ctype.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ CTRL := 64;
ALNUMEXTRA := 128;
HEX := 256;
BINARY := 512;
EXTRA := 1024;
SPACE := WHITE | NEWLINE;
ALPHA := UPPER | LOWER;
ALNUM := ALPHA | DIGIT | ALNUMEXTRA;
SPECIAL := DIGIT | SPACE | QUOTE | EXTRA;

foreach c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" do setchartype(c,UPPER);
foreach c in "abcdefghijklmnopqrstuvwxyz" do setchartype(c,LOWER);
Expand All @@ -24,6 +26,7 @@ foreach c in "01" do setchartype(c,BINARY);
foreach c in " \t\r" do setchartype(c,WHITE);
foreach c in "\n" do setchartype(c,NEWLINE);
foreach c in "$'" do setchartype(c,ALNUMEXTRA);
foreach c in ".#;," do setchartype(c,EXTRA);

for c from 128 to 255 do setchartype(char(c),ALPHA);
setchartype('\"',QUOTE);
Expand All @@ -40,6 +43,7 @@ export iswhite (c:int ):bool := (chartype(c) & WHITE ) != 0;
export isspace (c:int ):bool := (chartype(c) & SPACE ) != 0;
export isnewline (c:int ):bool := (chartype(c) & NEWLINE ) != 0;
export isquote (c:int ):bool := (chartype(c) & QUOTE ) != 0;
export isspecial (c:int ):bool := (chartype(c) & SPECIAL ) != 0;
export isdigit (c:char):bool := (chartype(c) & DIGIT ) != 0;
export ishex (c:char):bool := (chartype(c) & HEX ) != 0;
Expand All @@ -50,6 +54,7 @@ export iswhite (c:char):bool := (chartype(c) & WHITE ) != 0;
export isspace (c:char):bool := (chartype(c) & SPACE ) != 0;
export isnewline (c:char):bool := (chartype(c) & NEWLINE ) != 0;
export isquote (c:char):bool := (chartype(c) & QUOTE ) != 0;
export isspecial (c:char):bool := (chartype(c) & SPECIAL ) != 0;
-- c = two bytes concatenated
export ismathoperator(c:int):bool := (
Expand All @@ -76,6 +81,20 @@ export isvalidsymbol(s:string):bool := (
then return false);
true);
export isvalidkeyword(s:string):bool := (
if length(s)==0 then return false;
for i from 0 to length(s) - 1 do (
if isspecial(s.i) then return false;
if i<length(s)-1 then (
if s.i=='-' && (s.(i+1)=='*' || s.(i+1)=='-') then return false;
if s.i=='*' && s.(i+1)=='-' then return false;
if i<length(s)-2 then (
if s.i=='/' && s.(i+1)=='/' && s.(i+2)=='/' then return false;
));
);
true);
-- Local Variables:
-- compile-command: "echo \"make: Entering directory \\`$M2BUILDDIR/Macaulay2/d'\" && make -C $M2BUILDDIR/Macaulay2/d "
-- End:

0 comments on commit 8df20ab

Please sign in to comment.