-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptableRefactorings.g
More file actions
180 lines (128 loc) · 3.26 KB
/
ScriptableRefactorings.g
File metadata and controls
180 lines (128 loc) · 3.26 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
grammar ScriptableRefactorings;
/* make it runnable */
@header {
import org.antlr.runtime.*;
}
@members {
public static void main(String[] args) throws Exception {
ANTLRInputStream input =
new ANTLRInputStream(System.in);
ScriptableRefactoringsLexer lexer =
new ScriptableRefactoringsLexer (input);
CommonTokenStream tokens =
new CommonTokenStream(lexer);
ScriptableRefactoringsParser parser =
new ScriptableRefactoringsParser(tokens);
parser.script();
}
} // end @members
/*** PARSER RULES ***/
script :
opts? refactoring+ EOF;
// opts is a section that allows options specific to the command
// line to be specified within the refactoring script file rather
// than on the command line.
opts : '@options' '{' ~('}')+ '}';
refactoring:
ID block ';'?;
block:
'{' parameterSequence (';' parameterSequence)* ';' '}';
parameterSequence:
parameter (',' parameter)*;
parameter
: simpleParameter
| namedParameter;
simpleParameter:
dataType;
namedParameter
: parameterName '=' dataType;
parameterName
: ID;
elementRegExp:
'/' ~'/'* '/';
dataType :
basicType
| positionMarker
| elementReference
| elementReferenceArray;
elementReference
: nonArrayElementComponent
(SCOPE_OPERATOR elementComponent)*
| SCOPE_OPERATOR elementComponent;
elementComponent
: elementId typeRestriction? indexRestriction?
| elementIdArray typeRestriction? indexRestriction?
| typeRestriction indexRestriction?;
nonArrayElementComponent
: elementId typeRestriction? indexRestriction?
| typeRestriction indexRestriction?;
// this restriction could be relaxed to support lists of valid
// elements, inverted sets, etc.
indexRestriction
: '[' INTEGER ']';
elementReferenceArray
: '[' elementReference (',' elementReference)* ']';
elementId
: ID
| elementRegExp;
elementIdArray
: '[' (ID | elementRegExp)
(',' (ID | elementRegExp))* ']';
positionMarker
: '@' '(' positionMarkerAtom
(('+'|'-') positionMarkerAtom)* ')';
positionMarkerAtom
: LINE_COLUMN_REFERENCE
| INTEGER
| elementReference
;
// I need to change this to a full blown expression grammar with &&,
// ||, !, and parenthesis.
typeRestriction
: '{' idExpr '}';
idExpr : idAtom (('||' | '&&') idAtom)*;
idAtom : ID
| '!' ID
| '(' idExpr ')';
idWithBackReferences
: ( 'a'..'z' | 'A'..'Z' | '_' | BACKREFERENCE)
( 'a'..'z' | 'A'..'Z' | '_' | DIGITS | BACKREFERENCE)*;
basicType
: STRING
| INTEGER
| LONG
| DOUBLE
| BOOLEAN
| LINE_COLUMN_REFERENCE;
/*** LEXER RULES ***/
WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+
{ $channel = HIDDEN; } ;
SINGLE_COMMENT
: '//' ~('\r' | '\n')* NEWLINE { skip(); };
MULTI_COMMENT
: '/*' (.*)'*/' NEWLINE? { skip(); };
ID : ( 'a'..'z' | 'A'..'Z' | '_' | BACKREFERENCE)
( 'a'..'z' | 'A'..'Z' | '_' | DIGITS | BACKREFERENCE )*;
STRING
: '"' ~'"'* '"';
SCOPE_OPERATOR
: '::';
INTEGER
: '1'..'9' DIGITS*;
LONG : INTEGER 'L';
BOOLEAN
: 'true' | 'false';
DOUBLE
: ('1'..'9' DIGITS*)? '.' DIGITS+;
LINE_COLUMN_REFERENCE
: INTEGER ':' INTEGER;
fragment ID_NO_BACKREFERENCES
: ( 'a'..'z' | 'A'..'Z' | '_' )
( 'a'..'z' | 'A'..'Z' | '_' | DIGITS)*;
fragment DIGITS
: '0'..'9';
fragment BACKREFERENCE
: '\\' INTEGER
| '(?P=' ID_NO_BACKREFERENCES ')';
fragment NEWLINE
: ('\r'? '\n')+;