Home | History | Annotate | Download | only in functional
      1 grammar t014parser;
      2 options {
      3   language = JavaScript;
      4 }
      5 
      6 @parser::members {
      7 this.reportedErrors = [];
      8 this.events = [];
      9 this.emitErrorMessage = function(msg) {
     10     this.reportedErrors.push(msg);
     11 };
     12 this.eventMessage = function(msg) {
     13     this.events.push(msg);
     14 };
     15 }
     16         
     17 
     18 document:
     19         ( declaration
     20         | call
     21         )*
     22         EOF
     23     ;
     24 
     25 declaration:
     26         'var' t=IDENTIFIER ';'
     27         {this.eventMessage(['decl', $t.getText()]);}
     28     ;
     29 
     30 call:
     31         t=IDENTIFIER '(' ')' ';'
     32         {this.eventMessage(['call', $t.getText()]);}
     33     ;
     34 
     35 IDENTIFIER: ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;
     36 WS:  (' '|'\r'|'\t'|'\n') {$channel=HIDDEN;};
     37