Home | History | Annotate | Download | only in gnparser
      1 grammar gn;
      2 
      3 
      4 /*
      5  * Lexer Rules
      6  */
      7 
      8 r : statementlist EOF;
      9 
     10 
     11 
     12 //string     : '"' ( NLETTER | DIGIT | LETTER | Escape | expansion)* '"' ;
     13 
     14 //Escape     : '\\' ( '$' | '"' | NLETTER | DIGIT | LETTER) ;
     15 
     16 //bracketexpansion : '{' ( Identifier | arrayaccess | scopeaccess ) '}' ;
     17 
     18 //expansion        : '$' ( Identifier | bracketexpansion | HEX ) ;
     19 
     20 statement     : assignment | call | condition ;
     21 lvalue        : Identifier | arrayaccess | scopeaccess ;
     22 assignment    : lvalue AssignOp expr ;
     23 call          : Identifier '('  exprlist? ')' block? ;
     24 condition     : 'if' '(' expr ')' block
     25                (elsec ( condition | block ))? ;
     26 block         : '{' statementlist '}' ;
     27 statementlist  :  ( statement | comment )* ;
     28 arrayaccess   : Identifier '[' expr ']' ;
     29 scopeaccess   : Identifier '.' Identifier ;
     30 expr          : unaryexpr | expr BinaryOp expr ;
     31 unaryexpr     : primaryexpr | UnaryOp unaryexpr ;
     32 primaryexpr   : Identifier | Integer | String | call
     33               | arrayaccess | scopeaccess | block
     34               | '(' expr ')'
     35               | '[' ( exprlist  ','? )? ']' ;
     36 exprlist      : expr ( ',' expr )* ;
     37 elsec         : 'else' ;
     38 comment       : COMMENT ;
     39 
     40 
     41 AssignOp : '=' | '+=' | '-=' ;
     42 UnaryOp  : '!' ;
     43 BinaryOp : '+' | '-'
     44          | '<' | '<=' | '>' | '>='
     45          | '==' | '!='
     46          | '&&'
     47          | '||' ;
     48 
     49 Identifier : LETTER ( DIGIT | LETTER )* ;
     50 Integer    : '-'? DIGIT+ ;
     51 String     : '"' ('\\"'|~'"')* '"' ;
     52 
     53 fragment DIGIT  : [0-9] ;
     54 fragment LETTER : ([a-z] | [A-Z] | '_') ;
     55 COMMENT : '#' ~[\r\n]* '\r'? '\n' -> skip ;
     56 WS     : [ \r\n] -> skip ;
     57 
     58 //NLETTER   : ~[\r\n$"0-9a-zA-Z_] ;
     59 //HEX    : '0x' [0-9A-Fa-f]+ ;
     60 
     61