@sccharts-lab/engine 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/LICENSE +277 -0
  2. package/README.md +125 -2
  3. package/dist/codegen/expr.d.ts +36 -0
  4. package/dist/codegen/expr.js +252 -0
  5. package/dist/codegen/expr.js.map +1 -0
  6. package/dist/codegen/index.d.ts +4 -0
  7. package/dist/codegen/index.js +238 -0
  8. package/dist/codegen/index.js.map +1 -0
  9. package/dist/codegen/layout.d.ts +57 -0
  10. package/dist/codegen/layout.js +306 -0
  11. package/dist/codegen/layout.js.map +1 -0
  12. package/dist/codegen/logic.d.ts +31 -0
  13. package/dist/codegen/logic.js +258 -0
  14. package/dist/codegen/logic.js.map +1 -0
  15. package/dist/codegen/methods.d.ts +17 -0
  16. package/dist/codegen/methods.js +242 -0
  17. package/dist/codegen/methods.js.map +1 -0
  18. package/dist/codegen/reset.d.ts +6 -0
  19. package/dist/codegen/reset.js +110 -0
  20. package/dist/codegen/reset.js.map +1 -0
  21. package/dist/codegen/types.d.ts +81 -0
  22. package/dist/codegen/types.js +3 -0
  23. package/dist/codegen/types.js.map +1 -0
  24. package/dist/format.d.ts +136 -0
  25. package/dist/format.js +872 -0
  26. package/dist/format.js.map +1 -0
  27. package/dist/index.d.ts +120 -0
  28. package/dist/index.js +507 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/internal.d.ts +1 -0
  31. package/dist/internal.js +4 -0
  32. package/dist/internal.js.map +1 -0
  33. package/dist/parser/ids.d.ts +4 -0
  34. package/dist/parser/ids.js +172 -0
  35. package/dist/parser/ids.js.map +1 -0
  36. package/dist/parser/imports.d.ts +2 -0
  37. package/dist/parser/imports.js +28 -0
  38. package/dist/parser/imports.js.map +1 -0
  39. package/dist/parser/interface.d.ts +10 -0
  40. package/dist/parser/interface.js +93 -0
  41. package/dist/parser/interface.js.map +1 -0
  42. package/dist/parser/kielerWording.d.ts +2 -0
  43. package/dist/parser/kielerWording.js +196 -0
  44. package/dist/parser/kielerWording.js.map +1 -0
  45. package/dist/parser/lexer.d.ts +25 -0
  46. package/dist/parser/lexer.js +334 -0
  47. package/dist/parser/lexer.js.map +1 -0
  48. package/dist/parser/parser.d.ts +29 -0
  49. package/dist/parser/parser.js +3249 -0
  50. package/dist/parser/parser.js.map +1 -0
  51. package/dist/parser/resolve.d.ts +46 -0
  52. package/dist/parser/resolve.js +919 -0
  53. package/dist/parser/resolve.js.map +1 -0
  54. package/dist/parser/source.d.ts +15 -0
  55. package/dist/parser/source.js +42 -0
  56. package/dist/parser/source.js.map +1 -0
  57. package/dist/parser/validate.d.ts +5 -0
  58. package/dist/parser/validate.js +1430 -0
  59. package/dist/parser/validate.js.map +1 -0
  60. package/dist/sim/abortRegions.d.ts +9 -0
  61. package/dist/sim/abortRegions.js +192 -0
  62. package/dist/sim/abortRegions.js.map +1 -0
  63. package/dist/sim/analysis.d.ts +113 -0
  64. package/dist/sim/analysis.js +1104 -0
  65. package/dist/sim/analysis.js.map +1 -0
  66. package/dist/sim/codegen.d.ts +30 -0
  67. package/dist/sim/codegen.js +730 -0
  68. package/dist/sim/codegen.js.map +1 -0
  69. package/dist/sim/compile.d.ts +43 -0
  70. package/dist/sim/compile.js +1062 -0
  71. package/dist/sim/compile.js.map +1 -0
  72. package/dist/sim/deps.d.ts +73 -0
  73. package/dist/sim/deps.js +481 -0
  74. package/dist/sim/deps.js.map +1 -0
  75. package/dist/sim/describe.d.ts +22 -0
  76. package/dist/sim/describe.js +272 -0
  77. package/dist/sim/describe.js.map +1 -0
  78. package/dist/sim/describePreemption.d.ts +22 -0
  79. package/dist/sim/describePreemption.js +90 -0
  80. package/dist/sim/describePreemption.js.map +1 -0
  81. package/dist/sim/describeStructure.d.ts +75 -0
  82. package/dist/sim/describeStructure.js +293 -0
  83. package/dist/sim/describeStructure.js.map +1 -0
  84. package/dist/sim/eval.d.ts +99 -0
  85. package/dist/sim/eval.js +644 -0
  86. package/dist/sim/eval.js.map +1 -0
  87. package/dist/sim/exec.d.ts +212 -0
  88. package/dist/sim/exec.js +874 -0
  89. package/dist/sim/exec.js.map +1 -0
  90. package/dist/sim/fold.d.ts +2 -0
  91. package/dist/sim/fold.js +40 -0
  92. package/dist/sim/fold.js.map +1 -0
  93. package/dist/sim/goblock.d.ts +16 -0
  94. package/dist/sim/goblock.js +171 -0
  95. package/dist/sim/goblock.js.map +1 -0
  96. package/dist/sim/guardIndices.d.ts +13 -0
  97. package/dist/sim/guardIndices.js +137 -0
  98. package/dist/sim/guardIndices.js.map +1 -0
  99. package/dist/sim/index.d.ts +43 -0
  100. package/dist/sim/index.js +138 -0
  101. package/dist/sim/index.js.map +1 -0
  102. package/dist/sim/lower.d.ts +33 -0
  103. package/dist/sim/lower.js +716 -0
  104. package/dist/sim/lower.js.map +1 -0
  105. package/dist/sim/memory.d.ts +47 -0
  106. package/dist/sim/memory.js +328 -0
  107. package/dist/sim/memory.js.map +1 -0
  108. package/dist/sim/model.d.ts +487 -0
  109. package/dist/sim/model.js +772 -0
  110. package/dist/sim/model.js.map +1 -0
  111. package/dist/sim/passes/abort.d.ts +2 -0
  112. package/dist/sim/passes/abort.js +269 -0
  113. package/dist/sim/passes/abort.js.map +1 -0
  114. package/dist/sim/passes/abortRegion.d.ts +10 -0
  115. package/dist/sim/passes/abortRegion.js +62 -0
  116. package/dist/sim/passes/abortRegion.js.map +1 -0
  117. package/dist/sim/passes/arrayAssignment.d.ts +2 -0
  118. package/dist/sim/passes/arrayAssignment.js +147 -0
  119. package/dist/sim/passes/arrayAssignment.js.map +1 -0
  120. package/dist/sim/passes/codeEffects.d.ts +2 -0
  121. package/dist/sim/passes/codeEffects.js +14 -0
  122. package/dist/sim/passes/codeEffects.js.map +1 -0
  123. package/dist/sim/passes/complexFinalState.d.ts +4 -0
  124. package/dist/sim/passes/complexFinalState.js +77 -0
  125. package/dist/sim/passes/complexFinalState.js.map +1 -0
  126. package/dist/sim/passes/connector.d.ts +2 -0
  127. package/dist/sim/passes/connector.js +18 -0
  128. package/dist/sim/passes/connector.js.map +1 -0
  129. package/dist/sim/passes/contained.d.ts +37 -0
  130. package/dist/sim/passes/contained.js +198 -0
  131. package/dist/sim/passes/contained.js.map +1 -0
  132. package/dist/sim/passes/context.d.ts +39 -0
  133. package/dist/sim/passes/context.js +3 -0
  134. package/dist/sim/passes/context.js.map +1 -0
  135. package/dist/sim/passes/countDelay.d.ts +2 -0
  136. package/dist/sim/passes/countDelay.js +51 -0
  137. package/dist/sim/passes/countDelay.js.map +1 -0
  138. package/dist/sim/passes/dataflow.d.ts +11 -0
  139. package/dist/sim/passes/dataflow.js +319 -0
  140. package/dist/sim/passes/dataflow.js.map +1 -0
  141. package/dist/sim/passes/deferred.d.ts +2 -0
  142. package/dist/sim/passes/deferred.js +345 -0
  143. package/dist/sim/passes/deferred.js.map +1 -0
  144. package/dist/sim/passes/detect.d.ts +10 -0
  145. package/dist/sim/passes/detect.js +33 -0
  146. package/dist/sim/passes/detect.js.map +1 -0
  147. package/dist/sim/passes/during.d.ts +2 -0
  148. package/dist/sim/passes/during.js +67 -0
  149. package/dist/sim/passes/during.js.map +1 -0
  150. package/dist/sim/passes/entry.d.ts +5 -0
  151. package/dist/sim/passes/entry.js +93 -0
  152. package/dist/sim/passes/entry.js.map +1 -0
  153. package/dist/sim/passes/enum.d.ts +2 -0
  154. package/dist/sim/passes/enum.js +22 -0
  155. package/dist/sim/passes/enum.js.map +1 -0
  156. package/dist/sim/passes/exit.d.ts +4 -0
  157. package/dist/sim/passes/exit.js +120 -0
  158. package/dist/sim/passes/exit.js.map +1 -0
  159. package/dist/sim/passes/finalRegion.d.ts +2 -0
  160. package/dist/sim/passes/finalRegion.js +21 -0
  161. package/dist/sim/passes/finalRegion.js.map +1 -0
  162. package/dist/sim/passes/followedBy.d.ts +2 -0
  163. package/dist/sim/passes/followedBy.js +78 -0
  164. package/dist/sim/passes/followedBy.js.map +1 -0
  165. package/dist/sim/passes/forRegion.d.ts +9 -0
  166. package/dist/sim/passes/forRegion.js +230 -0
  167. package/dist/sim/passes/forRegion.js.map +1 -0
  168. package/dist/sim/passes/history.d.ts +12 -0
  169. package/dist/sim/passes/history.js +115 -0
  170. package/dist/sim/passes/history.js.map +1 -0
  171. package/dist/sim/passes/hostCode.d.ts +2 -0
  172. package/dist/sim/passes/hostCode.js +152 -0
  173. package/dist/sim/passes/hostCode.js.map +1 -0
  174. package/dist/sim/passes/index.d.ts +4 -0
  175. package/dist/sim/passes/index.js +84 -0
  176. package/dist/sim/passes/index.js.map +1 -0
  177. package/dist/sim/passes/inheritance.d.ts +8 -0
  178. package/dist/sim/passes/inheritance.js +233 -0
  179. package/dist/sim/passes/inheritance.js.map +1 -0
  180. package/dist/sim/passes/initOperator.d.ts +2 -0
  181. package/dist/sim/passes/initOperator.js +68 -0
  182. package/dist/sim/passes/initOperator.js.map +1 -0
  183. package/dist/sim/passes/initialization.d.ts +2 -0
  184. package/dist/sim/passes/initialization.js +69 -0
  185. package/dist/sim/passes/initialization.js.map +1 -0
  186. package/dist/sim/passes/ode.d.ts +2 -0
  187. package/dist/sim/passes/ode.js +14 -0
  188. package/dist/sim/passes/ode.js.map +1 -0
  189. package/dist/sim/passes/period.d.ts +2 -0
  190. package/dist/sim/passes/period.js +106 -0
  191. package/dist/sim/passes/period.js.map +1 -0
  192. package/dist/sim/passes/prTransitions.d.ts +2 -0
  193. package/dist/sim/passes/prTransitions.js +12 -0
  194. package/dist/sim/passes/prTransitions.js.map +1 -0
  195. package/dist/sim/passes/pre.d.ts +4 -0
  196. package/dist/sim/passes/pre.js +326 -0
  197. package/dist/sim/passes/pre.js.map +1 -0
  198. package/dist/sim/passes/quirks.d.ts +2 -0
  199. package/dist/sim/passes/quirks.js +169 -0
  200. package/dist/sim/passes/quirks.js.map +1 -0
  201. package/dist/sim/passes/reference.d.ts +60 -0
  202. package/dist/sim/passes/reference.js +386 -0
  203. package/dist/sim/passes/reference.js.map +1 -0
  204. package/dist/sim/passes/regionActions.d.ts +2 -0
  205. package/dist/sim/passes/regionActions.js +56 -0
  206. package/dist/sim/passes/regionActions.js.map +1 -0
  207. package/dist/sim/passes/sequentialFollowedBy.d.ts +2 -0
  208. package/dist/sim/passes/sequentialFollowedBy.js +72 -0
  209. package/dist/sim/passes/sequentialFollowedBy.js.map +1 -0
  210. package/dist/sim/passes/signal.d.ts +2 -0
  211. package/dist/sim/passes/signal.js +230 -0
  212. package/dist/sim/passes/signal.js.map +1 -0
  213. package/dist/sim/passes/static.d.ts +5 -0
  214. package/dist/sim/passes/static.js +67 -0
  215. package/dist/sim/passes/static.js.map +1 -0
  216. package/dist/sim/passes/suspend.d.ts +10 -0
  217. package/dist/sim/passes/suspend.js +71 -0
  218. package/dist/sim/passes/suspend.js.map +1 -0
  219. package/dist/sim/passes/termination.d.ts +9 -0
  220. package/dist/sim/passes/termination.js +69 -0
  221. package/dist/sim/passes/termination.js.map +1 -0
  222. package/dist/sim/passes/timedAutomata.d.ts +10 -0
  223. package/dist/sim/passes/timedAutomata.js +437 -0
  224. package/dist/sim/passes/timedAutomata.js.map +1 -0
  225. package/dist/sim/passes/unpackClasses.d.ts +2 -0
  226. package/dist/sim/passes/unpackClasses.js +54 -0
  227. package/dist/sim/passes/unpackClasses.js.map +1 -0
  228. package/dist/sim/passes/userSchedule.d.ts +2 -0
  229. package/dist/sim/passes/userSchedule.js +43 -0
  230. package/dist/sim/passes/userSchedule.js.map +1 -0
  231. package/dist/sim/passes/weakSuspend.d.ts +2 -0
  232. package/dist/sim/passes/weakSuspend.js +145 -0
  233. package/dist/sim/passes/weakSuspend.js.map +1 -0
  234. package/dist/sim/preemptionLog.d.ts +41 -0
  235. package/dist/sim/preemptionLog.js +133 -0
  236. package/dist/sim/preemptionLog.js.map +1 -0
  237. package/dist/sim/random.d.ts +12 -0
  238. package/dist/sim/random.js +40 -0
  239. package/dist/sim/random.js.map +1 -0
  240. package/dist/sim/reasons.d.ts +29 -0
  241. package/dist/sim/reasons.js +168 -0
  242. package/dist/sim/reasons.js.map +1 -0
  243. package/dist/sim/scg.d.ts +124 -0
  244. package/dist/sim/scg.js +723 -0
  245. package/dist/sim/scg.js.map +1 -0
  246. package/dist/sim/sfr.d.ts +4 -0
  247. package/dist/sim/sfr.js +264 -0
  248. package/dist/sim/sfr.js.map +1 -0
  249. package/dist/sim/stringConditions.d.ts +3 -0
  250. package/dist/sim/stringConditions.js +42 -0
  251. package/dist/sim/stringConditions.js.map +1 -0
  252. package/dist/sim/structure/copy.d.ts +4 -0
  253. package/dist/sim/structure/copy.js +140 -0
  254. package/dist/sim/structure/copy.js.map +1 -0
  255. package/dist/sim/structure/delays.d.ts +30 -0
  256. package/dist/sim/structure/delays.js +127 -0
  257. package/dist/sim/structure/delays.js.map +1 -0
  258. package/dist/sim/structure/instance.d.ts +15 -0
  259. package/dist/sim/structure/instance.js +69 -0
  260. package/dist/sim/structure/instance.js.map +1 -0
  261. package/dist/sim/structure/methods.d.ts +19 -0
  262. package/dist/sim/structure/methods.js +550 -0
  263. package/dist/sim/structure/methods.js.map +1 -0
  264. package/dist/sim/structure/rewrite.d.ts +20 -0
  265. package/dist/sim/structure/rewrite.js +113 -0
  266. package/dist/sim/structure/rewrite.js.map +1 -0
  267. package/dist/sim/structure/track.d.ts +22 -0
  268. package/dist/sim/structure/track.js +123 -0
  269. package/dist/sim/structure/track.js.map +1 -0
  270. package/dist/sim/tracker.d.ts +77 -0
  271. package/dist/sim/tracker.js +265 -0
  272. package/dist/sim/tracker.js.map +1 -0
  273. package/dist/sim/values.d.ts +31 -0
  274. package/dist/sim/values.js +103 -0
  275. package/dist/sim/values.js.map +1 -0
  276. package/dist/types.d.ts +670 -0
  277. package/dist/types.js +9 -0
  278. package/dist/types.js.map +1 -0
  279. package/package.json +58 -3
