1lexer grammar t020fuzzyLexer;
2options {
3    language=Python;
4    filter=true;
5}
6
7@header {
8from cStringIO import StringIO
9}
10
11@init {
12self.output = StringIO()
13}
14
15IMPORT
16	:	'import' WS name=QIDStar WS? ';'
17	;
18
19/** Avoids having "return foo;" match as a field */
20RETURN
21	:	'return' (options {greedy=false;}:.)* ';'
22	;
23
24CLASS
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
30METHOD
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
36FIELD
37    :   TYPE WS name=ID '[]'? WS? (';'|'=')
38        {self.output.write("found var "+$name.text+"\n");}
39    ;
40
41STAT:	('if'|'while'|'switch'|'for') WS? '(' ;
42
43CALL
44    :   name=QID WS? '('
45        {self.output.write("found call "+$name.text+"\n");}
46    ;
47
48COMMENT
49    :   '/*' (options {greedy=false;} : . )* '*/'
50        {self.output.write("found comment "+self.getText()+"\n");}
51    ;
52
53SL_COMMENT
54    :   '//' (options {greedy=false;} : . )* '\n'
55        {self.output.write("found // comment "+self.getText()+"\n");}
56    ;
57
58STRING
59	:	'"' (options {greedy=false;}: ESC | .)* '"'
60	;
61
62CHAR
63	:	'\'' (options {greedy=false;}: ESC | .)* '\''
64	;
65
66WS  :   (' '|'\t'|'\n')+
67    ;
68
69fragment
70QID :	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 */
77fragment
78QIDStar
79	:	ID ('.' ID)* '.*'?
80	;
81
82fragment
83TYPE:   QID '[]'?
84    ;
85
86fragment
87ARG :   TYPE WS ID
88    ;
89
90fragment
91ID  :   ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
92    ;
93
94fragment
95ESC	:	'\\' ('"'|'\''|'\\')
96	;
97