Neo4查询语言Cypher3.0.7在antlr4下的文法(原创分享)

本人网上找了很久都没有一个比较好的cypher文法,于是花了一段时间研究cypher和编写基于antlr4下的cypher文法。

希望对想用做cypher相关工具的朋友有一点用,欢迎交流。

珍重声明:该文法经过测试,能够在ANTLRWorks2.1下正确运行,并通过了官网上示例测试。

但不表示完美的,如有朋友用它是发现问题,请提交问题到项目git下或者在文章下留言。

另外由于csdn没有转针对antrl文法代码的着色方案,因此选择了actionscript语言着色,还可以看。

 

 


官网示例:https://neo4j.com/docs/developer-manual/3.0/cypher/
项目git地址:https://github.com/yoyoma214/Cypher-Antlr4-Grammer

 

  1 /*
  2  * MIT license 
  3  * Copyright (C) 2016/12/10 adam
  4  */
  5  
  6 grammar Cypher;
  7 
  8 document: (unionQuery |  callClause | dropConstraint | dropIndexClause | importClause) ';'?;
  9 directive: CYPHER directiveItem (',' directiveItem )*;
 10 directiveItem:  id EQUAL expression ;
 11 createNode: CREATE assignGraphRelation (',' assignGraphRelation)*;
 12 unwind: UNWIND expression (AS id)? ;
 13 //merge;
 14 mergeClause: MERGE graphRelation mergeClauseOn*;
 15 mergeClauseOn:mergeOnCreate | mergeOnMatch;
 16 mergeOnCreate:  ON CREATE setClause;
 17 mergeOnMatch:  ON MATCH setClause;
 18 setClause: SET setClauseItem (',' setClauseItem)*;
 19 setClauseItem: assignExpression | setMap | setAddMap | setLabel ;
 20 setMap: id EQUAL(PARAMETER | nodePropertyList );
 21 setAddMap: id ADDEQUAL (PARAMETER | nodePropertyList );
 22 setLabel: id labelVar+;
 23 assignExpression: idPath EQUAL expression;
 24 procedure: idPath  expressionList? ;
 25 //index
 26 createIndexClause: CREATE INDEX ON labelVar '(' id ')';
 27 createUnique: CREATE UNIQUE graphRelation ( ',' graphRelation )*;
 28 useIndexClause: USING INDEX id labelVar '(' id ')';
 29 useScanClause: USING SCAN id labelVar ;
 30 useJoinClause: USING JOIN id (',' id)* ;
 31 dropIndexClause: DROP INDEX ON labelVar '(' id ')';
 32 callClause: CALL procedure (YIELD id)? returnClause?;
 33 createConstraint: CREATE CONSTRAINT ON (node | graphRelation) assert_;
 34 dropConstraint: DROP CONSTRAINT ON graphRelation assert_;
 35 assert_: ASSERT_ expression;
 36 unionQuery: directive? query unionClause* ;
 37 unionClause: UNION ALL? query;
 38 query: PROFILE? startClause?  (matchOrWith)* 
 39        modifyCluase*
 40        returnClause? ;
 41 modifyCluase:createClause | mergeClause |setClause | deleteClause | removeClause | foreachClause;
 42 startClause: START  assignGraphRelation (',' assignGraphRelation)*;
 43 matchOrWith: matchClause |  unwind  | withClause;
 44 createClause:  createIndexClause | createUnique | createConstraint | createNode   ; //| createNodeMap
 45 matchClause : matchClauseItem+ (useIndexClause | useScanClause | useJoinClause)*
 46         whereClause?  ;
 47 matchClauseItem: OPTIONAL? MATCH assignGraphRelation (',' assignGraphRelation)*;
 48 assignGraphRelation: (id EQUAL)? (relationIndex | nodeIndex | graphRelation |  builtInCall);
 49 nodeIndex:  NODE labelVar '(' (id EQUAL expression | indexQueryString) ')';
 50 relationIndex: RELATIONSHIP labelVar '(' (id EQUAL expression | indexQueryString) ')';
 51 indexQueryString:STRING;
 52 
 53 whereClause: WHERE expression ;
 54 fetchVar:  fetchOneVar | allVar;
 55 fetchOneVar:( DISTINCT? idPath | expression) (AS var)?;
 56 allVar: MULIT;
 57 withClause:WITH fetchVar(',' fetchVar)*  orderBy? skipClause? limitClause? whereClause?; 
 58 orderBy: ORDER BY orderByItem (',' orderByItem)*;
 59 orderByItem: idPath (ASC | DESC)?;
 60 skipClause: SKIP expression;
 61 limitClause: LIMIT expression;
 62 returnClause: RETURN fetchVar(',' fetchVar)* orderBy? skipClause? limitClause?;
 63 
 64 deleteClause: DETACH? DELETE deleteItem  (',' deleteItem)*;
 65 deleteItem:var | graphRelation;
 66 removeClause: removeLabel | removeProperty;
 67 removeLabel: REMOVE var+;
 68 removeProperty: REMOVE idPath;
 69 
 70 updateClause: SET updateItem (',' updateItem )*;
 71 updateItem: idPath EQUAL expression;
 72 
 73 foreachClause: FOREACH '(' var IN expression '|' (setClause | createClause) ')';
 74 
 75 nodePropertyList: json | PARAMETER;
 76 node : nodeEmpty | nodeNotEmpty ;
 77 nodeNotEmpty:  '(' id? labelVar*   nodePropertyList? ')' ;
 78 nodeEmpty: NIL;
 79 idPath: id ('.' id)*;
 80 
 81 graphRelation: node |  node relation*;
 82 relation: (relationToNext | relationToPrev | relationToBoth )
 83           node;
 84 
 85 relationToNext:'-' relationType?  ARROWAHEAD;
 86 relationToPrev:ARROWBACK relationType? '-';
 87 relationToBoth:'-' relationType? '-';
 88 relationType:  '['matchTag relationTypeRestrict? nodePropertyList? ']';
 89 matchTag: var? labelVar? ;
 90 relationTypeRestrict: relationTypeCounterRange | relationTypeCounterAll | relationTypeIdList ;
 91 relationTypeCounterRange: MULIT INTEGER? (DOUBLEDOT  INTEGER)? ; 
 92 relationTypeCounterAll: MULIT ALL ;
 93 relationTypeIdList: labelVar ('|' labelVar)*;
 94 
 95 importClause: usingPeriodicCommit?
 96               loadCvs
 97               matchClause?
 98               modifyCluase*;    
 99 
