sccd_grammar.g 22 KB

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