sccd_grammar.g 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. start: sccd;
  2. sccd: diagram INDENT (top)? element+ (bottom)? DEDENT;
  3. @element: (inport | class);
  4. inport: INPORT LPAR nameattr RPAR NEWLINE;
  5. nameattr: NAMEATTR ASSIGN string;
  6. defaultattr: DEFAULTATTR ASSIGN boolean;
  7. classattr: CLASSATTR ASSIGN string;
  8. class: CLASS LPAR classdefattrs RPAR
  9. ( (COLON NEWLINE INDENT classelement+ DEDENT) | NEWLINE);
  10. classdefattrs: classdefattr (COMMA classdefattr)*;
  11. classdefattr: nameattr | defaultattr;
  12. @classelement: inport | association | inheritance | aggregation | composition |
  13. attribute | constructor | destructor | method | statemachine;
  14. aggregation: AGGREGATION LPAR aggregattrs RPAR NEWLINE;
  15. aggregattrs: relattr (COMMA relattr)*;
  16. composition: COMPOSITION LPAR compattrs RPAR NEWLINE;
  17. compattrs: relattr (COMMA relattr)*;
  18. @relattr: classattr | minattr | maxattr;
  19. minattr: MIN ASSIGN integer;
  20. maxattr: MAX ASSIGN integer;
  21. association: ASSOCIATION LPAR assocattrs RPAR NEWLINE;
  22. assocattrs: assocattr (COMMA assocattr)*;
  23. assocattr: nameattr | relattr;
  24. inheritance: INHERITANCE LPAR inherattrs RPAR NEWLINE;
  25. inherattrs: inherattr (COMMA inherattr)*;
  26. inherattr: priorityattr | classattr;
  27. priorityattr: PRIORITYATTR ASSIGN integer;
  28. attribute: ATTRIBUTE LPAR attributeattrs RPAR NEWLINE;
  29. attributeattrs: attributeattr (COMMA attributeattr)*;
  30. attributeattr: nameattr | defaultvalueattr | typenameattr;
  31. defaultvalueattr: DEFAULTATTR ASSIGN string;
  32. typenameattr: TYPEATTR ASSIGN string;
  33. diagram: DIAGRAM (NEWLINE)+;
  34. DIAGRAM: 'Diagram\([^\)]*\):'
  35. {
  36. start: 'Diagram\(' attrs '\)' ':';
  37. @attr: (attrname|attrauthor|attrdescription);
  38. @attrs: attr (',' attr)*;
  39. attrname: ATTRNAME '=' string;
  40. attrauthor: ATTRAUTHOR '=' string;
  41. attrdescription: ATTRDESCRIPTION '=' string;
  42. ATTRNAME: 'name';
  43. ATTRAUTHOR: 'author';
  44. ATTRDESCRIPTION: 'description';
  45. string: (STRVALUE|LONG_STRVALUE) string? ;
  46. STRVALUE : 'u?r?("(?!"").*?(?<!\\)(\\\\)*?"|\'(?!\'\').*?(?<!\\)(\\\\)*?\')' ;
  47. LONG_STRVALUE : '(?s)u?r?(""".*?(?<!\\)(\\\\)*?"""|\'\'\'.*?(?<!\\)(\\\\)*?\'\'\')'
  48. (%newline)
  49. ;
  50. WS: '[\t \f\n]+' (%ignore);
  51. COMMENT: '\#[^\n]*'(%ignore);
  52. };
  53. top: TOP BODY NEWLINE;
  54. bottom: BOTTOM BODY;
  55. constructor: CONSTRUCTOR body NEWLINE;
  56. destructor: DESTRUCTOR body NEWLINE;
  57. method: METHOD body NEWLINE;
  58. statemachine: STATEMACHINE (NEWLINE |
  59. (COLON NEWLINE INDENT (state | orthogonal | pseudostate | transition)+ DEDENT));
  60. @state_element: state | orthogonal | pseudostate | transition | onenter | onexit;
  61. onenter: ONENTER BODY NEWLINE;
  62. onexit: ONEXIT BODY NEWLINE;
  63. state: STATE LPAR statename RPAR (NEWLINE |
  64. (COLON NEWLINE INDENT state_element+ DEDENT));
  65. orthogonal: ORTHOGONAL LPAR statename RPAR (NEWLINE |
  66. (COLON NEWLINE INDENT state_element+ DEDENT));
  67. @pseudostate: (initial | final | history) NEWLINE;
  68. initial: INITIAL ASSIGN statename;
  69. final: FINAL ASSIGN statename;
  70. history: HISTORY ASSIGN statename;
  71. statename: string;
  72. transition: TRANSITION LPAR transitionattrs RPAR (NEWLINE |
  73. (COLON NEWLINE INDENT event? guard? raise* actions? DEDENT));
  74. transitionattrs: transitionattr (COMMA transitionattr)*;
  75. transitionattr: (portattr | targetattr | afterattr);
  76. portattr: PORTATTR ASSIGN string;
  77. targetattr: TARGETATTR ASSIGN string;
  78. afterattr: AFTERATTR;
  79. AFTERATTR: 'after\([^\)]+\)'
  80. {
  81. start: AFTER LPAR expression RPAR;
  82. funccall_expr: (expression '->')? functionname LPAR arguments? RPAR;
  83. functionname: name;
  84. nav_expr: self? | (self DOT)? dotexpression;
  85. self: SELF;
  86. dotexpression: dotted_name;
  87. arguments: argument (COMMA argument)*;
  88. argument: (argumentname ASSIGN)? expression;
  89. argumentname: name;
  90. expression: nav_expr | atomvalue | tuple | vector | dict |
  91. unopexpr | binopexpr | funccall_expr | selection;
  92. atomvalue: integervalue | floatvalue | booleanvalue | stringvalue;
  93. integervalue: integer;
  94. floatvalue: float;
  95. booleanvalue: boolean;
  96. stringvalue: string;
  97. @unopexpr: parexpr | notexpr | minusexpr;
  98. parexpr: LPAR expression RPAR;
  99. notexpr: NOT expression;
  100. minusexpr: MINUS expression;
  101. @binopexpr: selection | andexpr | orexpr | lthanexpr | leqthanexpr |
  102. gthanexpr | geqthanexpr | equalsexpr | nequalsexpr |
  103. multexpr | divexpr | modexpr | subtractionexpr | sumexpr;
  104. dict: LSQBR NEWLINE? dictitems NEWLINE? RSQBR;
  105. dictitems: dictitem (COMMA NEWLINE? dictitem)*;
  106. dictitem: expression COLON expression;
  107. vector: LSQBR NEWLINE? (vectoritems NEWLINE?)? RSQBR;
  108. vectoritems: vectoritem (COMMA NEWLINE? vectoritem)*;
  109. vectoritem: expression;
  110. tuple: LPAR tuplearg (COMMA tuplearg)+ RPAR;
  111. tuplearg: expression;
  112. selection: expression LSQBR expression RSQBR;
  113. andexpr: expression LAND expression;
  114. orexpr: expression LOR expression;
  115. lthanexpr: expression LTHAN expression;
  116. leqthanexpr: expression LEQTHAN expression;
  117. gthanexpr: expression GTHAN expression;
  118. geqthanexpr: expression GEQTHAN expression;
  119. equalsexpr: expression EQUALS expression;
  120. nequalsexpr: expression NEQUALS expression;
  121. subtractionexpr: expression MINUS expression;
  122. sumexpr: expression PLUS expression;
  123. multexpr: expression MULT expression;
  124. divexpr: expression DIV expression;
  125. modexpr: expression MOD expression;
  126. dotted_name: name (DOT name)*;
  127. name: NAME;
  128. NAME: '[a-zA-Z_][a-zA-Z_0-9]*(?!r?"|r?\')'
  129. (%unless
  130. NOT: 'not';
  131. TRUE: 'True';
  132. FALSE: 'False';
  133. LAND: 'and';
  134. LOR: 'or';
  135. AFTER: 'after';
  136. SELF: 'self';
  137. );
  138. boolean: TRUE | FALSE;
  139. DEC_NUMBER: '[+-]?(0|[1-9]\d*[lL]?)';
  140. FLOAT_NUMBER: '[+-]?((\d+\.\d*|\.\d+)([eE][-+]?\d+)?|\d+[eE][-+]?\d+)';
  141. integer: DEC_NUMBER;
  142. float: FLOAT_NUMBER;
  143. STRVALUE : 'u?r?("(?!"").*?(?<!\\)(\\\\)*?"|\'(?!\'\').*?(?<!\\)(\\\\)*?\')' ;
  144. LONG_STRVALUE : '(?s)u?r?(""".*?(?<!\\)(\\\\)*?"""|\'\'\'.*?(?<!\\)(\\\\)*?\'\'\')'
  145. (%newline)
  146. ;
  147. string: (STRVALUE|LONG_STRVALUE) string?;
  148. MULT: '\*';
  149. DIV: '/';
  150. POTENCY: '@\d';
  151. LTHAN: '<';
  152. LEQTHAN: '<=';
  153. GTHAN: '>';
  154. GEQTHAN: '>=';
  155. ASSIGN: '=';
  156. DOT: '\.';
  157. COLON: ':';
  158. LPAR: '\(';
  159. RPAR: '\)';
  160. COMMA: ',';
  161. EQUALS: '==';
  162. NEQUALS: '!=';
  163. PLUS: '\+';
  164. MINUS: '-';
  165. MOD: '%';
  166. LSQBR: '\[';
  167. RSQBR: '\]';
  168. LBR: '\{';
  169. RBR: '\}';
  170. NEWLINE: '(\r?\n[\t ]*)+'
  171. (%newline)
  172. ;
  173. WS: '[\t \f]+' (%ignore);
  174. COMMENT: '\#[^\n]*'(%ignore);
  175. };
  176. event: EVENT NEWLINE;
  177. EVENT: 'event\ =\ [^\(]+\([^\)]*\)'
  178. {
  179. start: EVENT ASSIGN namevalue LPAR formalparameters? RPAR;
  180. formalparameters: formalparameter (COMMA formalparameter)*;
  181. formalparameter: namevalue COLON nav_expr (ASSIGN defaultvalue)?;
  182. namevalue: name;
  183. nav_expr: self? | (self DOT)? dotexpression;
  184. self: SELF;
  185. dotexpression: dotted_name;
  186. defaultvalue: atomvalue;
  187. atomvalue: integervalue | floatvalue | booleanvalue | stringvalue;
  188. integervalue: integer;
  189. floatvalue: float;
  190. booleanvalue: boolean;
  191. stringvalue: string;
  192. dotted_name: name (DOT name)*;
  193. name: NAME;
  194. NAME: '[a-zA-Z_][a-zA-Z_0-9\-]*(?!r?"|r?\')'
  195. (%unless
  196. EVENT: 'event';
  197. TRUE: 'True';
  198. FALSE: 'False';
  199. SELF: 'self';
  200. );
  201. boolean: TRUE | FALSE;
  202. DEC_NUMBER: '[+-]?(0|[1-9]\d*[lL]?)';
  203. FLOAT_NUMBER: '[+-]?((\d+\.\d*|\.\d+)([eE][-+]?\d+)?|\d+[eE][-+]?\d+)';
  204. integer: DEC_NUMBER;
  205. float: FLOAT_NUMBER;
  206. STRVALUE : 'u?r?("(?!"").*?(?<!\\)(\\\\)*?"|\'(?!\'\').*?(?<!\\)(\\\\)*?\')' ;
  207. LONG_STRVALUE : '(?s)u?r?(""".*?(?<!\\)(\\\\)*?"""|\'\'\'.*?(?<!\\)(\\\\)*?\'\'\')'
  208. (%newline)
  209. ;
  210. string: (STRVALUE|LONG_STRVALUE) string?;
  211. ASSIGN: '=';
  212. DOT: '\.';
  213. COLON: ':';
  214. LPAR: '\(';
  215. RPAR: '\)';
  216. COMMA: ',';
  217. WS: '[\t \f\n]+' (%ignore);
  218. COMMENT: '\#[^\n]*'(%ignore);
  219. };
  220. guard: GUARD NEWLINE;
  221. GUARD: 'guard\ =\ \{[^\}]*\}'
  222. {
  223. start: GUARD ASSIGN LBR expression RBR;
  224. funccall_expr: (expression '->')? functionname LPAR arguments? RPAR;
  225. functionname: name;
  226. nav_expr: self? | (self DOT)? dotexpression;
  227. self: SELF;
  228. dotexpression: dotted_name;
  229. arguments: argument (COMMA argument)*;
  230. argument: (argumentname ASSIGN)? expression;
  231. argumentname: name;
  232. expression: nav_expr | atomvalue | tuple | vector | dict |
  233. unopexpr | binopexpr | funccall_expr | selection;
  234. atomvalue: integervalue | floatvalue | booleanvalue | stringvalue;
  235. integervalue: integer;
  236. floatvalue: float;
  237. booleanvalue: boolean;
  238. stringvalue: string;
  239. @unopexpr: parexpr | notexpr | minusexpr;
  240. parexpr: LPAR expression RPAR;
  241. notexpr: NOT expression;
  242. minusexpr: MINUS expression;
  243. @binopexpr: selection | andexpr | orexpr | lthanexpr | leqthanexpr |
  244. gthanexpr | geqthanexpr | equalsexpr | nequalsexpr |
  245. multexpr | divexpr | modexpr | subtractionexpr | sumexpr;
  246. dict: LSQBR NEWLINE? dictitems NEWLINE? RSQBR;
  247. dictitems: dictitem (COMMA NEWLINE? dictitem)*;
  248. dictitem: expression COLON expression;
  249. vector: LSQBR NEWLINE? (vectoritems NEWLINE?)? RSQBR;
  250. vectoritems: vectoritem (COMMA NEWLINE? vectoritem)*;
  251. vectoritem: expression;
  252. tuple: LPAR tuplearg (COMMA tuplearg)+ RPAR;
  253. tuplearg: expression;
  254. selection: expression LSQBR expression RSQBR;
  255. andexpr: expression LAND expression;
  256. orexpr: expression LOR expression;
  257. lthanexpr: expression LTHAN expression;
  258. leqthanexpr: expression LEQTHAN expression;
  259. gthanexpr: expression GTHAN expression;
  260. geqthanexpr: expression GEQTHAN expression;
  261. equalsexpr: expression EQUALS expression;
  262. nequalsexpr: expression NEQUALS expression;
  263. subtractionexpr: expression MINUS expression;
  264. sumexpr: expression PLUS expression;
  265. multexpr: expression MULT expression;
  266. divexpr: expression DIV expression;
  267. modexpr: expression MOD expression;
  268. dotted_name: name (DOT name)*;
  269. name: NAME;
  270. NAME: '[a-zA-Z_][a-zA-Z_0-9]*(?!r?"|r?\')'
  271. (%unless
  272. NOT: 'not';
  273. TRUE: 'True';
  274. FALSE: 'False';
  275. LAND: 'and';
  276. LOR: 'or';
  277. GUARD: 'guard';
  278. SELF: 'self';
  279. );
  280. boolean: TRUE | FALSE;
  281. DEC_NUMBER: '[+-]?(0|[1-9]\d*[lL]?)';
  282. FLOAT_NUMBER: '[+-]?((\d+\.\d*|\.\d+)([eE][-+]?\d+)?|\d+[eE][-+]?\d+)';
  283. integer: DEC_NUMBER;
  284. float: FLOAT_NUMBER;
  285. STRVALUE : 'u?r?("(?!"").*?(?<!\\)(\\\\)*?"|\'(?!\'\').*?(?<!\\)(\\\\)*?\')' ;
  286. LONG_STRVALUE : '(?s)u?r?(""".*?(?<!\\)(\\\\)*?"""|\'\'\'.*?(?<!\\)(\\\\)*?\'\'\')'
  287. (%newline)
  288. ;
  289. string: (STRVALUE|LONG_STRVALUE) string?;
  290. MULT: '\*';
  291. DIV: '/';
  292. POTENCY: '@\d';
  293. LTHAN: '<';
  294. LEQTHAN: '<=';
  295. GTHAN: '>';
  296. GEQTHAN: '>=';
  297. ASSIGN: '=';
  298. DOT: '\.';
  299. COLON: ':';
  300. LPAR: '\(';
  301. RPAR: '\)';
  302. COMMA: ',';
  303. EQUALS: '==';
  304. NEQUALS: '!=';
  305. PLUS: '\+';
  306. MINUS: '-';
  307. MOD: '%';
  308. LSQBR: '\[';
  309. RSQBR: '\]';
  310. LBR: '\{';
  311. RBR: '\}';
  312. NEWLINE: '(\r?\n[\t ]*)+'
  313. (%newline)
  314. ;
  315. WS: '[\t \f]+' (%ignore);
  316. COMMENT: '\#[^\n]*'(%ignore);
  317. };
  318. raise: RAISE NEWLINE;
  319. RAISE: 'raise\ \+=\ \{[^\}]*\}'
  320. {
  321. start: RAISE PLUS ASSIGN LBR scopeattr? targetattr? funccall_expr RBR;
  322. scopeattr: SCOPE ASSIGN expression COMMA;
  323. targetattr: TARGET ASSIGN expression COMMA;
  324. funccall_expr: functionname LPAR arguments? RPAR;
  325. functionname: name;
  326. nav_expr: self? | (self DOT)? dotexpression;
  327. self: SELF;
  328. dotexpression: dotted_name;
  329. arguments: argument (COMMA argument)*;
  330. argument: (argumentname ASSIGN)? expression;
  331. argumentname: name;
  332. expression: nav_expr | atomvalue | tuple | vector | dict |
  333. unopexpr | binopexpr | funccall_expr | selection;
  334. atomvalue: integervalue | floatvalue | booleanvalue | stringvalue;
  335. integervalue: integer;
  336. floatvalue: float;
  337. booleanvalue: boolean;
  338. stringvalue: string;
  339. @unopexpr: parexpr | notexpr | minusexpr;
  340. parexpr: LPAR expression RPAR;
  341. notexpr: NOT expression;
  342. minusexpr: MINUS expression;
  343. @binopexpr: selection | andexpr | orexpr | lthanexpr | leqthanexpr |
  344. gthanexpr | geqthanexpr | equalsexpr | nequalsexpr |
  345. multexpr | divexpr | modexpr | subtractionexpr | sumexpr;
  346. dict: LSQBR NEWLINE? dictitems NEWLINE? RSQBR;
  347. dictitems: dictitem (COMMA NEWLINE? dictitem)*;
  348. dictitem: expression COLON expression;
  349. vector: LSQBR NEWLINE? (vectoritems NEWLINE?)? RSQBR;
  350. vectoritems: vectoritem (COMMA NEWLINE? vectoritem)*;
  351. vectoritem: expression;
  352. tuple: LPAR tuplearg (COMMA tuplearg)+ RPAR;
  353. tuplearg: expression;
  354. selection: expression LSQBR expression RSQBR;
  355. andexpr: expression LAND expression;
  356. orexpr: expression LOR expression;
  357. lthanexpr: expression LTHAN expression;
  358. leqthanexpr: expression LEQTHAN expression;
  359. gthanexpr: expression GTHAN expression;
  360. geqthanexpr: expression GEQTHAN expression;
  361. equalsexpr: expression EQUALS expression;
  362. nequalsexpr: expression NEQUALS expression;
  363. subtractionexpr: expression MINUS expression;
  364. sumexpr: expression PLUS expression;
  365. multexpr: expression MULT expression;
  366. divexpr: expression DIV expression;
  367. modexpr: expression MOD expression;
  368. dotted_name: name (DOT name)*;
  369. name: NAME;
  370. NAME: '[a-zA-Z_][a-zA-Z_0-9]*(?!r?"|r?\')'
  371. (%unless
  372. NOT: 'not';
  373. TRUE: 'True';
  374. FALSE: 'False';
  375. LAND: 'and';
  376. LOR: 'or';
  377. RAISE: 'raise';
  378. SCOPE: 'scope';
  379. TARGET: 'target';
  380. SELF: 'self';
  381. );
  382. boolean: TRUE | FALSE;
  383. DEC_NUMBER: '[+-]?(0|[1-9]\d*[lL]?)';
  384. FLOAT_NUMBER: '[+-]?((\d+\.\d*|\.\d+)([eE][-+]?\d+)?|\d+[eE][-+]?\d+)';
  385. integer: DEC_NUMBER;
  386. float: FLOAT_NUMBER;
  387. STRVALUE : 'u?r?("(?!"").*?(?<!\\)(\\\\)*?"|\'(?!\'\').*?(?<!\\)(\\\\)*?\')' ;
  388. LONG_STRVALUE : '(?s)u?r?(""".*?(?<!\\)(\\\\)*?"""|\'\'\'.*?(?<!\\)(\\\\)*?\'\'\')'
  389. (%newline)
  390. ;
  391. string: (STRVALUE|LONG_STRVALUE) string?;
  392. MULT: '\*';
  393. DIV: '/';
  394. POTENCY: '@\d';
  395. LTHAN: '<';
  396. LEQTHAN: '<=';
  397. GTHAN: '>';
  398. GEQTHAN: '>=';
  399. ASSIGN: '=';
  400. DOT: '\.';
  401. COLON: ':';
  402. LPAR: '\(';
  403. RPAR: '\)';
  404. COMMA: ',';
  405. EQUALS: '==';
  406. NEQUALS: '!=';
  407. PLUS: '\+';
  408. MINUS: '-';
  409. MOD: '%';
  410. LSQBR: '\[';
  411. RSQBR: '\]';
  412. LBR: '\{';
  413. RBR: '\}';
  414. NEWLINE: '(\r?\n[\t ]*)+'
  415. (%newline)
  416. ;
  417. WS: '[\t \f]+' (%ignore);
  418. COMMENT: '\#[^\n]*'(%ignore);
  419. };
  420. actions: ACTIONS body NEWLINE;
  421. CONSTRUCTOR: 'Constructor(\([^\)]*\))?'
  422. {
  423. start: CONSTRUCTOR (LPAR formalparameters RPAR)?;
  424. formalparameters: formalparameter (COMMA formalparameter)*;
  425. formalparameter: namevalue (COLON nav_expr)?(ASSIGN defaultvalue)?;
  426. namevalue: name;
  427. nav_expr: self? | (self DOT)? dotexpression;
  428. self: SELF;
  429. dotexpression: dotted_name;
  430. defaultvalue: atomvalue;
  431. atomvalue: integervalue | floatvalue | booleanvalue | stringvalue;
  432. integervalue: integer;
  433. floatvalue: float;
  434. booleanvalue: boolean;
  435. stringvalue: string;
  436. dotted_name: name (DOT name)*;
  437. name: NAME;
  438. NAME: '[a-zA-Z_][a-zA-Z_0-9]*(?!r?"|r?\')'
  439. (%unless
  440. TRUE: 'True';
  441. FALSE: 'False';
  442. CONSTRUCTOR: 'Constructor';
  443. SELF: 'self';
  444. );
  445. boolean: TRUE | FALSE;
  446. DEC_NUMBER: '[+-]?(0|[1-9]\d*[lL]?)';
  447. FLOAT_NUMBER: '[+-]?((\d+\.\d*|\.\d+)([eE][-+]?\d+)?|\d+[eE][-+]?\d+)';
  448. integer: DEC_NUMBER;
  449. float: FLOAT_NUMBER;
  450. STRVALUE : 'u?r?("(?!"").*?(?<!\\)(\\\\)*?"|\'(?!\'\').*?(?<!\\)(\\\\)*?\')' ;
  451. LONG_STRVALUE : '(?s)u?r?(""".*?(?<!\\)(\\\\)*?"""|\'\'\'.*?(?<!\\)(\\\\)*?\'\'\')'
  452. (%newline)
  453. ;
  454. string: (STRVALUE|LONG_STRVALUE) string?;
  455. ASSIGN: '=';
  456. DOT: '\.';
  457. COLON: ':';
  458. LPAR: '\(';
  459. RPAR: '\)';
  460. COMMA: ',';
  461. WS: '[\t \f\n]+' (%ignore);
  462. COMMENT: '\#[^\n]*'(%ignore);
  463. };
  464. METHOD: 'Method [^\(]*\([^\)]*\)'
  465. {
  466. start: METHOD methodname LPAR formalparameters? RPAR;
  467. methodname: name;
  468. formalparameters: formalparameter (COMMA formalparameter)*;
  469. formalparameter: namevalue (COLON nav_expr)?(ASSIGN defaultvalue)?;
  470. namevalue: name;
  471. nav_expr: self? | (self DOT)? dotexpression;
  472. self: SELF;
  473. dotexpression: dotted_name;
  474. defaultvalue: atomvalue;
  475. atomvalue: integervalue | floatvalue | booleanvalue | stringvalue;
  476. integervalue: integer;
  477. floatvalue: float;
  478. booleanvalue: boolean;
  479. stringvalue: string;
  480. dotted_name: name (DOT name)*;
  481. name: NAME;
  482. NAME: '[a-zA-Z_][a-zA-Z_0-9]*(?!r?"|r?\')'
  483. (%unless
  484. TRUE: 'True';
  485. FALSE: 'False';
  486. METHOD: 'Method';
  487. SELF: 'self';
  488. );
  489. boolean: TRUE | FALSE;
  490. DEC_NUMBER: '[+-]?(0|[1-9]\d*[lL]?)';
  491. FLOAT_NUMBER: '[+-]?((\d+\.\d*|\.\d+)([eE][-+]?\d+)?|\d+[eE][-+]?\d+)';
  492. integer: DEC_NUMBER;
  493. float: FLOAT_NUMBER;
  494. STRVALUE : 'u?r?("(?!"").*?(?<!\\)(\\\\)*?"|\'(?!\'\').*?(?<!\\)(\\\\)*?\')' ;
  495. LONG_STRVALUE : '(?s)u?r?(""".*?(?<!\\)(\\\\)*?"""|\'\'\'.*?(?<!\\)(\\\\)*?\'\'\')'
  496. (%newline)
  497. ;
  498. string: (STRVALUE|LONG_STRVALUE) string?;
  499. ASSIGN: '=';
  500. DOT: '\.';
  501. COLON: ':';
  502. LPAR: '\(';
  503. RPAR: '\)';
  504. COMMA: ',';
  505. WS: '[\t \f\n]+' (%ignore);
  506. COMMENT: '\#[^\n]*'(%ignore);
  507. };
  508. body: BODY;
  509. BODY: '\{[^\}]*\}'
  510. {
  511. start: LBR NEWLINE? statement* RBR;
  512. @statement: import | funccall_stm | decl_stm |
  513. assignment | plusassign | minusassign | while_stm
  514. | ifelse_stm | break_stm | continue_stm | return_stm;
  515. decl_stm: nav_expr decl_name (ASSIGN expression)? NEWLINE;
  516. decl_name: name;
  517. return_stm: RETURN (expression)? NEWLINE;
  518. ifelse_stm: IF expression COLON NEWLINE
  519. statementbody
  520. (ELSE COLON NEWLINE
  521. statementbody
  522. )? END NEWLINE
  523. ;
  524. while_stm: WHILE expression COLON NEWLINE statementbody END NEWLINE;
  525. statementbody: statement+;
  526. break_stm: BREAK NEWLINE;
  527. continue_stm: CONTINUE NEWLINE;
  528. import: (FROM fromname)? IMPORT importname (AS asname)? NEWLINE;
  529. fromname: dotted_name;
  530. importname: dotted_name | MULT;
  531. asname: name;
  532. funccall_stm: (expression '->')? functionname LPAR arguments? RPAR NEWLINE;
  533. funccall_expr: (expression '->')? functionname LPAR arguments? RPAR;
  534. nav_expr: self? | (self DOT)? dotexpression;
  535. self: SELF;
  536. dotexpression: dotted_name;
  537. functionname: name;
  538. arguments: argument (COMMA argument)*;
  539. argument: (argumentname ASSIGN)? expression;
  540. argumentname: name;
  541. assignment: expression ASSIGN expression NEWLINE;
  542. plusassign: expression PLUSASSIGN expression NEWLINE;
  543. minusassign: expression MINUSASSIGN expression NEWLINE;
  544. expression: nav_expr | atomvalue | tuple | vector | dict |
  545. unopexpr | binopexpr | funccall_expr | selection;
  546. atomvalue: integervalue | floatvalue | booleanvalue | stringvalue;
  547. integervalue: integer;
  548. floatvalue: float;
  549. booleanvalue: boolean;
  550. stringvalue: string;
  551. @unopexpr: parexpr | notexpr | minusexpr;
  552. parexpr: LPAR expression RPAR;
  553. notexpr: NOT expression;
  554. minusexpr: MINUS expression;
  555. @binopexpr: selection | andexpr | orexpr | lthanexpr | leqthanexpr |
  556. gthanexpr | geqthanexpr | equalsexpr | nequalsexpr |
  557. multexpr | divexpr | modexpr | subtractionexpr | sumexpr;
  558. dict: LSQBR NEWLINE? dictitems NEWLINE? RSQBR;
  559. dictitems: dictitem (COMMA NEWLINE? dictitem)*;
  560. dictitem: expression COLON expression;
  561. vector: LSQBR NEWLINE? (vectoritems NEWLINE?)? RSQBR;
  562. vectoritems: vectoritem (COMMA NEWLINE? vectoritem)*;
  563. vectoritem: expression;
  564. tuple: LPAR tuplearg (COMMA tuplearg)+ RPAR;
  565. tuplearg: expression;
  566. selection: expression LSQBR expression RSQBR;
  567. andexpr: expression LAND expression;
  568. orexpr: expression LOR expression;
  569. lthanexpr: expression LTHAN expression;
  570. leqthanexpr: expression LEQTHAN expression;
  571. gthanexpr: expression GTHAN expression;
  572. geqthanexpr: expression GEQTHAN expression;
  573. equalsexpr: expression EQUALS expression;
  574. nequalsexpr: expression NEQUALS expression;
  575. subtractionexpr: expression MINUS expression;
  576. sumexpr: expression PLUS expression;
  577. multexpr: expression MULT expression;
  578. divexpr: expression DIV expression;
  579. modexpr: expression MOD expression;
  580. dotted_name: name (DOT name)*;
  581. name: NAME;
  582. NAME: '[a-zA-Z_][a-zA-Z_0-9]*(?!r?"|r?\')'
  583. (%unless
  584. IMPORT: 'import';
  585. AS: 'as';
  586. FROM: 'from';
  587. NOT: 'not';
  588. TRUE: 'True';
  589. FALSE: 'False';
  590. LAND: 'and';
  591. LOR: 'or';
  592. IF: 'if';
  593. ELSE: 'else';
  594. WHILE: 'while';
  595. BREAK: 'break';
  596. CONTINUE: 'continue';
  597. RETURN: 'return';
  598. END: 'end';
  599. SELF: 'self';
  600. );
  601. boolean: TRUE | FALSE;
  602. DEC_NUMBER: '[+-]?(0|[1-9]\d*[lL]?)';
  603. FLOAT_NUMBER: '[+-]?((\d+\.\d*|\.\d+)([eE][-+]?\d+)?|\d+[eE][-+]?\d+)';
  604. integer: DEC_NUMBER;
  605. float: FLOAT_NUMBER;
  606. STRVALUE : 'u?r?("(?!"").*?(?<!\\)(\\\\)*?"|\'(?!\'\').*?(?<!\\)(\\\\)*?\')' ;
  607. LONG_STRVALUE : '(?s)u?r?(""".*?(?<!\\)(\\\\)*?"""|\'\'\'.*?(?<!\\)(\\\\)*?\'\'\')'
  608. (%newline)
  609. ;
  610. string: (STRVALUE|LONG_STRVALUE) string?;
  611. MULT: '\*';
  612. DIV: '/';
  613. POTENCY: '@\d';
  614. LTHAN: '<';
  615. LEQTHAN: '<=';
  616. GTHAN: '>';
  617. GEQTHAN: '>=';
  618. ASSIGN: '=';
  619. PLUSASSIGN: '\+=';
  620. MINUSASSIGN: '\-=';
  621. DOT: '\.';
  622. COLON: ':';
  623. LPAR: '\(';
  624. RPAR: '\)';
  625. COMMA: ',';
  626. EQUALS: '==';
  627. NEQUALS: '!=';
  628. PLUS: '\+';
  629. MINUS: '-';
  630. MOD: '%';
  631. LSQBR: '\[';
  632. RSQBR: '\]';
  633. LBR: '\{';
  634. RBR: '\}';
  635. NEWLINE: '(\r?\n[\t ]*)+'
  636. (%newline)
  637. ;
  638. WS: '[\t \f]+' (%ignore);
  639. COMMENT: '\#[^\n]*'(%ignore);
  640. INDENT: '<INDENT>';
  641. DEDENT: '<DEDENT>';
  642. };
  643. // specific tokens
  644. CLASS: 'Class';
  645. TOP: 'Top';
  646. BOTTOM: 'Bottom';
  647. INPORT: 'Inport';
  648. NAMEATTR: 'name';
  649. DEFAULTATTR: 'default';
  650. TYPEATTR: 'type';
  651. CLASSATTR: 'class';
  652. PRIORITYATTR: 'priority';
  653. ASSOCIATION: 'Association';
  654. INHERITANCE: 'Inheritance';
  655. COMPOSITION: 'Composition';
  656. AGGREGATION: 'Aggregation';
  657. ATTRIBUTE: 'Attribute';
  658. MIN: 'min';
  659. MAX: 'max';
  660. DESTRUCTOR: 'Destructor';
  661. STATEMACHINE: 'StateMachine';
  662. STATE: 'State';
  663. INITIAL: 'initial';
  664. FINAL: 'final';
  665. HISTORY: 'history';
  666. ORTHOGONAL: 'Orthogonal';
  667. TRANSITION: 'Transition';
  668. TARGETATTR: 'target';
  669. PORTATTR: 'port';
  670. ACTIONS: 'Actions';
  671. ONENTER: 'OnEnter';
  672. ONEXIT: 'OnExit';
  673. // general tokens
  674. TRUE: 'True';
  675. FALSE: 'False';
  676. boolean: TRUE | FALSE;
  677. DEC_NUMBER: '[+-]?(0|[1-9]\d*[lL]?)';
  678. FLOAT_NUMBER: '[+-]?((\d+\.\d*|\.\d+)([eE][-+]?\d+)?|\d+[eE][-+]?\d+)';
  679. integer: DEC_NUMBER;
  680. float: FLOAT_NUMBER;
  681. STRVALUE : 'u?r?("(?!"").*?(?<!\\)(\\\\)*?"|\'(?!\'\').*?(?<!\\)(\\\\)*?\')' ;
  682. LONG_STRVALUE : '(?s)u?r?(""".*?(?<!\\)(\\\\)*?"""|\'\'\'.*?(?<!\\)(\\\\)*?\'\'\')'
  683. (%newline)
  684. ;
  685. string: (STRVALUE|LONG_STRVALUE) string?;
  686. MULT: '\*';
  687. DIV: '/';
  688. POTENCY: '@\d';
  689. LTHAN: '<';
  690. LEQTHAN: '<=';
  691. GTHAN: '>';
  692. GEQTHAN: '>=';
  693. ASSIGN: '=';
  694. DOT: '\.';
  695. COLON: ':';
  696. LPAR: '\(';
  697. RPAR: '\)';
  698. COMMA: ',';
  699. EQUALS: '==';
  700. PLUS: '\+';
  701. MINUS: '-';
  702. MOD: '%';
  703. LSQBR: '\[';
  704. RSQBR: '\]';
  705. NEWLINE: '(\r?\n[\t ]*)+' // Don't count on the + to prevent multiple NEWLINE tokens. It's just an optimization
  706. (%newline)
  707. ;
  708. // ignores
  709. WS: '[\t \f]+' (%ignore);
  710. LINE_CONT: '\\[\t \f]*\r?\n' (%ignore) (%newline);
  711. COMMENT: '\#[^\n]*'(%ignore);
  712. // identation
  713. INDENT: '<INDENT>';
  714. DEDENT: '<DEDENT>';
  715. EOF: '<EOF>';
  716. ###
  717. from plyplus.grammars.python_indent_postlex import PythonIndentTracker
  718. self.lexer_postproc = PythonIndentTracker