@@ -0,0 +1,25 @@
1
+ import type { Diagnostic } from "../types.js";
2
+ import { LineMap } from "./source.js";
3
+ export type TokenKind = 'ID' | 'INT' | 'FLOAT' | 'BOOLEAN' | 'STRING' | 'HOSTCODE' | 'COMMENT_ANNOTATION' | 'SL_COMMENT_ANNOTATION' | 'ANY_OTHER' | 'EOF' | string;
4
+ export interface Token {
5
+ kind: TokenKind;
6
+ start: number;
7
+ end: number;
8
+ text: string;
9
+ }
10
+ export interface Comment {
11
+ kind: 'line' | 'block';
12
+ start: number;
13
+ end: number;
14
+ text: string;
15
+ }
16
+ /** Every keyword and punctuation token of the generated SCTX lexer (InternalSCTX.tokens). */
17
+ export declare const KEYWORDS: ReadonlySet<string>;
18
+ export interface LexResult {
19
+ tokens: Token[];
20
+ comments: Comment[];
21
+ diagnostics: Diagnostic[];
22
+ }
23
+ export declare function lex(text: string, lines?: LineMap): LexResult;
24
+ /** Human-readable name of a token for messages: `'state'`, `the name 'foo'`, `the end of the file`. */
25
+ export declare function describeToken(t: Token): string;
@@ -0,0 +1,334 @@
1
+ // The SCTX lexer. It reproduces the terminals of KIELER's Xtext grammars (Annotations.xtext, KExpressions.xtext,
2
+ // Terminals) and the keyword set of the generated InternalSCTX lexer, with ANTLR's longest-match rule: the longest
3
+ // token wins, and on a tie a keyword beats a terminal (so `state` is a keyword and `states` an ID).
4
+ //
5
+ // Hidden tokens: whitespace (space, tab, CR, LF only), `/* ... */` and `// ...` comments. Doc comments `/** ... */`
6
+ // and `//* ...` comment annotations are real tokens: the grammar only allows them in certain places.
7
+ import { LineMap } from "./source.js";
8
+ /** Every keyword and punctuation token of the generated SCTX lexer (InternalSCTX.tokens). */
9
+ export const KEYWORDS = new Set([
10
+ '!&', '!', '!=', '#', '%', '%=', '&&', '&', '&=', '(', '()', ')', '*', '*=', '+', '++', '+=', ',', '-', '--', '-=', '->',
11
+ '.', '/', '/=', ':', ';', '<', '<<', '<<=', '<=', '=', '==', '>', '>=', '>>', '>>=', '>>>', '>>>=', '?', '@', 'Pr', 'Pr=',
12
+ '[', "'", ']', '^', '^=', '_', 'abort', 'annotated(', 'auto', 'bool', 'calls', 'class', 'clock', 'clock-time', 'combine',
13
+ 'commuting', 'conflicting', 'connector', 'const', 'dataflow', 'deep deferred', 'deferred', 'delayed', 'do', 'during',
14
+ 'else', 'entry', 'enum', 'exit', 'expression', 'extends', 'extern', 'fby', 'final', 'float', 'for', 'global', 'go',
15
+ 'goto', 'history', 'host', 'if', 'immediate', 'import', 'initial', 'input', 'int', 'is', 'join', 'json', 'label', 'max',
16
+ 'max=', 'method', 'min', 'min=', 'module', 'nondeterministic', 'none', 'null', 'ode', 'once', 'output', 'override',
17
+ 'period', 'policy', 'pre', 'primitive', 'print', 'private', 'protected', 'public', 'pure', 'random', 'randomize', 'ref',
18
+ 'region', 'reset', 'return', 'scchart', 'schedule', 'scope', 'seq', 'sfby', 'shallow history', 'signal', 'state',
19
+ 'static', 'string', 'strong', 'struct', 'super.', 'suspend', 'this', 'to', 'undefined', 'val', 'violation', 'void',
20
+ 'weak', 'while', '{', '|', '|=', '||', '}', '~',
21
+ ]);
22
+ /** Keywords made of letters (and the few with a space, dot, hyphen or bracket), for matching at an identifier. */
23
+ const WORD_KEYWORDS = [...KEYWORDS].filter(k => /^[A-Za-z]/.test(k));
24
+ /** Multi-character keywords that extend past an identifier: `clock-time`, `deep deferred`, `super.`, `Pr=` ... */
25
+ const LONG_WORD_KEYWORDS = WORD_KEYWORDS.filter(k => !/^[A-Za-z]+$/.test(k)).sort((a, b) => b.length - a.length);
26
+ const PUNCTUATION = [...KEYWORDS].filter(k => !/^[A-Za-z]/.test(k)).sort((a, b) => b.length - a.length);
27
+ const PUNCTUATION_BY_CHAR = new Map();
28
+ for (const p of PUNCTUATION) {
29
+ const list = PUNCTUATION_BY_CHAR.get(p[0]) ?? [];
30
+ list.push(p);
31
+ PUNCTUATION_BY_CHAR.set(p[0], list);
32
+ }
33
+ const isDigit = (c) => c >= 48 && c <= 57;
34
+ const isLetter = (c) => (c >= 65 && c <= 90) || (c >= 97 && c <= 122);
35
+ const isIdPart = (c) => isLetter(c) || isDigit(c) || c === 95;
36
+ const ESCAPABLE = new Set(['b', 't', 'n', 'f', 'r', '"', "'", '\\']);
37
+ export function lex(text, lines = new LineMap(text)) {
38
+ const tokens = [];
39
+ const comments = [];
40
+ const diagnostics = [];
41
+ const n = text.length;
42
+ let i = 0;
43
+ const error = (start, end, message, hint, kieler) => {
44
+ const d = { severity: 'error', message, hint, code: 'parse', span: lines.span(start, Math.max(end, start)) };
45
+ if (kieler)
46
+ d.kieler = kieler;
47
+ diagnostics.push(d);
48
+ };
49
+ const push = (kind, start, end) => tokens.push({ kind, start, end, text: text.slice(start, end) });
50
+ /** ID per Annotations.xtext: '^'? (('_'? 'a'..'z'|'_'? 'A'..'Z') | '_' '0'..'9' | '__') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')* */
51
+ const idLength = (at) => {
52
+ let j = at;
53
+ if (text.charCodeAt(j) === 94 /* ^ */)
54
+ j++;
55
+ const c = text.charCodeAt(j);
56
+ if (isLetter(c))
57
+ j++;
58
+ else if (c === 95 /* _ */) {
59
+ const d = text.charCodeAt(j + 1);
60
+ if (isLetter(d) || isDigit(d) || d === 95)
61
+ j += 2;
62
+ else
63
+ return 0;
64
+ }
65
+ else
66
+ return 0;
67
+ while (j < n && isIdPart(text.charCodeAt(j)))
68
+ j++;
69
+ return j - at;
70
+ };
71
+ /** A quoted terminal (STRING with '"', HOSTCODE with '`'): escapes \b \t \n \f \r \" \' \\ only. */
72
+ const quoted = (quote, kind) => {
73
+ const start = i;
74
+ let j = i + 1;
75
+ let ok = true;
76
+ while (j < n) {
77
+ const c = text.charCodeAt(j);
78
+ if (c === quote) {
79
+ j++;
80
+ push(kind, start, j);
81
+ i = j;
82
+ return;
83
+ }
84
+ if (c === 92 /* \ */) {
85
+ const next = text[j + 1];
86
+ if (next === undefined)
87
+ break;
88
+ if (!ESCAPABLE.has(next)) {
89
+ if (ok)
90
+ error(j, j + 2, `'\\${next}' is not an escape sequence SCTX knows`, kind === 'STRING'
91
+ ? 'Inside a string, a backslash can only start \\n, \\t, \\r, \\b, \\f, \\", \\\' or \\\\. Write \\\\ for a backslash.'
92
+ : 'Inside host code, a backslash can only start \\n, \\t, \\r, \\b, \\f, \\", \\\' or \\\\.');
93
+ ok = false;
94
+ }
95
+ j += 2;
96
+ continue;
97
+ }
98
+ j++;
99
+ }
100
+ const what = kind === 'STRING' ? 'string' : 'host code';
101
+ error(start, Math.min(n, start + 1), `This ${what} is never closed`, kind === 'STRING'
102
+ ? 'Add the closing `"` (strings can span several lines, so everything after the opening quote became part of the string).'
103
+ : 'Add the closing backtick.', kind === 'STRING' ? `mismatched character '<EOF>' expecting '"'` : undefined);
104
+ push(kind, start, n);
105
+ i = n;
106
+ };
107
+ while (i < n) {
108
+ const c = text.charCodeAt(i);
109
+ // WS: ' ' | '\t' | '\r' | '\n'
110
+ if (c === 32 || c === 9 || c === 13 || c === 10) {
111
+ i++;
112
+ continue;
113
+ }
114
+ const start = i;
115
+ if (c === 47 /* / */) {
116
+ const c1 = text.charCodeAt(i + 1);
117
+ if (c1 === 42 /* * */) {
118
+ if (text.charCodeAt(i + 2) === 42) {
119
+ // COMMENT_ANNOTATION: '/**' -> '*/'
120
+ const close = text.indexOf('*/', i + 3);
121
+ if (close < 0) {
122
+ error(start, start + 3, 'This /** comment is never closed', 'Add `*/` to end the comment.');
123
+ push('COMMENT_ANNOTATION', start, n);
124
+ i = n;
125
+ }
126
+ else {
127
+ push('COMMENT_ANNOTATION', start, close + 2);
128
+ i = close + 2;
129
+ }
130
+ continue;
131
+ }
132
+ // ML_COMMENT: '/*' !'*' -> '*/'
133
+ if (i + 2 >= n) {
134
+ error(start, n, 'This /* comment is never closed', 'Add `*/` to end the comment.', "mismatched character '<EOF>' expecting '*'");
135
+ i = n;
136
+ continue;
137
+ }
138
+ const close = text.indexOf('*/', i + 3);
139
+ if (close < 0) {
140
+ error(start, start + 2, 'This /* comment is never closed', 'Add `*/` to end the comment.');
141
+ comments.push({ kind: 'block', start, end: n, text: text.slice(start) });
142
+ i = n;
143
+ }
144
+ else {
145
+ comments.push({ kind: 'block', start, end: close + 2, text: text.slice(start, close + 2) });
146
+ i = close + 2;
147
+ }
148
+ continue;
149
+ }
150
+ if (c1 === 47 /* / */) {
151
+ if (text.charCodeAt(i + 2) === 42) {
152
+ // SL_COMMENT_ANNOTATION: '//*' !('\n'|'\r')* ('\r'? '\n')?
153
+ let j = i + 3;
154
+ while (j < n && text[j] !== '\n' && text[j] !== '\r')
155
+ j++;
156
+ if (text[j] === '\r' && text[j + 1] === '\n')
157
+ j += 2;
158
+ else if (text[j] === '\n')
159
+ j++;
160
+ push('SL_COMMENT_ANNOTATION', start, j);
161
+ i = j;
162
+ continue;
163
+ }
164
+ // SL_COMMENT: '//' !'*' !('\n'|'\r')* ('\r'? '\n')? -- the first character after // is consumed whatever
165
+ // it is (even a line break), exactly as KIELER's lexer does.
166
+ if (i + 2 >= n) {
167
+ error(start, n, 'A // comment cannot be the very last thing in the file', 'Add a line break after the comment, or remove the //.');
168
+ i = n;
169
+ continue;
170
+ }
171
+ let j = i + 3;
172
+ while (j < n && text[j] !== '\n' && text[j] !== '\r')
173
+ j++;
174
+ if (text[j] === '\r' && text[j + 1] === '\n')
175
+ j += 2;
176
+ else if (text[j] === '\n')
177
+ j++;
178
+ if (text[i + 2] === '\n' && text.slice(i + 3, j).trim()) {
179
+ const lineStart = i + 3;
180
+ const lineEnd = text.slice(lineStart, j).replace(/\r?\n$/, '').length + lineStart;
181
+ diagnostics.push({
182
+ severity: 'warning', code: 'swallowed-line', span: lines.span(lineStart, lineEnd),
183
+ message: 'KIELER treats this line as part of the empty // comment on the line above',
184
+ hint: 'An empty // comment at the end of a line also comments out the whole next line in KIELER. Write something after the //, or delete it.',
185
+ });
186
+ }
187
+ comments.push({ kind: 'line', start, end: j, text: text.slice(start, j).replace(/\r?\n$/, '') });
188
+ i = j;
189
+ continue;
190
+ }
191
+ }
192
+ if (c === 34 /* " */) {
193
+ quoted(34, 'STRING');
194
+ continue;
195
+ }
196
+ if (c === 96 /* ` */) {
197
+ quoted(96, 'HOSTCODE');
198
+ continue;
199
+ }
200
+ if (isDigit(c)) {
201
+ let j = i;
202
+ while (j < n && isDigit(text.charCodeAt(j)))
203
+ j++;
204
+ let kind = 'INT';
205
+ if (text.charCodeAt(j) === 46 /* . */) {
206
+ kind = 'FLOAT';
207
+ j++;
208
+ while (j < n && isDigit(text.charCodeAt(j)))
209
+ j++;
210
+ const e = text.charCodeAt(j);
211
+ if (e === 101 || e === 69 /* e E */) {
212
+ // KIELER's lexer commits to an exponent as soon as it sees the 'e': `1.e5` is a number, `1.ex`
213
+ // is a lexical error (not `1.` followed by `ex`).
214
+ let k = j + 1;
215
+ const s = text.charCodeAt(k);
216
+ if (s === 43 || s === 45 /* + - */)
217
+ k++;
218
+ if (isDigit(text.charCodeAt(k))) {
219
+ while (k < n && isDigit(text.charCodeAt(k)))
220
+ k++;
221
+ }
222
+ else {
223
+ error(start, k, `The number ${text.slice(start, k)} has an exponent without digits`, 'After the `e` of a floating-point number, SCTX expects the exponent digits, as in `1.5e3`. Put a space or an operator after the number if the `e` belongs to a name.');
224
+ }
225
+ j = k;
226
+ }
227
+ if (text.charCodeAt(j) === 102 /* f */)
228
+ j++;
229
+ }
230
+ else if (text.charCodeAt(j) === 102 /* f */) {
231
+ kind = 'FLOAT';
232
+ j++;
233
+ }
234
+ push(kind, start, j);
235
+ if (kind === 'INT' && (j - start > 10 || Number(text.slice(start, j)) > 2147483647)) {
236
+ // KIELER converts INT with Java's Integer.valueOf.
237
+ error(start, j, `The number ${text.slice(start, j)} is too large`, 'SCTX integers are 32-bit: the largest is 2147483647. Use a float (with a decimal point) for larger values.', `For input string: "${text.slice(start, j)}"`);
238
+ }
239
+ i = j;
240
+ continue;
241
+ }
242
+ const idLen = idLength(i);
243
+ if (idLen > 0) {
244
+ // Longest match: a keyword with a space, dot, hyphen or bracket (`deep deferred`, `super.`, `clock-time`,
245
+ // `Pr=`, `annotated(`) can be longer than the identifier at the same place.
246
+ let best = idLen;
247
+ let kind = 'ID';
248
+ for (const k of LONG_WORD_KEYWORDS) {
249
+ if (k.length > best && text.startsWith(k, i)) {
250
+ best = k.length;
251
+ kind = k;
252
+ break;
253
+ }
254
+ }
255
+ if (kind === 'ID') {
256
+ // KIELER's lexer commits to `deep deferred`, `shallow history` and `clock-time` as soon as it has read
257
+ // `deep `, `shallow ` or `clock-`, so a variable called deep or shallow followed by a space is a
258
+ // lexical error there. Reproduce the rejection (and explain it), then carry on with the plain name.
259
+ const word = text.slice(i, i + idLen);
260
+ const committed = word === 'deep' || word === 'shallow' ? ' ' : word === 'clock' ? '-' : undefined;
261
+ if (committed && text[i + idLen] === committed) {
262
+ const keyword = word === 'deep' ? 'deep deferred' : word === 'shallow' ? 'shallow history' : 'clock-time';
263
+ error(start, i + idLen + 1, `KIELER reads '${word}${committed}' as the start of the keyword '${keyword}'`, word === 'clock'
264
+ ? `Write clock-time without spaces for the type, or put spaces around the minus ("clock - x"). clock is a keyword, so it cannot name a variable.`
265
+ : `A name '${word}' followed by a space confuses KIELER's lexer. Rename it, or write the next symbol without a space (${word}= 1).`);
266
+ }
267
+ }
268
+ if (kind === 'ID') {
269
+ const word = text.slice(i, i + idLen);
270
+ if (word === 'true' || word === 'false')
271
+ kind = 'BOOLEAN';
272
+ else if (KEYWORDS.has(word))
273
+ kind = word;
274
+ }
275
+ push(kind, start, i + best);
276
+ i += best;
277
+ continue;
278
+ }
279
+ const candidates = PUNCTUATION_BY_CHAR.get(text[i]);
280
+ if (candidates) {
281
+ const p = candidates.find(k => text.startsWith(k, i));
282
+ if (p) {
283
+ push(p, start, i + p.length);
284
+ i += p.length;
285
+ continue;
286
+ }
287
+ }
288
+ // RULE_ANY_OTHER: any other character is a token of its own that no grammar rule accepts.
289
+ const cp = text.codePointAt(i);
290
+ const len = cp > 0xffff ? 2 : 1;
291
+ push('ANY_OTHER', start, i + len);
292
+ i += len;
293
+ }
294
+ tokens.push({ kind: 'EOF', start: n, end: n, text: '' });
295
+ return { tokens, comments, diagnostics };
296
+ }
297
+ /** Human-readable name of a token for messages: `'state'`, `the name 'foo'`, `the end of the file`. */
298
+ export function describeToken(t) {
299
+ switch (t.kind) {
300
+ case 'EOF': return 'the end of the file';
301
+ case 'ID': return `the name '${t.text}'`;
302
+ case 'INT':
303
+ case 'FLOAT': return `the number ${t.text}`;
304
+ case 'BOOLEAN': return `'${t.text}'`;
305
+ case 'STRING': return `the string ${t.text.length > 30 ? t.text.slice(0, 27) + '..."' : t.text}`;
306
+ case 'HOSTCODE': return 'host code `...`';
307
+ case 'COMMENT_ANNOTATION': return 'a /** comment */';
308
+ case 'SL_COMMENT_ANNOTATION': return 'a //* comment';
309
+ case 'ANY_OTHER': return describeChar(t.text);
310
+ default: return `'${t.kind}'`;
311
+ }
312
+ }
313
+ function describeChar(ch) {
314
+ const cp = ch.codePointAt(0);
315
+ const hex = 'U+' + cp.toString(16).toUpperCase().padStart(4, '0');
316
+ if (cp === 0xa0)
317
+ return `a non-breaking space (${hex})`;
318
+ if (cp === 0x0c)
319
+ return `a form feed (${hex})`;
320
+ if (cp === 0x0b)
321
+ return `a vertical tab (${hex})`;
322
+ if (cp === 0xfeff)
323
+ return `an invisible byte order mark (${hex})`;
324
+ if (cp >= 0x2000 && cp <= 0x200b)
325
+ return `an unusual space character (${hex})`;
326
+ if (cp === 0x2018 || cp === 0x2019)
327
+ return `a curly quote ${ch} (${hex})`;
328
+ if (cp === 0x201c || cp === 0x201d)
329
+ return `a curly double quote ${ch} (${hex})`;
330
+ if (cp < 32)
331
+ return `the control character ${hex}`;
332
+ return `'${ch}'`;
333
+ }
334
+ //# sourceMappingURL=lexer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lexer.js","sourceRoot":"","sources":["../../src/parser/lexer.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,mHAAmH;AACnH,oGAAoG;AACpG,EAAE;AACF,oHAAoH;AACpH,qGAAqG;AAGrG,OAAO,EAAE,OAAO,EAAE,oBAAgB;AAsBlC,6FAA6F;AAC7F,MAAM,CAAC,MAAM,QAAQ,GAAwB,IAAI,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AAA;IACvD,IAAI,EAAE,KAAK,IAAI;QAAE,OAAO,gBAAgB,GAAG,GAAG,CAAA;IAC9C,IAAI,EAAE,KAAK,IAAI;QAAE,OAAO,mBAAmB,GAAG,GAAG,CAAA;IACjD,IAAI,EAAE,KAAK,MAAM;QAAE,OAAO,iCAAiC,GAAG,GAAG,CAAA;IACjE,IAAI,EAAE,IAAI,MAAM,IAAI,EAAE,IAAI,MAAM;QAAE,OAAO,+BAA+B,GAAG,GAAG,CAAA;IAC9E,IAAI,EAAE,KAAK,MAAM,IAAI,EAAE,KAAK,MAAM;QAAE,OAAO,iBAAiB,EAAE,KAAK,GAAG,GAAG,CAAA;IACzE,IAAI,EAAE,KAAK,MAAM,IAAI,EAAE,KAAK,MAAM;QAAE,OAAO,wBAAwB,EAAE,KAAK,GAAG,GAAG,CAAA;IAChF,IAAI,EAAE,GAAG,EAAE;QAAE,OAAO,yBAAyB,GAAG,EAAE,CAAA;IAClD,OAAO,IAAI,EAAE,GAAG,CAAA;AACpB,CAAC","sourcesContent":["// The SCTX lexer. It reproduces the terminals of KIELER's Xtext grammars (Annotations.xtext, KExpressions.xtext,\n// Terminals) and the keyword set of the generated InternalSCTX lexer, with ANTLR's longest-match rule: the longest\n// token wins, and on a tie a keyword beats a terminal (so `state` is a keyword and `states` an ID).\n//\n// Hidden tokens: whitespace (space, tab, CR, LF only), `/* ... */` and `// ...` comments. Doc comments `/** ... */`\n// and `//* ...` comment annotations are real tokens: the grammar only allows them in certain places.\n\nimport type { Diagnostic } from '../types'\nimport { LineMap } from './source'\n\nexport type TokenKind =\n | 'ID' | 'INT' | 'FLOAT' | 'BOOLEAN' | 'STRING' | 'HOSTCODE'\n | 'COMMENT_ANNOTATION' | 'SL_COMMENT_ANNOTATION'\n | 'ANY_OTHER' | 'EOF'\n | string // keywords and punctuation: the literal text, e.g. 'state', '{', 'deep deferred'\n\nexport interface Token {\n kind: TokenKind\n start: number\n end: number\n text: string\n}\n\nexport interface Comment {\n kind: 'line' | 'block'\n start: number\n end: number\n text: string\n}\n\n/** Every keyword and punctuation token of the generated SCTX lexer (InternalSCTX.tokens). */\nexport const KEYWORDS: ReadonlySet<string> = new Set([\n '!&', '!', '!=', '#', '%', '%=', '&&', '&', '&=', '(', '()', ')', '*', '*=', '+', '++', '+=', ',', '-', '--', '-=', '->',\n '.', '/', '/=', ':', ';', '<', '<<', '<<=', '<=', '=', '==', '>', '>=', '>>', '>>=', '>>>', '>>>=', '?', '@', 'Pr', 'Pr=',\n '[', \"'\", ']', '^', '^=', '_', 'abort', 'annotated(', 'auto', 'bool', 'calls', 'class', 'clock', 'clock-time', 'combine',\n 'commuting', 'conflicting', 'connector', 'const', 'dataflow', 'deep deferred', 'deferred', 'delayed', 'do', 'during',\n 'else', 'entry', 'enum', 'exit', 'expression', 'extends', 'extern', 'fby', 'final', 'float', 'for', 'global', 'go',\n 'goto', 'history', 'host', 'if', 'immediate', 'import', 'initial', 'input', 'int', 'is', 'join', 'json', 'label', 'max',\n 'max=', 'method', 'min', 'min=', 'module', 'nondeterministic', 'none', 'null', 'ode', 'once', 'output', 'override',\n 'period', 'policy', 'pre', 'primitive', 'print', 'private', 'protected', 'public', 'pure', 'random', 'randomize', 'ref',\n 'region', 'reset', 'return', 'scchart', 'schedule', 'scope', 'seq', 'sfby', 'shallow history', 'signal', 'state',\n 'static', 'string', 'strong', 'struct', 'super.', 'suspend', 'this', 'to', 'undefined', 'val', 'violation', 'void',\n 'weak', 'while', '{', '|', '|=', '||', '}', '~',\n])\n\n/** Keywords made of letters (and the few with a space, dot, hyphen or bracket), for matching at an identifier. */\nconst WORD_KEYWORDS = [...KEYWORDS].filter(k => /^[A-Za-z]/.test(k))\n/** Multi-character keywords that extend past an identifier: `clock-time`, `deep deferred`, `super.`, `Pr=` ... */\nconst LONG_WORD_KEYWORDS = WORD_KEYWORDS.filter(k => !/^[A-Za-z]+$/.test(k)).sort((a, b) => b.length - a.length)\nconst PUNCTUATION = [...KEYWORDS].filter(k => !/^[A-Za-z]/.test(k)).sort((a, b) => b.length - a.length)\nconst PUNCTUATION_BY_CHAR = new Map<string, string[]>()\nfor (const p of PUNCTUATION) {\n const list = PUNCTUATION_BY_CHAR.get(p[0]) ?? []\n list.push(p)\n PUNCTUATION_BY_CHAR.set(p[0], list)\n}\n\nconst isDigit = (c: number) => c >= 48 && c <= 57\nconst isLetter = (c: number) => (c >= 65 && c <= 90) || (c >= 97 && c <= 122)\nconst isIdPart = (c: number) => isLetter(c) || isDigit(c) || c === 95\nconst ESCAPABLE = new Set(['b', 't', 'n', 'f', 'r', '\"', \"'\", '\\\\'])\n\nexport interface LexResult {\n tokens: Token[]\n comments: Comment[]\n diagnostics: Diagnostic[]\n}\n\nexport function lex(text: string, lines: LineMap = new LineMap(text)): LexResult {\n const tokens: Token[] = []\n const comments: Comment[] = []\n const diagnostics: Diagnostic[] = []\n const n = text.length\n let i = 0\n\n const error = (start: number, end: number, message: string, hint?: string, kieler?: string) => {\n const d: Diagnostic = { severity: 'error', message, hint, code: 'parse', span: lines.span(start, Math.max(end, start)) }\n if (kieler) d.kieler = kieler\n diagnostics.push(d)\n }\n const push = (kind: TokenKind, start: number, end: number) => tokens.push({ kind, start, end, text: text.slice(start, end) })\n\n /** ID per Annotations.xtext: '^'? (('_'? 'a'..'z'|'_'? 'A'..'Z') | '_' '0'..'9' | '__') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')* */\n const idLength = (at: number): number => {\n let j = at\n if (text.charCodeAt(j) === 94 /* ^ */) j++\n const c = text.charCodeAt(j)\n if (isLetter(c)) j++\n else if (c === 95 /* _ */) {\n const d = text.charCodeAt(j + 1)\n if (isLetter(d) || isDigit(d) || d === 95) j += 2\n else return 0\n } else return 0\n while (j < n && isIdPart(text.charCodeAt(j))) j++\n return j - at\n }\n\n /** A quoted terminal (STRING with '\"', HOSTCODE with '`'): escapes \\b \\t \\n \\f \\r \\\" \\' \\\\ only. */\n const quoted = (quote: number, kind: 'STRING' | 'HOSTCODE') => {\n const start = i\n let j = i + 1\n let ok = true\n while (j < n) {\n const c = text.charCodeAt(j)\n if (c === quote) {\n j++\n push(kind, start, j)\n i = j\n return\n }\n if (c === 92 /* \\ */) {\n const next = text[j + 1]\n if (next === undefined) break\n if (!ESCAPABLE.has(next)) {\n if (ok) error(j, j + 2, `'\\\\${next}' is not an escape sequence SCTX knows`, kind === 'STRING'\n ? 'Inside a string, a backslash can only start \\\\n, \\\\t, \\\\r, \\\\b, \\\\f, \\\\\", \\\\\\' or \\\\\\\\. Write \\\\\\\\ for a backslash.'\n : 'Inside host code, a backslash can only start \\\\n, \\\\t, \\\\r, \\\\b, \\\\f, \\\\\", \\\\\\' or \\\\\\\\.')\n ok = false\n }\n j += 2\n continue\n }\n j++\n }\n const what = kind === 'STRING' ? 'string' : 'host code'\n error(start, Math.min(n, start + 1), `This ${what} is never closed`, kind === 'STRING'\n ? 'Add the closing `\"` (strings can span several lines, so everything after the opening quote became part of the string).'\n : 'Add the closing backtick.', kind === 'STRING' ? `mismatched character '<EOF>' expecting '\"'` : undefined)\n push(kind, start, n)\n i = n\n }\n\n while (i < n) {\n const c = text.charCodeAt(i)\n // WS: ' ' | '\\t' | '\\r' | '\\n'\n if (c === 32 || c === 9 || c === 13 || c === 10) { i++; continue }\n const start = i\n\n if (c === 47 /* / */) {\n const c1 = text.charCodeAt(i + 1)\n if (c1 === 42 /* * */) {\n if (text.charCodeAt(i + 2) === 42) {\n // COMMENT_ANNOTATION: '/**' -> '*/'\n const close = text.indexOf('*/', i + 3)\n if (close < 0) {\n error(start, start + 3, 'This /** comment is never closed', 'Add `*/` to end the comment.')\n push('COMMENT_ANNOTATION', start, n)\n i = n\n } else {\n push('COMMENT_ANNOTATION', start, close + 2)\n i = close + 2\n }\n continue\n }\n // ML_COMMENT: '/*' !'*' -> '*/'\n if (i + 2 >= n) {\n error(start, n, 'This /* comment is never closed', 'Add `*/` to end the comment.', \"mismatched character '<EOF>' expecting '*'\")\n i = n\n continue\n }\n const close = text.indexOf('*/', i + 3)\n if (close < 0) {\n error(start, start + 2, 'This /* comment is never closed', 'Add `*/` to end the comment.')\n comments.push({ kind: 'block', start, end: n, text: text.slice(start) })\n i = n\n } else {\n comments.push({ kind: 'block', start, end: close + 2, text: text.slice(start, close + 2) })\n i = close + 2\n }\n continue\n }\n if (c1 === 47 /* / */) {\n if (text.charCodeAt(i + 2) === 42) {\n // SL_COMMENT_ANNOTATION: '//*' !('\\n'|'\\r')* ('\\r'? '\\n')?\n let j = i + 3\n while (j < n && text[j] !== '\\n' && text[j] !== '\\r') j++\n if (text[j] === '\\r' && text[j + 1] === '\\n') j += 2\n else if (text[j] === '\\n') j++\n push('SL_COMMENT_ANNOTATION', start, j)\n i = j\n continue\n }\n // SL_COMMENT: '//' !'*' !('\\n'|'\\r')* ('\\r'? '\\n')? -- the first character after // is consumed whatever\n // it is (even a line break), exactly as KIELER's lexer does.\n if (i + 2 >= n) {\n error(start, n, 'A // comment cannot be the very last thing in the file', 'Add a line break after the comment, or remove the //.')\n i = n\n continue\n }\n let j = i + 3\n while (j < n && text[j] !== '\\n' && text[j] !== '\\r') j++\n if (text[j] === '\\r' && text[j + 1] === '\\n') j += 2\n else if (text[j] === '\\n') j++\n if (text[i + 2] === '\\n' && text.slice(i + 3, j).trim()) {\n const lineStart = i + 3\n const lineEnd = text.slice(lineStart, j).replace(/\\r?\\n$/, '').length + lineStart\n diagnostics.push({\n severity: 'warning', code: 'swallowed-line', span: lines.span(lineStart, lineEnd),\n message: 'KIELER treats this line as part of the empty // comment on the line above',\n hint: 'An empty // comment at the end of a line also comments out the whole next line in KIELER. Write something after the //, or delete it.',\n })\n }\n comments.push({ kind: 'line', start, end: j, text: text.slice(start, j).replace(/\\r?\\n$/, '') })\n i = j\n continue\n }\n }\n\n if (c === 34 /* \" */) { quoted(34, 'STRING'); continue }\n if (c === 96 /* ` */) { quoted(96, 'HOSTCODE'); continue }\n\n if (isDigit(c)) {\n let j = i\n while (j < n && isDigit(text.charCodeAt(j))) j++\n let kind: TokenKind = 'INT'\n if (text.charCodeAt(j) === 46 /* . */) {\n kind = 'FLOAT'\n j++\n while (j < n && isDigit(text.charCodeAt(j))) j++\n const e = text.charCodeAt(j)\n if (e === 101 || e === 69 /* e E */) {\n // KIELER's lexer commits to an exponent as soon as it sees the 'e': `1.e5` is a number, `1.ex`\n // is a lexical error (not `1.` followed by `ex`).\n let k = j + 1\n const s = text.charCodeAt(k)\n if (s === 43 || s === 45 /* + - */) k++\n if (isDigit(text.charCodeAt(k))) {\n while (k < n && isDigit(text.charCodeAt(k))) k++\n } else {\n error(start, k, `The number ${text.slice(start, k)} has an exponent without digits`,\n 'After the `e` of a floating-point number, SCTX expects the exponent digits, as in `1.5e3`. Put a space or an operator after the number if the `e` belongs to a name.')\n }\n j = k\n }\n if (text.charCodeAt(j) === 102 /* f */) j++\n } else if (text.charCodeAt(j) === 102 /* f */) {\n kind = 'FLOAT'\n j++\n }\n push(kind, start, j)\n if (kind === 'INT' && (j - start > 10 || Number(text.slice(start, j)) > 2147483647)) {\n // KIELER converts INT with Java's Integer.valueOf.\n error(start, j, `The number ${text.slice(start, j)} is too large`, 'SCTX integers are 32-bit: the largest is 2147483647. Use a float (with a decimal point) for larger values.', `For input string: \"${text.slice(start, j)}\"`)\n }\n i = j\n continue\n }\n\n const idLen = idLength(i)\n if (idLen > 0) {\n // Longest match: a keyword with a space, dot, hyphen or bracket (`deep deferred`, `super.`, `clock-time`,\n // `Pr=`, `annotated(`) can be longer than the identifier at the same place.\n let best = idLen\n let kind: TokenKind = 'ID'\n for (const k of LONG_WORD_KEYWORDS) {\n if (k.length > best && text.startsWith(k, i)) { best = k.length; kind = k; break }\n }\n if (kind === 'ID') {\n // KIELER's lexer commits to `deep deferred`, `shallow history` and `clock-time` as soon as it has read\n // `deep `, `shallow ` or `clock-`, so a variable called deep or shallow followed by a space is a\n // lexical error there. Reproduce the rejection (and explain it), then carry on with the plain name.\n const word = text.slice(i, i + idLen)\n const committed = word === 'deep' || word === 'shallow' ? ' ' : word === 'clock' ? '-' : undefined\n if (committed && text[i + idLen] === committed) {\n const keyword = word === 'deep' ? 'deep deferred' : word === 'shallow' ? 'shallow history' : 'clock-time'\n error(start, i + idLen + 1, `KIELER reads '${word}${committed}' as the start of the keyword '${keyword}'`,\n word === 'clock'\n ? `Write clock-time without spaces for the type, or put spaces around the minus (\"clock - x\"). clock is a keyword, so it cannot name a variable.`\n : `A name '${word}' followed by a space confuses KIELER's lexer. Rename it, or write the next symbol without a space (${word}= 1).`)\n }\n }\n if (kind === 'ID') {\n const word = text.slice(i, i + idLen)\n if (word === 'true' || word === 'false') kind = 'BOOLEAN'\n else if (KEYWORDS.has(word)) kind = word\n }\n push(kind, start, i + best)\n i += best\n continue\n }\n\n const candidates = PUNCTUATION_BY_CHAR.get(text[i])\n if (candidates) {\n const p = candidates.find(k => text.startsWith(k, i))\n if (p) {\n push(p, start, i + p.length)\n i += p.length\n continue\n }\n }\n\n // RULE_ANY_OTHER: any other character is a token of its own that no grammar rule accepts.\n const cp = text.codePointAt(i)!\n const len = cp > 0xffff ? 2 : 1\n push('ANY_OTHER', start, i + len)\n i += len\n }\n tokens.push({ kind: 'EOF', start: n, end: n, text: '' })\n return { tokens, comments, diagnostics }\n}\n\n/** Human-readable name of a token for messages: `'state'`, `the name 'foo'`, `the end of the file`. */\nexport function describeToken(t: Token): string {\n switch (t.kind) {\n case 'EOF': return 'the end of the file'\n case 'ID': return `the name '${t.text}'`\n case 'INT': case 'FLOAT': return `the number ${t.text}`\n case 'BOOLEAN': return `'${t.text}'`\n case 'STRING': return `the string ${t.text.length > 30 ? t.text.slice(0, 27) + '...\"' : t.text}`\n case 'HOSTCODE': return 'host code `...`'\n case 'COMMENT_ANNOTATION': return 'a /** comment */'\n case 'SL_COMMENT_ANNOTATION': return 'a //* comment'\n case 'ANY_OTHER': return describeChar(t.text)\n default: return `'${t.kind}'`\n }\n}\n\nfunction describeChar(ch: string): string {\n const cp = ch.codePointAt(0)!\n const hex = 'U+' + cp.toString(16).toUpperCase().padStart(4, '0')\n if (cp === 0xa0) return `a non-breaking space (${hex})`\n if (cp === 0x0c) return `a form feed (${hex})`\n if (cp === 0x0b) return `a vertical tab (${hex})`\n if (cp === 0xfeff) return `an invisible byte order mark (${hex})`\n if (cp >= 0x2000 && cp <= 0x200b) return `an unusual space character (${hex})`\n if (cp === 0x2018 || cp === 0x2019) return `a curly quote ${ch} (${hex})`\n if (cp === 0x201c || cp === 0x201d) return `a curly double quote ${ch} (${hex})`\n if (cp < 32) return `the control character ${hex}`\n return `'${ch}'`\n}\n"]}
@@ -0,0 +1,29 @@
1
+ import type { Diagnostic, Effect, Expression, Program, Reference, Span } from "../types.js";
2
+ import { LineMap } from "./source.js";
3
+ export interface ParseOutput {
4
+ program: Program;
5
+ diagnostics: Diagnostic[];
6
+ }
7
+ export declare function parseProgram(source: string, lines?: LineMap): ParseOutput;
8
+ /** What `parseStandalone` reads the text as: KIELER's `Expression` rule, its `Effect` rule, or whichever fits. */
9
+ export type StandaloneMode = 'expression' | 'effect' | 'auto';
10
+ export interface StandaloneOutput {
11
+ /** The rule the text was read with ('auto' tries the expression first, then the effect). */
12
+ as: 'expression' | 'effect';
13
+ expression?: Expression;
14
+ effect?: Effect;
15
+ diagnostics: Diagnostic[];
16
+ }
17
+ /**
18
+ * Parses one expression (KIELER's `Expression` rule, as in a trigger or an initial value) or one effect (its
19
+ * `Effect` rule, as after `do`) on its own, with the same grammar and the same messages as in a chart.
20
+ */
21
+ export declare function parseStandalone(source: string, mode?: StandaloneMode, lines?: LineMap): StandaloneOutput;
22
+ /** `a.b.c` for a reference chain. */
23
+ export declare function referenceName(r: Reference): string;
24
+ /**
25
+ * KIELER has no parenthesis node: the inner expression stands for `( ... )` and keeps its own span (diagnostics
26
+ * point at it, as KIELER's do). The span including the parentheses is kept here, for code that needs the source
27
+ * text of an operand as written (KIELER's NodeModelUtils.findActualNodeFor).
28
+ */
29
+ export declare const groupSpans: WeakMap<Expression, Span>;