-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathFuzzyJava.g
executable file
·85 lines (67 loc) · 1.63 KB
/
FuzzyJava.g
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
lexer grammar FuzzyJava;
options {language=JavaScript; filter=true;}
IMPORT
: 'import' WS name=QIDStar WS? ';'
;
/** Avoids having "return foo;" match as a field */
RETURN
: 'return' (options {greedy=false;}:.)* ';'
;
CLASS
: 'class' WS name=ID WS? ('extends' WS QID WS?)?
('implements' WS QID WS? (',' WS? QID WS?)*)? '{'
{print("found class "+$name.text);}
;
METHOD
: TYPE WS name=ID WS? '(' ( ARG WS? (',' WS? ARG WS?)* )? ')' WS?
('throws' WS QID WS? (',' WS? QID WS?)*)? '{'
{print("found method "+$name.text);}
;
FIELD
: TYPE WS name=ID '[]'? WS? (';'|'=')
{print("found var "+$name.text);}
;
STAT: ('if'|'while'|'switch'|'for') WS? '(' ;
CALL
: name=QID WS? '('
{/*ignore if this/super */ print("found call "+$name.text);}
;
COMMENT
: '/*' (options {greedy=false;} : . )* '*/'
{print("found comment "+ this.getText());}
;
SL_COMMENT
: '//' (options {greedy=false;} : . )* '\n'
{print("found // comment "+ this.getText());}
;
STRING
: '"' (options {greedy=false;}: ESC | .)* '"'
;
CHAR
: '\'' (options {greedy=false;}: ESC | .)* '\''
;
WS : (' '|'\t'|'\n')+
;
fragment
QID : ID ('.' ID)*
;
/** QID cannot see beyond end of token so using QID '.*'? somewhere won't
* ever match since k=1 lookahead in the QID loop of '.' will make it loop.
* I made this rule to compensate.
*/
fragment
QIDStar
: ID ('.' ID)* '.*'?
;
fragment
TYPE: QID '[]'?
;
fragment
ARG : TYPE WS ID
;
fragment
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
;
fragment
ESC : '\\' ('"'|'\''|'\\')
;