100 loadCvs:LOAD CSV (WITH HEADERS)? FROM STRING (AS id)? (FIELDTERMINATOR STRING)? ;
101 usingPeriodicCommit:USING PERIODIC COMMIT integerCypher?;
102 
103 //expression
104 expression   :   conditionalOrExpression ;
105 conditionalOrExpression   :   conditionalAndExpression ( OR conditionalAndExpression )* ;
106 conditionalAndExpression   :   valueLogical ( AND valueLogical )* ;
107 valueLogical   :   relationalExpression ;
108 
109 
110 argList   :   NIL | '(' DISTINCT? expression ( ',' expression )* ')'  ;
111 expressionList   :   NIL | '(' expression ( ',' expression )* ')'  ;
112 relationalExpression   : NOT? (relationalExpressionChain | relationalExpressionIsNull | relationalExpressionString | relationalExpressionIn | relationalExpresionExists | graphRelation | caseExpression | relationalIsUnique);
113 relationalExpressionIn:numericExpression (  IN expression | NOT IN expression )? ;
114 relationalExpressionChain: numericExpression relationalExpressionChainTtem* ;
115 relationalExpressionChainTtem:(LT | LT_EQUAL |GT | GT_EQUAL |EQUAL | NOT_EQUAL |XOR ) numericExpression;
116 
117 relationalExpressionIsNull: numericExpression IS NULL;
118 relationalExpressionString: relationalExpressionStartsWith | relationalExpressionEndsWith | relationalExpressionContains | relationalExpressionRegular;
119 relationalExpressionStartsWith: numericExpression STARTS WITH STRING;
120 relationalExpressionEndsWith: numericExpression ENDS WITH STRING;
121 relationalExpressionContains: numericExpression CONTAINS STRING;
122 relationalExpressionRegular:numericExpression EQUAL_REGUALR STRING;
123 
124 relationalIsUnique: idPath IS UNIQUE;
125 
126 relationalExpresionExists: EXISTS '(' expression ')';
127 
128 numericExpression   :   additiveExpression ;
129 
130 additiveExpression   :   multiplicativeExpression additiveExpressionRightPart* ;
131 
132 additiveExpressionRightPart:addMultiplicativeExpression | subtractionMultiplicativeExpression | additiveExpressionMulti;
133 
134 addMultiplicativeExpression : ADD multiplicativeExpression;
135 
136 subtractionMultiplicativeExpression: SUBTRACTION multiplicativeExpression ;
137 
138 multiplicativeExpression   :   unaryExpression multiplicativeExpressionItem* ;
139 
140 additiveExpressionMulti:
141                            numericLiteral  multiplicativeExpressionItem *
142                       ;
143 multiplicativeExpressionItem:
144                                  (MULIT | DIVISION) unaryExpression
145                              ;
146 unaryExpression   :     
147                       NEGATE primaryExpression 
148                     | ADD primaryExpression 
149                     | SUBTRACTION primaryExpression 
150                     | NOT primaryExpression
151                     | primaryExpression ;
152 
153 primaryExpression   :  
154                      caseExpression  
155                     |brackettedExpression 
156                     |anyVal  
157                     |listExpression 
158                     |list 
159                     |primaryExpressionChain;
160 
161 rangeExpression: '[' numericLiteral DOUBLEDOT numericLiteral ']';
162 primaryExpressionChain:
163                           primaryExpressionChainItem primaryExpressionChainRightPart*
164                       ;
165 
166 primaryExpressionChainRightPart:listFetch | '.' primaryExpressionChainItem | rangeExpression;
167 
168 primaryExpressionChainItem:
169                               builtInCall | id
170                           ;
171 
172 caseExpression: CASE expression? caseExpressionWhen+ caseExpressionElse? END ;
173 caseExpressionWhen: WHEN expression THEN  expression;
174 caseExpressionElse: ELSE expression;
175 listExpression: listExpressionAll | listExpressionAny | listExpressionNone | listExpressionSingle;
176 listExpressionExist:listExpressionAll | listExpressionAny | listExpressionNone | listExpressionSingle;
177 listExpressionAll: ALL '('var IN expression WHERE listExpressionCondition  ')';
178 listExpressionAny: ANY '('var IN expression WHERE listExpressionCondition  ')';
179 listExpressionNone: NONE '('var IN expression WHERE listExpressionCondition  ')';
180 listExpressionSingle: SINGLE '('var IN expression WHERE listExpressionCondition  ')';
181 listExpressionCondition:  EXISTS '(' idPath  ')' | expression ;
182 list: '[' anyVal (',' anyVal)* ']';
183 listFetch : '[' expression ']';
184 var : id ;
185 brackettedExpression   :   '(' expression ')' ;
186 builtInCall   :     pathFunc |  nodesFunc  | relationshipsFunc |extractFunc | filterFunc | absFunc | randFunc | roundFunc | sqrtFunc |signFunc | sinFunc | cosFunc | 
187            tanFunc | cotFunc |  asinFunc |  acosFunc | atanFunc |  atan2Func |  haversinFunc | degreesFunc | radiansFunc | pi | log10Func| logFunc | expFunc | e | countAllFunc |
188            countFunc | collectFunc | sumFunc | avgFunc |  minFunc |  maxFunc |percentileDiscFunc | percentileContFunc | stdevFunc | stdevpFunc | toStringFunc | replaceStrFunc | substringStrFunc | leftStrFunc | rightStrFunc | trimStrFunc | ltrimStrFunc|
189 rtrimStrFunc | upperStrFunc | lowerStrFunc | splitStrFunc | reverseStrFunc | lengthStrFunc | nodeId | rangeFunc | typeFunc | shortestPathFunc | allShortestPathsFunc | relsFunc | toLowerFunc |toInt | labelsFunc | timestampFunc | sizeFunc |
190 coalesceFunc | headFunc | lastFunc | startNodeFunc | endNodeFunc | propertiesFunc | toFloatFunc |keysFunc | tailFunc | reduceFunc | floorFunc;
191 
192 pathFunc: LENGTH '(' expression ')';
193 nodesFunc: NODES '(' expression ')';
194 relationshipsFunc: RELATIONSHIPS '(' expression ')';
195 extractFunc: EXTRACT '(' var IN expression '|' expression ')';
196 filterFunc: FILTER  '(' var IN expression WHERE relationalExpression ')';
197 absFunc: ABS '(' expression ')';
198 randFunc:RAND NIL;
199 roundFunc:ROUND '(' expression ')';
200 sqrtFunc: SQRT '(' expression ')';
201 signFunc: SIGN '(' expression ')';
202 sinFunc:SIN '(' expression ')';
203 cosFunc:COS '(' expression ')';
204 tanFunc:TAN '(' expression ')';
205 cotFunc:COT '(' expression ')';
206 asinFunc:ASIN '(' expression ')';
207 acosFunc:ACOS '(' expression ')';
208 atanFunc:ATAN '(' expression ')';
209 atan2Func:ATAN2 '(' expression ',' expression ')';
210 haversinFunc:HAVERSIN '(' expression ')';
211 degreesFunc:DEGREES '(' expression ')';
212 radiansFunc:RADIANS '(' expression ')';
213 pi:PI NIL;
214 log10Func:LOG10 '(' expression ')';
215 logFunc:LOG '(' expression ')';
216 expFunc:EXP '(' expression ')';
217 e: EFUNC NIL;
218 countAllFunc:COUNT '(' '*' ')';
219 countFunc:COUNT '(' DISTINCT? idPath ')';
220 collectFunc:COLLECT '(' idPath ')';
221 sumFunc:SUM '(' idPath ')';
222 avgFunc:AVG '(' idPath ')';
223 minFunc:MIN '(' idPath ')';
224 maxFunc:MAX '(' idPath ')';
225 percentileDiscFunc:PERCENTILEDISC '(' idPath ',' numericLiteral ')';
226 percentileContFunc:PERCENTILECONT '(' idPath ',' numericLiteral ')';
227 stdevFunc:STDEV '(' expression ')';
228 stdevpFunc:STDEVP '(' expression ')';
229 toStringFunc:TOSTRING '(' expression ')';
230 replaceStrFunc:REPLACE '(' expression ',' expression ',' expression ')';
231 substringStrFunc:SUBSTRING '(' expression ',' INTEGER (',' INTEGER)? ')';
232 leftStrFunc:LEFT '(' expression ',' INTEGER ')';
233 rightStrFunc:RIGHT '(' expression ',' INTEGER ')';
234 trimStrFunc:TRIM '(' expression ')';
235 ltrimStrFunc:LTRIM '(' expression ')';
236 rtrimStrFunc:RTRIM '(' expression ')';
237 upperStrFunc:UPPER '(' expression ')';
238 lowerStrFunc:LOWER '(' expression ')';
239 splitStrFunc:SPLIT '(' expression ',' STRING ')';
240 reverseStrFunc:REVERSE '(' expression ')';
241 lengthStrFunc:LENGTH '(' expression ')';
242 nodeId: IDFUNC '(' id ')';
243 rangeFunc: RANGE '(' expression ',' expression (',' expression)? ')';
244 typeFunc: TYPE '(' id ')';
245 shortestPathFunc: SHORTESTPATH '(' expression ')';
246 relsFunc: RELS '(' expression ')';
247 allShortestPathsFunc: ALLSHORTESTPATHS '(' expression ')';
248 toLowerFunc: TOLOWER '(' expression ')';
249 toInt:TOINT '(' expression ')';
250 labelsFunc: LABELS '(' expression ')';
251 timestampFunc:TIMESTAMP NIL;
252 sizeFunc: SIZE '(' expression ')';
253 coalesceFunc: COALESCE expressionList;
254 headFunc: HEAD '(' expression ')';
255 lastFunc: LAST '(' expression ')';
256 startNodeFunc: STARTNODE '(' expression ')';
257 endNodeFunc: ENDNODE '(' expression ')';
258 propertiesFunc:PROPERTIES  '(' expression ')';
259 toFloatFunc: TOFLOAT  '(' expression ')';
260 keysFunc: KEYS '(' expression ')';
261 tailFunc: TAIL '(' expression ')';
262 reduceFunc: REDUCE '(' accumulator EQUAL expression ',' ID IN expression '|' expression ')';
263 accumulator : ID;
264 floorFunc: FLOOR '(' expression ')';     
265 
266 graphElment: id labelVar;
267 
268 anyVal :  STRING | BOOLEAN | NULL | parameterPath | numericLiteral |graphElment | idPath | json ;
269 
270 //json
271 json:   jsonObject
272     |   jsonArray
273     ;
274 
275 jsonObject
276     :   ('{' jsonField (',' jsonField)* '}' 
277             |   '{' '}' // empty object
278         ) 
279     ;
280 jsonArray
281     :   '['list ']'  
282     |   '[' ']' // empty array
283     ;
284 
285 jsonField:   id ':' expression;
286 
287 numericLiteral: integerCypher | decimalCypher | doubleCypher ;
288 integerCypher   :   ('+'| '-')? INTEGER ;
289 decimalCypher   :   ('+'| '-')? DECIMAL ;
290 doubleCypher   :   ('+'| '-')? DOUBLE ;
291 
292 parameterPath: PARAMETER ('.' id )*;
293 labelVar: ':' id ;
294 id: ID | MATCH | OPTIONAL | WITH | SKIP | LIMIT | UNION | RETURN | DETACH |REMOVE|SET|CALL|YIELD|CONSTRAINT|ON|ASSERT_|DROP|
295     UNWIND|MERGE|INDEX|USING|SCAN|JOIN|FOREACH|CSV|IN|NOT|AND|OR|XOR|CASE|WHEN|ELSE|IS|UNIQUE|NULL|STARTS|START|ENDS|
296     END|CONTAINS|THEN|ALL|ANY|NONE|SINGLE|COUNT|DISTINCT|SUM|MIN|MAX|AVG|WHERE|SELECT|AS|FROM|BY|ORDER|ASC|DESC|LOAD|
297     CREATE|DELETE|EXISTS|HEADERS|FIELDTERMINATOR|PERIODIC|COMMIT|PROFILE|CYPHER|LENGTH|NODES|NODE|RELATIONSHIP|
298     RELATIONSHIPS|EXTRACT|FILTER|ABS|RAND|ROUND|SQRT|SIGN|COS|TAN|COT|ASIN|ACOS|ATAN|ATAN2|HAVERSIN|SIN|DEGREES|RADIANS|
299     PI|LOG10|LOG|EXP|EFUNC|COLLECT|PERCENTILEDISC|PERCENTILECONT|STDEVP|STDEV|TOSTRING|REPLACE|SUBSTRING|LEFT|RIGHT|TRIM|
300     LTRIM|RTRIM|UPPER|LOWER|SPLIT|REVERSE|IDFUNC|RANGE|TYPE|SHORTESTPATH|RELS|ALLSHORTESTPATHS|TOLOWER|TOINT|LABELS|
301     TIMESTAMP|SIZE|COALESCE|HEAD|LAST|STARTNODE|ENDNODE|PROPERTIES|TOFLOAT|KEYS|TAIL|REDUCE|FLOOR;
302 PARAMETER: '{' WS* (PN_CHARS_U ( PN_CHARS_U | [0-9])*) WS* '}';
303 LBRACE: '{';
304 RBRACE: '}';
305 MATCH: M A T C H;
306 OPTIONAL: O P T I O N A L;
307 WITH: W I T H;
308 SKIP: S K I P;
309 LIMIT: L I M I T;
310 UNION: U N I O N;
311 RETURN: R E T U R N;
312 DETACH: D E T A C H;
313 REMOVE: R E M O V E;
314 SET: S E T;
315 CALL: C A L L ;
316 YIELD: Y I E L D;
317 CONSTRAINT: C O N S T R A I N T;
318 ON: O N;
319 ASSERT_: A S S E R T;
320 DROP : D R O P ;
321 UNWIND :U N W I N D ;
322 MERGE: M E R G E;
323 INDEX: I N D E X;
324 USING : U S I N G;
325 SCAN:S C A N;
326 JOIN:J O I N;
327 FOREACH: F O R E A C H;
328 CSV: C S V;
329 IN:I N;
330 NOT:N O T;
331 AND: A N D ;
332 OR: O R;
333 XOR:X O R;
334 
335 CASE: C A S E;
336 WHEN : W H E N;
337 ELSE : E L S E;
338 IS: I S;
339 UNIQUE:U N I Q U E;
340 NULL: N U L L ;
341 STARTS: S T A R T S;
342 START: S T A R T;
343 ENDS: E N D S;
344 END: E N D; 
345 CONTAINS: C O N T A I N S;  
346 THEN: T H E N;
347 ALL : A L L;
348 ANY: A N Y ;
349 NONE: N O N E;
350 SINGLE: S I N G L E;
351 BOOLEAN : BOOL_VAL_TRUE | BOOL_VAL_FALSE;
352 COUNT : C O U N T;
353 DISTINCT : D I S T I N C T;
354 SUM : S U M;
355 MIN : M I N;
356 MAX : M A X;
357 AVG : A V G;
358 WHERE: W H E R E;
359 SELECT:S E L E C T;
360 AS:A S;
361 FROM:F R O M;
362 BY:B Y;
363 ORDER:O R D E R;
364 ASC:A S C;
365 DESC:D E S C;   
366 LOAD:L O A D;
367 CREATE:C R E A T E;
368 DELETE:D E L E T E;
369 EXISTS:E X I S T S;
370 HEADERS:H E A D E R S;
371 FIELDTERMINATOR:F I E L D T E R M I N A T O R;
372 PERIODIC:P E R I O D I C;
373 COMMIT: C O M M I T;
374 PROFILE:P R O F I L E;
375 CYPHER:C Y P H E R ;
376 
377 LENGTH : L E N G T H;
378 NODES : N O D E S;
379 NODE:N O D E;
380 RELATIONSHIP:R E L A T I O N S H I P;
381 RELATIONSHIPS:R E L A T I O N S H I P S;
382 EXTRACT:E X T R A C T;
383 FILTER:F I L T E R;
384 ABS:A B S;
385 RAND:R A N D;
386 ROUND:R O U N D;
387 SQRT:S Q R T;
388 SIGN:S I G N;
389 COS:C O S;
390 TAN:T A N;
391 COT:C O T;
392 ASIN:A S I N;
393 ACOS:A C O S;
394 ATAN:A T A N;
395 ATAN2:A T A N '2';
396 HAVERSIN:H A V E R S I N;
397 SIN:S I N;
398 DEGREES:D E G R E E S;
399 RADIANS:R A D I A N S;
400 PI:P I;
401 LOG10:L O G '10';
402 LOG:L O G;
403 EXP:E X P;
404 EFUNC:E;
405 COLLECT:C O L L E C T;
406 PERCENTILEDISC:P E R C E N T I L E D I S C;
407 PERCENTILECONT:P E R C E N T I L E C O N T;
408 STDEVP:S T D E V P;
409 STDEV:S T D E V;
410 TOSTRING:T O S T R I N G;
411 REPLACE:R E P L A C E;
412 SUBSTRING:S U B S T R I N G;
413 LEFT:L E F T;
414 RIGHT:R I G H T;
415 TRIM:T R I M;
416 LTRIM:L T R I M;
417 RTRIM:R T R I M;
418 UPPER:U P P E R;
419 LOWER:L O W E R;
420 SPLIT:S P L I T;
421 REVERSE:R E V E R S E;
422 IDFUNC:I D;
423 RANGE: R A N G E;
424 TYPE: T Y P E;
425 SHORTESTPATH: S H O R T E S T P A T H;
426 RELS:R E L S;
427 ALLSHORTESTPATHS:A L L S H O R T E S T P A T H S;
428 TOLOWER:T O L O W E R ;
429 TOINT: T O I N T ;
430 LABELS:L A B E L S;
431 TIMESTAMP:T I M E S T A M P;
432 SIZE:S I Z E;
433 COALESCE:C O A L E S C E;
434 HEAD: H E A D;
435 LAST:L A S T;
436 STARTNODE: S T A R T N O D E;
437 ENDNODE:E N D N O D E;
438 PROPERTIES:P R O P E R T I E S;
439 TOFLOAT:T O F L O A T;
440 KEYS:K E Y S;
441 TAIL:T A I L;
442 REDUCE:R E D U C E;
443 FLOOR:F L O O R;
444 
445 EQUAL_REGUALR:'=~';
446 ADDEQUAL: '+=';
447 NOT_EQUAL:'<>';
448 LT_EQUAL:'<=';
449 GT_EQUAL:'>=';
450 DOUBLEDOT: '..';
451 ARROWAHEAD :'->';
452 ARROWBACK:'<-';
453 LT:'<';
454 GT:'>';
455 EQUAL:'=';
456 NEGATE:'!';
457 DOT:'.';
458 MULIT:'*';
459 ADD :'+';
460 SUBTRACTION:'-';
461 DIVISION:'/';
462 STRING: STRING_VAL1 | STRING_VAL2;
463 INTEGER   :   [0-9]+ ;
464 DECIMAL   :   [0-9]* '.' [0-9]+ ;
465 DOUBLE   :   [0-9]+ '.' [0-9]+ EXPONENT | '.' ([0-9])+ EXPONENT | ([0-9])+ EXPONENT ;
466 NIL   :   '(' ')' ;
467 WS   :   ('\u0020' | '\u0009' | '\u000D' | '\u000A') {skip();} ;
468 ANON   :   '[' ']' ;  
469 ID: (PN_CHARS_U ( PN_CHARS_U | [0-9])*) | ('`' (ESC | ~[`\\])* '`');
470 
471 fragment STRING_VAL1   :   '\'' (ESC | ~['\\])* '\'' ;
472 fragment STRING_VAL2   :   '\"' (ESC | ~["\\])* '\"' ;
473 fragment BOOL_VAL_TRUE:'true';
474 fragment BOOL_VAL_FALSE:'false';
475 fragment ESC :   '\\' (['\\/bfnrt]);
476 fragment EXPONENT   :   'e' [+-]? [0-9]+ ;
477 fragment ECHAR   :   '\\' [tbnrf\\"'] ;
478 fragment PN_CHARS_BASE   :   (A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z) | [\u00C0-\u00D6] | [\u00D8-\u00F6] | [\u00F8-\u02FF] | [\u0370-\u037D] | [\u037F-\u1FFF] | [\u200C-\u200D] | [\u2070-\u218F] | [\u2C00-\u2FEF] | [\u3001-\uD7FF] | [\uF900-\uFDCF] | [\uFDF0-\uFFFD];// | [\u10000-\uEFFFF] ;
479 fragment PN_CHARS_U   :   PN_CHARS_BASE | '_' ;
480 fragment PN_CHARS   :   PN_CHARS_U | '-' | [0-9] | '\u00B7' | [\u0300-\u036F] | [\u203F-\u2040] ;
481 
482 fragment A:[aA];
483 fragment B:[bB];
484 fragment C:[cC];
485 fragment D:[dD];
486 fragment E:[eE];
487 fragment F:[fF];
488 fragment G:[gG];
489 fragment H:[hH];
490 fragment I:[iI];
491 fragment J:[jJ];
492 fragment K:[kK];
493 fragment L:[lL];
494 fragment M:[mM];
495 fragment N:[nN];
496 fragment O:[oO];
497 fragment P:[pP];
498 fragment Q:[qQ];
499 fragment R:[rR];
500 fragment S:[sS];
501 fragment T:[tT];
502 fragment U:[uU];
503 fragment V:[vV];
504 fragment W:[wW];      
505 fragment X:[xX];
506 fragment Y:[yY];
507 fragment Z:[zZ];

 

posted @ 2016-12-10 18:00 adam# 阅读(...) 评论(...) 编辑 收藏