Home | History | Annotate | Download | only in tests
      1 lexer grammar t020fuzzyLexer;
      2 options {
      3     language=Python;
      4     filter=true;
      5 }
      6 
      7 @header {
      8 from cStringIO import StringIO
      9 }
     10 
     11 @init {
     12 self.output = StringIO()
     13 }
     14 
     15 IMPORT
     16 	:	'import' WS name=QIDStar WS? ';'
     17 	;
     18 	
     19 /** Avoids having "return foo;" match as a field */
     20 RETURN
     21 	:	'return' (options {greedy=false;}:.)* ';'
     22 	;
     23 
     24 CLASS
     25 	:	'class' WS name=ID WS? ('extends' WS QID WS?)?
     26 		('implements' WS QID WS? (',' WS? QID WS?)*)? '{'
     27         {self.output.write("found class "+$name.text+"\n")}
     28 	;
     29 	
     30 METHOD
     31     :   TYPE WS name=ID WS? '(' ( ARG WS? (',' WS? ARG WS?)* )? ')' WS? 
     32        ('throws' WS QID WS? (',' WS? QID WS?)*)? '{'
     33         {self.output.write("found method "+$name.text+"\n");}
     34     ;
     35 
     36 FIELD
     37     :   TYPE WS name=ID '[]'? WS? (';'|'=')
     38         {self.output.write("found var "+$name.text+"\n");}
     39     ;
     40 
     41 STAT:	('if'|'while'|'switch'|'for') WS? '(' ;
     42 	
     43 CALL
     44     :   name=QID WS? '('
     45         {self.output.write("found call "+$name.text+"\n");}
     46     ;
     47 
     48 COMMENT
     49     :   '/*' (options {greedy=false;} : . )* '*/'
     50         {self.output.write("found comment "+self.getText()+"\n");}
     51     ;
     52 
     53 SL_COMMENT
     54     :   '//' (options {greedy=false;} : . )* '\n'
     55         {self.output.write("found // comment "+self.getText()+"\n");}
     56     ;
     57 	
     58 STRING
     59 	:	'"' (options {greedy=false;}: ESC | .)* '"'
     60 	;
     61 
     62 CHAR
     63 	:	'\'' (options {greedy=false;}: ESC | .)* '\''
     64 	;
     65 
     66 WS  :   (' '|'\t'|'\n')+
     67     ;
     68 
     69 fragment
     70 QID :	ID ('.' ID)*
     71 	;
     72 	
     73 /** QID cannot see beyond end of token so using QID '.*'? somewhere won't
     74  *  ever match since k=1 lookahead in the QID loop of '.' will make it loop.
     75  *  I made this rule to compensate.
     76  */
     77 fragment
     78 QIDStar
     79 	:	ID ('.' ID)* '.*'?
     80 	;
     81 
     82 fragment
     83 TYPE:   QID '[]'?
     84     ;
     85     
     86 fragment
     87 ARG :   TYPE WS ID
     88     ;
     89 
     90 fragment
     91 ID  :   ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
     92     ;
     93 
     94 fragment
     95 ESC	:	'\\' ('"'|'\''|'\\')
     96 	;
     97