Python3.g4 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2014 by Bart Kiers
  5. *
  6. * Permission is hereby granted, free of charge, to any person
  7. * obtaining a copy of this software and associated documentation
  8. * files (the "Software"), to deal in the Software without
  9. * restriction, including without limitation the rights to use,
  10. * copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  20. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  22. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25. * OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. * Project : python3-parser; an ANTLR4 grammar for Python 3
  28. * https://github.com/bkiers/python3-parser
  29. * Developed by : Bart Kiers, bart@big-o.nl
  30. */
  31. grammar Python3;
  32. // All comments that start with "///" are copy-pasted from
  33. // The Python Language Reference: https://docs.python.org/3.3/reference/grammar.html
  34. tokens { INDENT, DEDENT }
  35. @lexer::members {
  36. // A queue where extra tokens are pushed on (see the NEWLINE lexer rule).
  37. private java.util.LinkedList<Token> tokens = new java.util.LinkedList<>();
  38. // The stack that keeps track of the indentation level.
  39. private java.util.Stack<Integer> indents = new java.util.Stack<>();
  40. // The amount of opened braces, brackets and parenthesis.
  41. private int opened = 0;
  42. // The most recently produced token.
  43. private Token lastToken = null;
  44. @Override
  45. public void emit(Token t) {
  46. super.setToken(t);
  47. tokens.offer(t);
  48. }
  49. @Override
  50. public Token nextToken() {
  51. // Check if the end-of-file is ahead and there are still some DEDENTS expected.
  52. if (_input.LA(1) == EOF && !this.indents.isEmpty()) {
  53. // Remove any trailing EOF tokens from our buffer.
  54. for (int i = tokens.size() - 1; i >= 0; i--) {
  55. if (tokens.get(i).getType() == EOF) {
  56. tokens.remove(i);
  57. }
  58. }
  59. // First emit an extra line break that serves as the end of the statement.
  60. this.emit(commonToken(Python3Parser.NEWLINE, "\n"));
  61. // Now emit as much DEDENT tokens as needed.
  62. while (!indents.isEmpty()) {
  63. this.emit(createDedent());
  64. indents.pop();
  65. }
  66. // Put the EOF back on the token stream.
  67. this.emit(commonToken(Python3Parser.EOF, "<EOF>"));
  68. }
  69. Token next = super.nextToken();
  70. if (next.getChannel() == Token.DEFAULT_CHANNEL) {
  71. // Keep track of the last token on the default channel.
  72. this.lastToken = next;
  73. }
  74. return tokens.isEmpty() ? next : tokens.poll();
  75. }
  76. private Token createDedent() {
  77. CommonToken dedent = commonToken(Python3Parser.DEDENT, "");
  78. dedent.setLine(this.lastToken.getLine());
  79. return dedent;
  80. }
  81. private CommonToken commonToken(int type, String text) {
  82. int stop = this.getCharIndex() - 1;
  83. int start = text.isEmpty() ? stop : stop - text.length() + 1;
  84. return new CommonToken(this._tokenFactorySourcePair, type, DEFAULT_TOKEN_CHANNEL, start, stop);
  85. }
  86. // Calculates the indentation of the provided spaces, taking the
  87. // following rules into account:
  88. //
  89. // "Tabs are replaced (from left to right) by one to eight spaces
  90. // such that the total number of characters up to and including
  91. // the replacement is a multiple of eight [...]"
  92. //
  93. // -- https://docs.python.org/3.1/reference/lexical_analysis.html#indentation
  94. static int getIndentationCount(String spaces) {
  95. int count = 0;
  96. for (char ch : spaces.toCharArray()) {
  97. switch (ch) {
  98. case '\t':
  99. count += 8 - (count % 8);
  100. break;
  101. default:
  102. // A normal space char.
  103. count++;
  104. }
  105. }
  106. return count;
  107. }
  108. boolean atStartOfInput() {
  109. return super.getCharPositionInLine() == 0 && super.getLine() == 1;
  110. }
  111. }
  112. /*
  113. * parser rules
  114. */
  115. /// single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
  116. single_input
  117. : NEWLINE
  118. | simple_stmt
  119. | compound_stmt NEWLINE
  120. ;
  121. /// file_input: (NEWLINE | stmt)* ENDMARKER
  122. file_input
  123. : ( NEWLINE | stmt )* EOF
  124. ;
  125. /// eval_input: testlist NEWLINE* ENDMARKER
  126. eval_input
  127. : testlist NEWLINE* EOF
  128. ;
  129. /// decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
  130. decorator
  131. : '@' dotted_name ( '(' arglist? ')' )? NEWLINE
  132. ;
  133. /// decorators: decorator+
  134. decorators
  135. : decorator+
  136. ;
  137. /// decorated: decorators (classdef | funcdef)
  138. decorated
  139. : decorators ( classdef | funcdef )
  140. ;
  141. /// funcdef: 'def' NAME parameters ['->' test] ':' suite
  142. funcdef
  143. : DEF NAME parameters ( '->' test )? ':' suite
  144. ;
  145. /// parameters: '(' [typedargslist] ')'
  146. parameters
  147. : '(' typedargslist? ')'
  148. ;
  149. /// typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [','
  150. /// ['*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef]]
  151. /// | '*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef)
  152. typedargslist
  153. : tfpdef ( '=' test )? ( ',' tfpdef ( '=' test )? )* ( ',' ( '*' tfpdef? ( ',' tfpdef ( '=' test )? )* ( ',' '**' tfpdef )?
  154. | '**' tfpdef
  155. )?
  156. )?
  157. | '*' tfpdef? ( ',' tfpdef ( '=' test )? )* ( ',' '**' tfpdef )?
  158. | '**' tfpdef
  159. ;
  160. /// tfpdef: NAME [':' test]
  161. tfpdef
  162. : NAME ( ':' test )?
  163. ;
  164. /// varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [','
  165. /// ['*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef]]
  166. /// | '*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef)
  167. varargslist
  168. : vfpdef ( '=' test )? ( ',' vfpdef ( '=' test )? )* ( ',' ( '*' vfpdef? ( ',' vfpdef ( '=' test )? )* ( ',' '**' vfpdef )?
  169. | '**' vfpdef
  170. )?
  171. )?
  172. | '*' vfpdef? ( ',' vfpdef ( '=' test )? )* ( ',' '**' vfpdef )?
  173. | '**' vfpdef
  174. ;
  175. /// vfpdef: NAME
  176. vfpdef
  177. : NAME
  178. ;
  179. /// stmt: simple_stmt | compound_stmt
  180. stmt
  181. : simple_stmt
  182. | compound_stmt
  183. ;
  184. /// simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
  185. simple_stmt
  186. : small_stmt ( ';' small_stmt )* ';'? NEWLINE
  187. ;
  188. /// small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt |
  189. /// import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
  190. small_stmt
  191. : expr_stmt
  192. | del_stmt
  193. | pass_stmt
  194. | flow_stmt
  195. | import_stmt
  196. | global_stmt
  197. | nonlocal_stmt
  198. | assert_stmt
  199. ;
  200. /// expr_stmt: testlist_star_expr (augassign (yield_expr|testlist) |
  201. /// ('=' (yield_expr|testlist_star_expr))*)
  202. expr_stmt
  203. : testlist_star_expr ( augassign ( yield_expr | testlist)
  204. | ( '=' ( yield_expr| testlist_star_expr ) )*
  205. )
  206. ;
  207. /// testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
  208. testlist_star_expr
  209. : ( test | star_expr ) ( ',' ( test | star_expr ) )* ','?
  210. ;
  211. /// augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' |
  212. /// '<<=' | '>>=' | '**=' | '//=')
  213. augassign
  214. : '+='
  215. | '-='
  216. | '*='
  217. | '@=' // PEP 465
  218. | '/='
  219. | '%='
  220. | '&='
  221. | '|='
  222. | '^='
  223. | '<<='
  224. | '>>='
  225. | '**='
  226. | '//='
  227. ;
  228. /// del_stmt: 'del' exprlist
  229. del_stmt
  230. : DEL exprlist
  231. ;
  232. /// pass_stmt: 'pass'
  233. pass_stmt
  234. : PASS
  235. ;
  236. /// flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
  237. flow_stmt
  238. : break_stmt
  239. | continue_stmt
  240. | return_stmt
  241. | raise_stmt
  242. | yield_stmt
  243. ;
  244. /// break_stmt: 'break'
  245. break_stmt
  246. : BREAK
  247. ;
  248. /// continue_stmt: 'continue'
  249. continue_stmt
  250. : CONTINUE
  251. ;
  252. /// return_stmt: 'return' [testlist]
  253. return_stmt
  254. : RETURN testlist?
  255. ;
  256. /// yield_stmt: yield_expr
  257. yield_stmt
  258. : yield_expr
  259. ;
  260. /// raise_stmt: 'raise' [test ['from' test]]
  261. raise_stmt
  262. : RAISE ( test ( FROM test )? )?
  263. ;
  264. /// import_stmt: import_name | import_from
  265. import_stmt
  266. : import_name
  267. | import_from
  268. ;
  269. /// import_name: 'import' dotted_as_names
  270. import_name
  271. : IMPORT dotted_as_names
  272. ;
  273. /// # note below: the ('.' | '...') is necessary because '...' is tokenized as ELLIPSIS
  274. /// import_from: ('from' (('.' | '...')* dotted_name | ('.' | '...')+)
  275. /// 'import' ('*' | '(' import_as_names ')' | import_as_names))
  276. import_from
  277. : FROM ( ( '.' | '...' )* dotted_name
  278. | ('.' | '...')+
  279. )
  280. IMPORT ( '*'
  281. | '(' import_as_names ')'
  282. | import_as_names
  283. )
  284. ;
  285. /// import_as_name: NAME ['as' NAME]
  286. import_as_name
  287. : NAME ( AS NAME )?
  288. ;
  289. /// dotted_as_name: dotted_name ['as' NAME]
  290. dotted_as_name
  291. : dotted_name ( AS NAME )?
  292. ;
  293. /// import_as_names: import_as_name (',' import_as_name)* [',']
  294. import_as_names
  295. : import_as_name ( ',' import_as_name )* ','?
  296. ;
  297. /// dotted_as_names: dotted_as_name (',' dotted_as_name)*
  298. dotted_as_names
  299. : dotted_as_name ( ',' dotted_as_name )*
  300. ;
  301. /// dotted_name: NAME ('.' NAME)*
  302. dotted_name
  303. : NAME ( '.' NAME )*
  304. ;
  305. /// global_stmt: 'global' NAME (',' NAME)*
  306. global_stmt
  307. : GLOBAL NAME ( ',' NAME )*
  308. ;
  309. /// nonlocal_stmt: 'nonlocal' NAME (',' NAME)*
  310. nonlocal_stmt
  311. : NONLOCAL NAME ( ',' NAME )*
  312. ;
  313. /// assert_stmt: 'assert' test [',' test]
  314. assert_stmt
  315. : ASSERT test ( ',' test )?
  316. ;
  317. /// compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated
  318. compound_stmt
  319. : if_stmt
  320. | while_stmt
  321. | for_stmt
  322. | try_stmt
  323. | with_stmt
  324. | funcdef
  325. | classdef
  326. | decorated
  327. ;
  328. /// if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
  329. if_stmt
  330. : IF test ':' suite ( ELIF test ':' suite )* ( ELSE ':' suite )?
  331. ;
  332. /// while_stmt: 'while' test ':' suite ['else' ':' suite]
  333. while_stmt
  334. : WHILE test ':' suite ( ELSE ':' suite )?
  335. ;
  336. /// for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
  337. for_stmt
  338. : FOR exprlist IN testlist ':' suite ( ELSE ':' suite )?
  339. ;
  340. /// try_stmt: ('try' ':' suite
  341. /// ((except_clause ':' suite)+
  342. /// ['else' ':' suite]
  343. /// ['finally' ':' suite] |
  344. /// 'finally' ':' suite))
  345. try_stmt
  346. : TRY ':' suite ( ( except_clause ':' suite )+
  347. ( ELSE ':' suite )?
  348. ( FINALLY ':' suite )?
  349. | FINALLY ':' suite
  350. )
  351. ;
  352. /// with_stmt: 'with' with_item (',' with_item)* ':' suite
  353. with_stmt
  354. : WITH with_item ( ',' with_item )* ':' suite
  355. ;
  356. /// with_item: test ['as' expr]
  357. with_item
  358. : test ( AS expr )?
  359. ;
  360. /// # NB compile.c makes sure that the default except clause is last
  361. /// except_clause: 'except' [test ['as' NAME]]
  362. except_clause
  363. : EXCEPT ( test ( AS NAME )? )?
  364. ;
  365. /// suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
  366. suite
  367. : simple_stmt
  368. | NEWLINE INDENT stmt+ DEDENT
  369. ;
  370. /// test: or_test ['if' or_test 'else' test] | lambdef
  371. test
  372. : or_test ( IF or_test ELSE test )?
  373. | lambdef
  374. ;
  375. /// test_nocond: or_test | lambdef_nocond
  376. test_nocond
  377. : or_test
  378. | lambdef_nocond
  379. ;
  380. /// lambdef: 'lambda' [varargslist] ':' test
  381. lambdef
  382. : LAMBDA varargslist? ':' test
  383. ;
  384. /// lambdef_nocond: 'lambda' [varargslist] ':' test_nocond
  385. lambdef_nocond
  386. : LAMBDA varargslist? ':' test_nocond
  387. ;
  388. /// or_test: and_test ('or' and_test)*
  389. or_test
  390. : and_test ( OR and_test )*
  391. ;
  392. /// and_test: not_test ('and' not_test)*
  393. and_test
  394. : not_test ( AND not_test )*
  395. ;
  396. /// not_test: 'not' not_test | comparison
  397. not_test
  398. : NOT not_test
  399. | comparison
  400. ;
  401. /// comparison: star_expr (comp_op star_expr)*
  402. comparison
  403. : star_expr ( comp_op star_expr )*
  404. ;
  405. /// # <> isn't actually a valid comparison operator in Python. It's here for the
  406. /// # sake of a __future__ import described in PEP 401
  407. /// comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
  408. comp_op
  409. : '<'
  410. | '>'
  411. | '=='
  412. | '>='
  413. | '<='
  414. | '<>'
  415. | '!='
  416. | IN
  417. | NOT IN
  418. | IS
  419. | IS NOT
  420. ;
  421. /// star_expr: ['*'] expr
  422. star_expr
  423. : '*'? expr
  424. ;
  425. /// expr: xor_expr ('|' xor_expr)*
  426. expr
  427. : xor_expr ( '|' xor_expr )*
  428. ;
  429. /// xor_expr: and_expr ('^' and_expr)*
  430. xor_expr
  431. : and_expr ( '^' and_expr )*
  432. ;
  433. /// and_expr: shift_expr ('&' shift_expr)*
  434. and_expr
  435. : shift_expr ( '&' shift_expr )*
  436. ;
  437. /// shift_expr: arith_expr (('<<'|'>>') arith_expr)*
  438. shift_expr
  439. : arith_expr ( '<<' arith_expr
  440. | '>>' arith_expr
  441. )*
  442. ;
  443. /// arith_expr: term (('+'|'-') term)*
  444. arith_expr
  445. : term ( '+' term
  446. | '-' term
  447. )*
  448. ;
  449. /// term: factor (('*'|'/'|'%'|'//') factor)*
  450. term
  451. : factor ( '*' factor
  452. | '/' factor
  453. | '%' factor
  454. | '//' factor
  455. | '@' factor // PEP 465
  456. )*
  457. ;
  458. /// factor: ('+'|'-'|'~') factor | power
  459. factor
  460. : '+' factor
  461. | '-' factor
  462. | '~' factor
  463. | power
  464. ;
  465. /// power: atom trailer* ['**' factor]
  466. power
  467. : atom trailer* ( '**' factor )?
  468. ;
  469. /// atom: ('(' [yield_expr|testlist_comp] ')' |
  470. /// '[' [testlist_comp] ']' |
  471. /// '{' [dictorsetmaker] '}' |
  472. /// NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')
  473. atom
  474. : '(' ( yield_expr | testlist_comp )? ')'
  475. | '[' testlist_comp? ']'
  476. | '{' dictorsetmaker? '}'
  477. | NAME
  478. | number
  479. | string+
  480. | '...'
  481. | NONE
  482. | TRUE
  483. | FALSE
  484. ;
  485. /// testlist_comp: test ( comp_for | (',' test)* [','] )
  486. testlist_comp
  487. : test ( comp_for
  488. | ( ',' test )* ','?
  489. )
  490. ;
  491. /// trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
  492. trailer
  493. : '(' arglist? ')'
  494. | '[' subscriptlist ']'
  495. | '.' NAME
  496. ;
  497. /// subscriptlist: subscript (',' subscript)* [',']
  498. subscriptlist
  499. : subscript ( ',' subscript )* ','?
  500. ;
  501. /// subscript: test | [test] ':' [test] [sliceop]
  502. subscript
  503. : test
  504. | test? ':' test? sliceop?
  505. ;
  506. /// sliceop: ':' [test]
  507. sliceop
  508. : ':' test?
  509. ;
  510. /// exprlist: star_expr (',' star_expr)* [',']
  511. exprlist
  512. : star_expr ( ',' star_expr )* ','?
  513. ;
  514. /// testlist: test (',' test)* [',']
  515. testlist
  516. : test ( ',' test )* ','?
  517. ;
  518. /// dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |
  519. /// (test (comp_for | (',' test)* [','])) )
  520. dictorsetmaker
  521. : test ':' test ( comp_for
  522. | ( ',' test ':' test )* ','?
  523. )
  524. | test ( comp_for
  525. | ( ',' test )* ','?
  526. )
  527. ;
  528. /// classdef: 'class' NAME ['(' [arglist] ')'] ':' suite
  529. classdef
  530. : CLASS NAME ( '(' arglist? ')' )? ':' suite
  531. ;
  532. /// arglist: (argument ',')* (argument [',']
  533. /// |'*' test (',' argument)* [',' '**' test]
  534. /// |'**' test)
  535. arglist
  536. : ( argument ',' )* ( argument ','?
  537. | '*' test ( ',' argument )* ( ',' '**' test )?
  538. | '**' test
  539. )
  540. ;
  541. /// # The reason that keywords are test nodes instead of NAME is that using NAME
  542. /// # results in an ambiguity. ast.c makes sure it's a NAME.
  543. /// argument: test [comp_for] | test '=' test # Really [keyword '='] test
  544. argument
  545. : test comp_for?
  546. | test '=' test
  547. ;
  548. /// comp_iter: comp_for | comp_if
  549. comp_iter
  550. : comp_for
  551. | comp_if
  552. ;
  553. /// comp_for: 'for' exprlist 'in' or_test [comp_iter]
  554. comp_for
  555. : FOR exprlist IN or_test comp_iter?
  556. ;
  557. /// comp_if: 'if' test_nocond [comp_iter]
  558. comp_if
  559. : IF test_nocond comp_iter?
  560. ;
  561. /// yield_expr: 'yield' [testlist]
  562. yield_expr
  563. : YIELD yield_arg?
  564. ;
  565. /// yield_arg: 'from' test | testlist
  566. yield_arg
  567. : FROM test
  568. | testlist
  569. ;
  570. string
  571. : STRING_LITERAL
  572. | BYTES_LITERAL
  573. ;
  574. number
  575. : integer
  576. | FLOAT_NUMBER
  577. | IMAG_NUMBER
  578. ;
  579. /// integer ::= decimalinteger | octinteger | hexinteger | bininteger
  580. integer
  581. : DECIMAL_INTEGER
  582. | OCT_INTEGER
  583. | HEX_INTEGER
  584. | BIN_INTEGER
  585. ;
  586. /*
  587. * lexer rules
  588. */
  589. DEF : 'def';
  590. RETURN : 'return';
  591. RAISE : 'raise';
  592. FROM : 'from';
  593. IMPORT : 'import';
  594. AS : 'as';
  595. GLOBAL : 'global';
  596. NONLOCAL : 'nonlocal';
  597. ASSERT : 'assert';
  598. IF : 'if';
  599. ELIF : 'elif';
  600. ELSE : 'else';
  601. WHILE : 'while';
  602. FOR : 'for';
  603. IN : 'in';
  604. TRY : 'try';
  605. FINALLY : 'finally';
  606. WITH : 'with';
  607. EXCEPT : 'except';
  608. LAMBDA : 'lambda';
  609. OR : 'or';
  610. AND : 'and';
  611. NOT : 'not';
  612. IS : 'is';
  613. NONE : 'None';
  614. TRUE : 'True';
  615. FALSE : 'False';
  616. CLASS : 'class';
  617. YIELD : 'yield';
  618. DEL : 'del';
  619. PASS : 'pass';
  620. CONTINUE : 'continue';
  621. BREAK : 'break';
  622. NEWLINE
  623. : ( {atStartOfInput()}? SPACES
  624. | ( '\r'? '\n' | '\r' ) SPACES?
  625. )
  626. {
  627. String newLine = getText().replaceAll("[^\r\n]+", "");
  628. String spaces = getText().replaceAll("[\r\n]+", "");
  629. int next = _input.LA(1);
  630. if (opened > 0 || next == '\r' || next == '\n' || next == '#') {
  631. // If we're inside a list or on a blank line, ignore all indents,
  632. // dedents and line breaks.
  633. skip();
  634. }
  635. else {
  636. emit(commonToken(NEWLINE, newLine));
  637. int indent = getIndentationCount(spaces);
  638. int previous = indents.isEmpty() ? 0 : indents.peek();
  639. if (indent == previous) {
  640. // skip indents of the same size as the present indent-size
  641. skip();
  642. }
  643. else if (indent > previous) {
  644. indents.push(indent);
  645. emit(commonToken(Python3Parser.INDENT, spaces));
  646. }
  647. else {
  648. // Possibly emit more than 1 DEDENT token.
  649. while(!indents.isEmpty() && indents.peek() > indent) {
  650. this.emit(createDedent());
  651. indents.pop();
  652. }
  653. }
  654. }
  655. }
  656. ;
  657. /// identifier ::= id_start id_continue*
  658. NAME
  659. : ID_START ID_CONTINUE*
  660. ;
  661. /// stringliteral ::= [stringprefix](shortstring | longstring)
  662. /// stringprefix ::= "r" | "R"
  663. STRING_LITERAL
  664. : [uU]? [rR]? ( SHORT_STRING | LONG_STRING )
  665. ;
  666. /// bytesliteral ::= bytesprefix(shortbytes | longbytes)
  667. /// bytesprefix ::= "b" | "B" | "br" | "Br" | "bR" | "BR"
  668. BYTES_LITERAL
  669. : [bB] [rR]? ( SHORT_BYTES | LONG_BYTES )
  670. ;
  671. /// decimalinteger ::= nonzerodigit digit* | "0"+
  672. DECIMAL_INTEGER
  673. : NON_ZERO_DIGIT DIGIT*
  674. | '0'+
  675. ;
  676. /// octinteger ::= "0" ("o" | "O") octdigit+
  677. OCT_INTEGER
  678. : '0' [oO] OCT_DIGIT+
  679. ;
  680. /// hexinteger ::= "0" ("x" | "X") hexdigit+
  681. HEX_INTEGER
  682. : '0' [xX] HEX_DIGIT+
  683. ;
  684. /// bininteger ::= "0" ("b" | "B") bindigit+
  685. BIN_INTEGER
  686. : '0' [bB] BIN_DIGIT+
  687. ;
  688. /// floatnumber ::= pointfloat | exponentfloat
  689. FLOAT_NUMBER
  690. : POINT_FLOAT
  691. | EXPONENT_FLOAT
  692. ;
  693. /// imagnumber ::= (floatnumber | intpart) ("j" | "J")
  694. IMAG_NUMBER
  695. : ( FLOAT_NUMBER | INT_PART ) [jJ]
  696. ;
  697. DOT : '.';
  698. ELLIPSIS : '...';
  699. STAR : '*';
  700. OPEN_PAREN : '(' {opened++;};
  701. CLOSE_PAREN : ')' {opened--;};
  702. COMMA : ',';
  703. COLON : ':';
  704. SEMI_COLON : ';';
  705. POWER : '**';
  706. ASSIGN : '=';
  707. OPEN_BRACK : '[' {opened++;};
  708. CLOSE_BRACK : ']' {opened--;};
  709. OR_OP : '|';
  710. XOR : '^';
  711. AND_OP : '&';
  712. LEFT_SHIFT : '<<';
  713. RIGHT_SHIFT : '>>';
  714. ADD : '+';
  715. MINUS : '-';
  716. DIV : '/';
  717. MOD : '%';
  718. IDIV : '//';
  719. NOT_OP : '~';
  720. OPEN_BRACE : '{' {opened++;};
  721. CLOSE_BRACE : '}' {opened--;};
  722. LESS_THAN : '<';
  723. GREATER_THAN : '>';
  724. EQUALS : '==';
  725. GT_EQ : '>=';
  726. LT_EQ : '<=';
  727. NOT_EQ_1 : '<>';
  728. NOT_EQ_2 : '!=';
  729. AT : '@';
  730. ARROW : '->';
  731. ADD_ASSIGN : '+=';
  732. SUB_ASSIGN : '-=';
  733. MULT_ASSIGN : '*=';
  734. AT_ASSIGN : '@=';
  735. DIV_ASSIGN : '/=';
  736. MOD_ASSIGN : '%=';
  737. AND_ASSIGN : '&=';
  738. OR_ASSIGN : '|=';
  739. XOR_ASSIGN : '^=';
  740. LEFT_SHIFT_ASSIGN : '<<=';
  741. RIGHT_SHIFT_ASSIGN : '>>=';
  742. POWER_ASSIGN : '**=';
  743. IDIV_ASSIGN : '//=';
  744. SKIP_
  745. : ( SPACES | COMMENT | LINE_JOINING ) -> skip
  746. ;
  747. UNKNOWN_CHAR
  748. : .
  749. ;
  750. /*
  751. * fragments
  752. */
  753. /// shortstring ::= "'" shortstringitem* "'" | '"' shortstringitem* '"'
  754. /// shortstringitem ::= shortstringchar | stringescapeseq
  755. /// shortstringchar ::= <any source character except "\" or newline or the quote>
  756. fragment SHORT_STRING
  757. : '\'' ( STRING_ESCAPE_SEQ | ~[\\\r\n'] )* '\''
  758. | '"' ( STRING_ESCAPE_SEQ | ~[\\\r\n"] )* '"'
  759. ;
  760. /// longstring ::= "'''" longstringitem* "'''" | '"""' longstringitem* '"""'
  761. fragment LONG_STRING
  762. : '\'\'\'' LONG_STRING_ITEM*? '\'\'\''
  763. | '"""' LONG_STRING_ITEM*? '"""'
  764. ;
  765. /// longstringitem ::= longstringchar | stringescapeseq
  766. fragment LONG_STRING_ITEM
  767. : LONG_STRING_CHAR
  768. | STRING_ESCAPE_SEQ
  769. ;
  770. /// longstringchar ::= <any source character except "\">
  771. fragment LONG_STRING_CHAR
  772. : ~'\\'
  773. ;
  774. /// stringescapeseq ::= "\" <any source character>
  775. fragment STRING_ESCAPE_SEQ
  776. : '\\' .
  777. ;
  778. /// nonzerodigit ::= "1"..."9"
  779. fragment NON_ZERO_DIGIT
  780. : [1-9]
  781. ;
  782. /// digit ::= "0"..."9"
  783. fragment DIGIT
  784. : [0-9]
  785. ;
  786. /// octdigit ::= "0"..."7"
  787. fragment OCT_DIGIT
  788. : [0-7]
  789. ;
  790. /// hexdigit ::= digit | "a"..."f" | "A"..."F"
  791. fragment HEX_DIGIT
  792. : [0-9a-fA-F]
  793. ;
  794. /// bindigit ::= "0" | "1"
  795. fragment BIN_DIGIT
  796. : [01]
  797. ;
  798. /// pointfloat ::= [intpart] fraction | intpart "."
  799. fragment POINT_FLOAT
  800. : INT_PART? FRACTION
  801. | INT_PART '.'
  802. ;
  803. /// exponentfloat ::= (intpart | pointfloat) exponent
  804. fragment EXPONENT_FLOAT
  805. : ( INT_PART | POINT_FLOAT ) EXPONENT
  806. ;
  807. /// intpart ::= digit+
  808. fragment INT_PART
  809. : DIGIT+
  810. ;
  811. /// fraction ::= "." digit+
  812. fragment FRACTION
  813. : '.' DIGIT+
  814. ;
  815. /// exponent ::= ("e" | "E") ["+" | "-"] digit+
  816. fragment EXPONENT
  817. : [eE] [+-]? DIGIT+
  818. ;
  819. /// shortbytes ::= "'" shortbytesitem* "'" | '"' shortbytesitem* '"'
  820. /// shortbytesitem ::= shortbyteschar | bytesescapeseq
  821. fragment SHORT_BYTES
  822. : '\'' ( SHORT_BYTES_CHAR_NO_SINGLE_QUOTE | BYTES_ESCAPE_SEQ )* '\''
  823. | '"' ( SHORT_BYTES_CHAR_NO_DOUBLE_QUOTE | BYTES_ESCAPE_SEQ )* '"'
  824. ;
  825. /// longbytes ::= "'''" longbytesitem* "'''" | '"""' longbytesitem* '"""'
  826. fragment LONG_BYTES
  827. : '\'\'\'' LONG_BYTES_ITEM*? '\'\'\''
  828. | '"""' LONG_BYTES_ITEM*? '"""'
  829. ;
  830. /// longbytesitem ::= longbyteschar | bytesescapeseq
  831. fragment LONG_BYTES_ITEM
  832. : LONG_BYTES_CHAR
  833. | BYTES_ESCAPE_SEQ
  834. ;
  835. /// shortbyteschar ::= <any ASCII character except "\" or newline or the quote>
  836. fragment SHORT_BYTES_CHAR_NO_SINGLE_QUOTE
  837. : [\u0000-\u0009]
  838. | [\u000B-\u000C]
  839. | [\u000E-\u0026]
  840. | [\u0028-\u005B]
  841. | [\u005D-\u007F]
  842. ;
  843. fragment SHORT_BYTES_CHAR_NO_DOUBLE_QUOTE
  844. : [\u0000-\u0009]
  845. | [\u000B-\u000C]
  846. | [\u000E-\u0021]
  847. | [\u0023-\u005B]
  848. | [\u005D-\u007F]
  849. ;
  850. /// longbyteschar ::= <any ASCII character except "\">
  851. fragment LONG_BYTES_CHAR
  852. : [\u0000-\u005B]
  853. | [\u005D-\u007F]
  854. ;
  855. /// bytesescapeseq ::= "\" <any ASCII character>
  856. fragment BYTES_ESCAPE_SEQ
  857. : '\\' [\u0000-\u007F]
  858. ;
  859. fragment SPACES
  860. : [ \t]+
  861. ;
  862. fragment COMMENT
  863. : '#' ~[\r\n]*
  864. ;
  865. fragment LINE_JOINING
  866. : '\\' SPACES? ( '\r'? '\n' | '\r' )
  867. ;
  868. /// id_start ::= <all characters in general categories Lu, Ll, Lt, Lm, Lo, Nl, the underscore, and characters with the Other_ID_Start property>
  869. fragment ID_START
  870. : '_'
  871. | [A-Z]
  872. | [a-z]
  873. | '\u00AA'
  874. | '\u00B5'
  875. | '\u00BA'
  876. | [\u00C0-\u00D6]
  877. | [\u00D8-\u00F6]
  878. | [\u00F8-\u01BA]
  879. | '\u01BB'
  880. | [\u01BC-\u01BF]
  881. | [\u01C0-\u01C3]
  882. | [\u01C4-\u0241]
  883. | [\u0250-\u02AF]
  884. | [\u02B0-\u02C1]
  885. | [\u02C6-\u02D1]
  886. | [\u02E0-\u02E4]
  887. | '\u02EE'
  888. | '\u037A'
  889. | '\u0386'
  890. | [\u0388-\u038A]
  891. | '\u038C'
  892. | [\u038E-\u03A1]
  893. | [\u03A3-\u03CE]
  894. | [\u03D0-\u03F5]
  895. | [\u03F7-\u0481]
  896. | [\u048A-\u04CE]
  897. | [\u04D0-\u04F9]
  898. | [\u0500-\u050F]
  899. | [\u0531-\u0556]
  900. | '\u0559'
  901. | [\u0561-\u0587]
  902. | [\u05D0-\u05EA]
  903. | [\u05F0-\u05F2]
  904. | [\u0621-\u063A]
  905. | '\u0640'
  906. | [\u0641-\u064A]
  907. | [\u066E-\u066F]
  908. | [\u0671-\u06D3]
  909. | '\u06D5'
  910. | [\u06E5-\u06E6]
  911. | [\u06EE-\u06EF]
  912. | [\u06FA-\u06FC]
  913. | '\u06FF'
  914. | '\u0710'
  915. | [\u0712-\u072F]
  916. | [\u074D-\u076D]
  917. | [\u0780-\u07A5]
  918. | '\u07B1'
  919. | [\u0904-\u0939]
  920. | '\u093D'
  921. | '\u0950'
  922. | [\u0958-\u0961]
  923. | '\u097D'
  924. | [\u0985-\u098C]
  925. | [\u098F-\u0990]
  926. | [\u0993-\u09A8]
  927. | [\u09AA-\u09B0]
  928. | '\u09B2'
  929. | [\u09B6-\u09B9]
  930. | '\u09BD'
  931. | '\u09CE'
  932. | [\u09DC-\u09DD]
  933. | [\u09DF-\u09E1]
  934. | [\u09F0-\u09F1]
  935. | [\u0A05-\u0A0A]
  936. | [\u0A0F-\u0A10]
  937. | [\u0A13-\u0A28]
  938. | [\u0A2A-\u0A30]
  939. | [\u0A32-\u0A33]
  940. | [\u0A35-\u0A36]
  941. | [\u0A38-\u0A39]
  942. | [\u0A59-\u0A5C]
  943. | '\u0A5E'
  944. | [\u0A72-\u0A74]
  945. | [\u0A85-\u0A8D]
  946. | [\u0A8F-\u0A91]
  947. | [\u0A93-\u0AA8]
  948. | [\u0AAA-\u0AB0]
  949. | [\u0AB2-\u0AB3]
  950. | [\u0AB5-\u0AB9]
  951. | '\u0ABD'
  952. | '\u0AD0'
  953. | [\u0AE0-\u0AE1]
  954. | [\u0B05-\u0B0C]
  955. | [\u0B0F-\u0B10]
  956. | [\u0B13-\u0B28]
  957. | [\u0B2A-\u0B30]
  958. | [\u0B32-\u0B33]
  959. | [\u0B35-\u0B39]
  960. | '\u0B3D'
  961. | [\u0B5C-\u0B5D]
  962. | [\u0B5F-\u0B61]
  963. | '\u0B71'
  964. | '\u0B83'
  965. | [\u0B85-\u0B8A]
  966. | [\u0B8E-\u0B90]
  967. | [\u0B92-\u0B95]
  968. | [\u0B99-\u0B9A]
  969. | '\u0B9C'
  970. | [\u0B9E-\u0B9F]
  971. | [\u0BA3-\u0BA4]
  972. | [\u0BA8-\u0BAA]
  973. | [\u0BAE-\u0BB9]
  974. | [\u0C05-\u0C0C]
  975. | [\u0C0E-\u0C10]
  976. | [\u0C12-\u0C28]
  977. | [\u0C2A-\u0C33]
  978. | [\u0C35-\u0C39]
  979. | [\u0C60-\u0C61]
  980. | [\u0C85-\u0C8C]
  981. | [\u0C8E-\u0C90]
  982. | [\u0C92-\u0CA8]
  983. | [\u0CAA-\u0CB3]
  984. | [\u0CB5-\u0CB9]
  985. | '\u0CBD'
  986. | '\u0CDE'
  987. | [\u0CE0-\u0CE1]
  988. | [\u0D05-\u0D0C]
  989. | [\u0D0E-\u0D10]
  990. | [\u0D12-\u0D28]
  991. | [\u0D2A-\u0D39]
  992. | [\u0D60-\u0D61]
  993. | [\u0D85-\u0D96]
  994. | [\u0D9A-\u0DB1]
  995. | [\u0DB3-\u0DBB]
  996. | '\u0DBD'
  997. | [\u0DC0-\u0DC6]
  998. | [\u0E01-\u0E30]
  999. | [\u0E32-\u0E33]
  1000. | [\u0E40-\u0E45]
  1001. | '\u0E46'
  1002. | [\u0E81-\u0E82]
  1003. | '\u0E84'
  1004. | [\u0E87-\u0E88]
  1005. | '\u0E8A'
  1006. | '\u0E8D'
  1007. | [\u0E94-\u0E97]
  1008. | [\u0E99-\u0E9F]
  1009. | [\u0EA1-\u0EA3]
  1010. | '\u0EA5'
  1011. | '\u0EA7'
  1012. | [\u0EAA-\u0EAB]
  1013. | [\u0EAD-\u0EB0]
  1014. | [\u0EB2-\u0EB3]
  1015. | '\u0EBD'
  1016. | [\u0EC0-\u0EC4]
  1017. | '\u0EC6'
  1018. | [\u0EDC-\u0EDD]
  1019. | '\u0F00'
  1020. | [\u0F40-\u0F47]
  1021. | [\u0F49-\u0F6A]
  1022. | [\u0F88-\u0F8B]
  1023. | [\u1000-\u1021]
  1024. | [\u1023-\u1027]
  1025. | [\u1029-\u102A]
  1026. | [\u1050-\u1055]
  1027. | [\u10A0-\u10C5]
  1028. | [\u10D0-\u10FA]
  1029. | '\u10FC'
  1030. | [\u1100-\u1159]
  1031. | [\u115F-\u11A2]
  1032. | [\u11A8-\u11F9]
  1033. | [\u1200-\u1248]
  1034. | [\u124A-\u124D]
  1035. | [\u1250-\u1256]
  1036. | '\u1258'
  1037. | [\u125A-\u125D]
  1038. | [\u1260-\u1288]
  1039. | [\u128A-\u128D]
  1040. | [\u1290-\u12B0]
  1041. | [\u12B2-\u12B5]
  1042. | [\u12B8-\u12BE]
  1043. | '\u12C0'
  1044. | [\u12C2-\u12C5]
  1045. | [\u12C8-\u12D6]
  1046. | [\u12D8-\u1310]
  1047. | [\u1312-\u1315]
  1048. | [\u1318-\u135A]
  1049. | [\u1380-\u138F]
  1050. | [\u13A0-\u13F4]
  1051. | [\u1401-\u166C]
  1052. | [\u166F-\u1676]
  1053. | [\u1681-\u169A]
  1054. | [\u16A0-\u16EA]
  1055. | [\u16EE-\u16F0]
  1056. | [\u1700-\u170C]
  1057. | [\u170E-\u1711]
  1058. | [\u1720-\u1731]
  1059. | [\u1740-\u1751]
  1060. | [\u1760-\u176C]
  1061. | [\u176E-\u1770]
  1062. | [\u1780-\u17B3]
  1063. | '\u17D7'
  1064. | '\u17DC'
  1065. | [\u1820-\u1842]
  1066. | '\u1843'
  1067. | [\u1844-\u1877]
  1068. | [\u1880-\u18A8]
  1069. | [\u1900-\u191C]
  1070. | [\u1950-\u196D]
  1071. | [\u1970-\u1974]
  1072. | [\u1980-\u19A9]
  1073. | [\u19C1-\u19C7]
  1074. | [\u1A00-\u1A16]
  1075. | [\u1D00-\u1D2B]
  1076. | [\u1D2C-\u1D61]
  1077. | [\u1D62-\u1D77]
  1078. | '\u1D78'
  1079. | [\u1D79-\u1D9A]
  1080. | [\u1D9B-\u1DBF]
  1081. | [\u1E00-\u1E9B]
  1082. | [\u1EA0-\u1EF9]
  1083. | [\u1F00-\u1F15]
  1084. | [\u1F18-\u1F1D]
  1085. | [\u1F20-\u1F45]
  1086. | [\u1F48-\u1F4D]
  1087. | [\u1F50-\u1F57]
  1088. | '\u1F59'
  1089. | '\u1F5B'
  1090. | '\u1F5D'
  1091. | [\u1F5F-\u1F7D]
  1092. | [\u1F80-\u1FB4]
  1093. | [\u1FB6-\u1FBC]
  1094. | '\u1FBE'
  1095. | [\u1FC2-\u1FC4]
  1096. | [\u1FC6-\u1FCC]
  1097. | [\u1FD0-\u1FD3]
  1098. | [\u1FD6-\u1FDB]
  1099. | [\u1FE0-\u1FEC]
  1100. | [\u1FF2-\u1FF4]
  1101. | [\u1FF6-\u1FFC]
  1102. | '\u2071'
  1103. | '\u207F'
  1104. | [\u2090-\u2094]
  1105. | '\u2102'
  1106. | '\u2107'
  1107. | [\u210A-\u2113]
  1108. | '\u2115'
  1109. | '\u2118'
  1110. | [\u2119-\u211D]
  1111. | '\u2124'
  1112. | '\u2126'
  1113. | '\u2128'
  1114. | [\u212A-\u212D]
  1115. | '\u212E'
  1116. | [\u212F-\u2131]
  1117. | [\u2133-\u2134]
  1118. | [\u2135-\u2138]
  1119. | '\u2139'
  1120. | [\u213C-\u213F]
  1121. | [\u2145-\u2149]
  1122. | [\u2160-\u2183]
  1123. | [\u2C00-\u2C2E]
  1124. | [\u2C30-\u2C5E]
  1125. | [\u2C80-\u2CE4]
  1126. | [\u2D00-\u2D25]
  1127. | [\u2D30-\u2D65]
  1128. | '\u2D6F'
  1129. | [\u2D80-\u2D96]
  1130. | [\u2DA0-\u2DA6]
  1131. | [\u2DA8-\u2DAE]
  1132. | [\u2DB0-\u2DB6]
  1133. | [\u2DB8-\u2DBE]
  1134. | [\u2DC0-\u2DC6]
  1135. | [\u2DC8-\u2DCE]
  1136. | [\u2DD0-\u2DD6]
  1137. | [\u2DD8-\u2DDE]
  1138. | '\u3005'
  1139. | '\u3006'
  1140. | '\u3007'
  1141. | [\u3021-\u3029]
  1142. | [\u3031-\u3035]
  1143. | [\u3038-\u303A]
  1144. | '\u303B'
  1145. | '\u303C'
  1146. | [\u3041-\u3096]
  1147. | [\u309B-\u309C]
  1148. | [\u309D-\u309E]
  1149. | '\u309F'
  1150. | [\u30A1-\u30FA]
  1151. | [\u30FC-\u30FE]
  1152. | '\u30FF'
  1153. | [\u3105-\u312C]
  1154. | [\u3131-\u318E]
  1155. | [\u31A0-\u31B7]
  1156. | [\u31F0-\u31FF]
  1157. | [\u3400-\u4DB5]
  1158. | [\u4E00-\u9FBB]
  1159. | [\uA000-\uA014]
  1160. | '\uA015'
  1161. | [\uA016-\uA48C]
  1162. | [\uA800-\uA801]
  1163. | [\uA803-\uA805]
  1164. | [\uA807-\uA80A]
  1165. | [\uA80C-\uA822]
  1166. | [\uAC00-\uD7A3]
  1167. | [\uF900-\uFA2D]
  1168. | [\uFA30-\uFA6A]
  1169. | [\uFA70-\uFAD9]
  1170. | [\uFB00-\uFB06]
  1171. | [\uFB13-\uFB17]
  1172. | '\uFB1D'
  1173. | [\uFB1F-\uFB28]
  1174. | [\uFB2A-\uFB36]
  1175. | [\uFB38-\uFB3C]
  1176. | '\uFB3E'
  1177. | [\uFB40-\uFB41]
  1178. | [\uFB43-\uFB44]
  1179. | [\uFB46-\uFBB1]
  1180. | [\uFBD3-\uFD3D]
  1181. | [\uFD50-\uFD8F]
  1182. | [\uFD92-\uFDC7]
  1183. | [\uFDF0-\uFDFB]
  1184. | [\uFE70-\uFE74]
  1185. | [\uFE76-\uFEFC]
  1186. | [\uFF21-\uFF3A]
  1187. | [\uFF41-\uFF5A]
  1188. | [\uFF66-\uFF6F]
  1189. | '\uFF70'
  1190. | [\uFF71-\uFF9D]
  1191. | [\uFF9E-\uFF9F]
  1192. | [\uFFA0-\uFFBE]
  1193. | [\uFFC2-\uFFC7]
  1194. | [\uFFCA-\uFFCF]
  1195. | [\uFFD2-\uFFD7]
  1196. | [\uFFDA-\uFFDC]
  1197. ;
  1198. /// id_continue ::= <all characters in id_start, plus characters in the categories Mn, Mc, Nd, Pc and others with the Other_ID_Continue property>
  1199. fragment ID_CONTINUE
  1200. : ID_START
  1201. | [0-9]
  1202. | [\u0300-\u036F]
  1203. | [\u0483-\u0486]
  1204. | [\u0591-\u05B9]
  1205. | [\u05BB-\u05BD]
  1206. | '\u05BF'
  1207. | [\u05C1-\u05C2]
  1208. | [\u05C4-\u05C5]
  1209. | '\u05C7'
  1210. | [\u0610-\u0615]
  1211. | [\u064B-\u065E]
  1212. | [\u0660-\u0669]
  1213. | '\u0670'
  1214. | [\u06D6-\u06DC]
  1215. | [\u06DF-\u06E4]
  1216. | [\u06E7-\u06E8]
  1217. | [\u06EA-\u06ED]
  1218. | [\u06F0-\u06F9]
  1219. | '\u0711'
  1220. | [\u0730-\u074A]
  1221. | [\u07A6-\u07B0]
  1222. | [\u0901-\u0902]
  1223. | '\u0903'
  1224. | '\u093C'
  1225. | [\u093E-\u0940]
  1226. | [\u0941-\u0948]
  1227. | [\u0949-\u094C]
  1228. | '\u094D'
  1229. | [\u0951-\u0954]
  1230. | [\u0962-\u0963]
  1231. | [\u0966-\u096F]
  1232. | '\u0981'
  1233. | [\u0982-\u0983]
  1234. | '\u09BC'
  1235. | [\u09BE-\u09C0]
  1236. | [\u09C1-\u09C4]
  1237. | [\u09C7-\u09C8]
  1238. | [\u09CB-\u09CC]
  1239. | '\u09CD'
  1240. | '\u09D7'
  1241. | [\u09E2-\u09E3]
  1242. | [\u09E6-\u09EF]
  1243. | [\u0A01-\u0A02]
  1244. | '\u0A03'
  1245. | '\u0A3C'
  1246. | [\u0A3E-\u0A40]
  1247. | [\u0A41-\u0A42]
  1248. | [\u0A47-\u0A48]
  1249. | [\u0A4B-\u0A4D]
  1250. | [\u0A66-\u0A6F]
  1251. | [\u0A70-\u0A71]
  1252. | [\u0A81-\u0A82]
  1253. | '\u0A83'
  1254. | '\u0ABC'
  1255. | [\u0ABE-\u0AC0]
  1256. | [\u0AC1-\u0AC5]
  1257. | [\u0AC7-\u0AC8]
  1258. | '\u0AC9'
  1259. | [\u0ACB-\u0ACC]
  1260. | '\u0ACD'
  1261. | [\u0AE2-\u0AE3]
  1262. | [\u0AE6-\u0AEF]
  1263. | '\u0B01'
  1264. | [\u0B02-\u0B03]
  1265. | '\u0B3C'
  1266. | '\u0B3E'
  1267. | '\u0B3F'
  1268. | '\u0B40'
  1269. | [\u0B41-\u0B43]
  1270. | [\u0B47-\u0B48]
  1271. | [\u0B4B-\u0B4C]
  1272. | '\u0B4D'
  1273. | '\u0B56'
  1274. | '\u0B57'
  1275. | [\u0B66-\u0B6F]
  1276. | '\u0B82'
  1277. | [\u0BBE-\u0BBF]
  1278. | '\u0BC0'
  1279. | [\u0BC1-\u0BC2]
  1280. | [\u0BC6-\u0BC8]
  1281. | [\u0BCA-\u0BCC]
  1282. | '\u0BCD'
  1283. | '\u0BD7'
  1284. | [\u0BE6-\u0BEF]
  1285. | [\u0C01-\u0C03]
  1286. | [\u0C3E-\u0C40]
  1287. | [\u0C41-\u0C44]
  1288. | [\u0C46-\u0C48]
  1289. | [\u0C4A-\u0C4D]
  1290. | [\u0C55-\u0C56]
  1291. | [\u0C66-\u0C6F]
  1292. | [\u0C82-\u0C83]
  1293. | '\u0CBC'
  1294. | '\u0CBE'
  1295. | '\u0CBF'
  1296. | [\u0CC0-\u0CC4]
  1297. | '\u0CC6'
  1298. | [\u0CC7-\u0CC8]
  1299. | [\u0CCA-\u0CCB]
  1300. | [\u0CCC-\u0CCD]
  1301. | [\u0CD5-\u0CD6]
  1302. | [\u0CE6-\u0CEF]
  1303. | [\u0D02-\u0D03]
  1304. | [\u0D3E-\u0D40]
  1305. | [\u0D41-\u0D43]
  1306. | [\u0D46-\u0D48]
  1307. | [\u0D4A-\u0D4C]
  1308. | '\u0D4D'
  1309. | '\u0D57'
  1310. | [\u0D66-\u0D6F]
  1311. | [\u0D82-\u0D83]
  1312. | '\u0DCA'
  1313. | [\u0DCF-\u0DD1]
  1314. | [\u0DD2-\u0DD4]
  1315. | '\u0DD6'
  1316. | [\u0DD8-\u0DDF]
  1317. | [\u0DF2-\u0DF3]
  1318. | '\u0E31'
  1319. | [\u0E34-\u0E3A]
  1320. | [\u0E47-\u0E4E]
  1321. | [\u0E50-\u0E59]
  1322. | '\u0EB1'
  1323. | [\u0EB4-\u0EB9]
  1324. | [\u0EBB-\u0EBC]
  1325. | [\u0EC8-\u0ECD]
  1326. | [\u0ED0-\u0ED9]
  1327. | [\u0F18-\u0F19]
  1328. | [\u0F20-\u0F29]
  1329. | '\u0F35'
  1330. | '\u0F37'
  1331. | '\u0F39'
  1332. | [\u0F3E-\u0F3F]
  1333. | [\u0F71-\u0F7E]
  1334. | '\u0F7F'
  1335. | [\u0F80-\u0F84]
  1336. | [\u0F86-\u0F87]
  1337. | [\u0F90-\u0F97]
  1338. | [\u0F99-\u0FBC]
  1339. | '\u0FC6'
  1340. | '\u102C'
  1341. | [\u102D-\u1030]
  1342. | '\u1031'
  1343. | '\u1032'
  1344. | [\u1036-\u1037]
  1345. | '\u1038'
  1346. | '\u1039'
  1347. | [\u1040-\u1049]
  1348. | [\u1056-\u1057]
  1349. | [\u1058-\u1059]
  1350. | '\u135F'
  1351. | [\u1369-\u1371]
  1352. | [\u1712-\u1714]
  1353. | [\u1732-\u1734]
  1354. | [\u1752-\u1753]
  1355. | [\u1772-\u1773]
  1356. | '\u17B6'
  1357. | [\u17B7-\u17BD]
  1358. | [\u17BE-\u17C5]
  1359. | '\u17C6'
  1360. | [\u17C7-\u17C8]
  1361. | [\u17C9-\u17D3]
  1362. | '\u17DD'
  1363. | [\u17E0-\u17E9]
  1364. | [\u180B-\u180D]
  1365. | [\u1810-\u1819]
  1366. | '\u18A9'
  1367. | [\u1920-\u1922]
  1368. | [\u1923-\u1926]
  1369. | [\u1927-\u1928]
  1370. | [\u1929-\u192B]
  1371. | [\u1930-\u1931]
  1372. | '\u1932'
  1373. | [\u1933-\u1938]
  1374. | [\u1939-\u193B]
  1375. | [\u1946-\u194F]
  1376. | [\u19B0-\u19C0]
  1377. | [\u19C8-\u19C9]
  1378. | [\u19D0-\u19D9]
  1379. | [\u1A17-\u1A18]
  1380. | [\u1A19-\u1A1B]
  1381. | [\u1DC0-\u1DC3]
  1382. | [\u203F-\u2040]
  1383. | '\u2054'
  1384. | [\u20D0-\u20DC]
  1385. | '\u20E1'
  1386. | [\u20E5-\u20EB]
  1387. | [\u302A-\u302F]
  1388. | [\u3099-\u309A]
  1389. | '\uA802'
  1390. | '\uA806'
  1391. | '\uA80B'
  1392. | [\uA823-\uA824]
  1393. | [\uA825-\uA826]
  1394. | '\uA827'
  1395. | '\uFB1E'
  1396. | [\uFE00-\uFE0F]
  1397. | [\uFE20-\uFE23]
  1398. | [\uFE33-\uFE34]
  1399. | [\uFE4D-\uFE4F]
  1400. | [\uFF10-\uFF19]
  1401. | '\uFF3F'
  1402. ;