Last active
October 8, 2023 04:35
-
-
Save LdBeth/8277950958b964d0778d70ffd3d998de to your computer and use it in GitHub Desktop.
IXML grammar for J
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jsource : line++NL . | |
{ "https://johnlumley.github.io/jwiXML.xhtml" } | |
{ Number constant } | |
-number : integer; float; complex; extend; power; radian; radix . | |
-uptofloat : integer; float . | |
-uptocomplex : uptofloat; complex . | |
radix : (uptocomplex; power; radian), -"b", rdxstr . | |
@rdxstr : ["0"-"9";"a"-"z"]+ . | |
radian : uptofloat, rtype, uptofloat . | |
@rtype : "ar"; "ad" . | |
power : uptocomplex, ptype, uptocomplex . | |
@ptype : "r"; "p"; "x" . | |
extend : integer, -"x" . | |
complex : uptofloat, -'j', uptofloat . | |
integer : "_"?, digit+ . | |
float : "_" ; "__" ; ("_"?, digit+, | |
(point; (point?, @expnt))) . | |
-point : ".", digit* . | |
@expnt : -"e", "_"?, digit+ . | |
{ Name } | |
name : alpha, (alpha; digit)**("_"?), locale? . | |
-locale : locale-name; locale-var . | |
locale-name : -"_", (alpha; digit)*, -"_" . | |
locale-var : -"__", alpha, (alpha; digit)*, locale? . | |
{ Primary } | |
single : graphic . | |
trail : (":"; ".")+ . | |
multip : -single, -trail . | |
keyword : ["a"-"z"], (alpha; "_"; digit)+, "." . | |
aword : alpha, -trail . | |
num_const : "_"?, ("_"; ["0"-"9"]), ":" . | |
left_cur : "{" . | |
right_cur : "}" . | |
left_cur_mul : "{" , -trail . | |
right_cur_mul : "}" , -trail . | |
-valid_after_any : valid_single; valid_multip; valid_paren . | |
-valid_after_const : valid_after_any; valid_direct; | |
valid_left_cur; valid_right_cur; valid_left_cur_mul; valid_right_cur_mul . | |
-valid_after_trail : valid_after_any; valid_direct; | |
valid_aword; valid_keyword; valid_number; valid_name; valid_string; | |
valid_num_const; | |
valid_left_cur; valid_right_cur; valid_left_cur_mul; valid_right_cur_mul . | |
-valid_after_cur : valid_after_any; valid_right_cur_mul; valid_left_cur_mul; | |
valid_aword; valid_keyword; valid_number; valid_name; valid_string; | |
valid_num_const . | |
{ Ends with trail } | |
-valid_single : single, valid_after_trail? . | |
-valid_trail : trail, valid_after_trail? . | |
-valid_multip : multip, valid_after_trail? . | |
-valid_aword : aword, valid_after_trail? . | |
-valid_keyword : keyword, valid_after_trail? . | |
-valid_left_cur_mul : left_cur_mul, valid_after_trail? . | |
-valid_right_cur_mul : right_cur_mul, valid_after_trail? . | |
-valid_num_const : num_const, valid_after_trail? . | |
{ Handle curly brackts } | |
-valid_left_cur : left_cur, (valid_after_cur; valid_right_cur)? . | |
-valid_right_cur : right_cur, (valid_after_cur; valid_left_cur; valid_direct)? . | |
-valid_name : name, (valid_after_const; valid_string)? . | |
-valid_string : string, (valid_after_const; valid_name; | |
valid_number; valid_trail; valid_aword; valid_keyword; valid_num_const)? . | |
-valid_number : number, (valid_after_const; valid_string)? . | |
{ Paren expr } | |
-valid_paren : paren, group? . | |
-valid_direct : direct, (valid_after_cur; valid_left_cur; valid_left_cur_mul)? . | |
{ String } | |
string : "'", (~["'"; #d; #a ]; "''")* , "'" . | |
{ Group } | |
-group : valid_single; valid_trail; valid_multip; valid_aword; valid_keyword; | |
valid_left_cur_mul; valid_right_cur_mul; valid_left_cur; valid_right_cur; | |
valid_name; valid_string; valid_number; valid_num_const; | |
valid_paren; valid_direct . | |
line : blank; comment; (WHITE?, group++WHITE, WHITE?, comment?); ')'. | |
@blank : -" "*, +"blank" . | |
paren : -"(", WHITE?, group++WHITE, WHITE?, -")" . | |
direct : -"{{", kind?, (multiline; oneline), -"}}" . | |
@kind : -")", ['mdvacn*'] . | |
-multiline : (line, NL)+, ((WHITE?, group++WHITE, WHITE?); WHITE)? . | |
-oneline : WHITE?, group++WHITE, WHITE? . | |
{ Comment } | |
comment : -"NB.", ~[#d; #a]* . | |
-NL: #d?, #a . | |
-WHITE: " "+ . | |
-alpha : ["a"-"z";"A"-"Z"] . | |
-digit : ["0"-"9"] . | |
-graphic : ["=<>+*-%$~|,;#!/\[]`@&?"; #5e; #22] . | |
{ Left right curly brackts are special } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment