@op-ted/efx-syntax-highlighter 0.3.0 → 0.4.1

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 (42) hide show
  1. package/README.md +19 -12
  2. package/dist/efx1/efx1Highlighting.js +45 -0
  3. package/dist/efx1/generated/lexer.js +1772 -0
  4. package/dist/efx1/lexer.js +26 -0
  5. package/dist/efx1/parser.js +23 -0
  6. package/dist/efx1/parser.terms.js +118 -0
  7. package/dist/{completion → efx2/completion}/CompletionItems.js +1 -1
  8. package/dist/{completion → efx2/completion}/EfxCompletions.js +6 -3
  9. package/dist/{completion → efx2/completion}/ExpectedTokens.js +14 -14
  10. package/dist/{efxHighlighting.js → efx2/efx2Highlighting.js} +7 -7
  11. package/dist/{generated → efx2/generated}/completions.js +1 -1
  12. package/dist/efx2/generated/lexer.js +3880 -0
  13. package/dist/efx2/generated/words.js +213 -0
  14. package/dist/efx2/lexer.js +49 -0
  15. package/dist/efx2/parser.js +23 -0
  16. package/dist/efx2/parser.terms.js +318 -0
  17. package/dist/efxLanguage.js +66 -17
  18. package/dist/efxSymbols.js +3 -1
  19. package/dist/index.d.ts +41 -0
  20. package/dist/lexer/AntlrLexer.js +427 -0
  21. package/dist/lexer/EditorLexer.js +134 -0
  22. package/dist/lexer/EditorParser.js +69 -0
  23. package/dist/lexer/Lexing.js +238 -0
  24. package/dist/lexer/ParseRanges.js +22 -0
  25. package/package.json +12 -6
  26. package/dist/efx-parser.js +0 -26
  27. package/dist/efx-parser.terms.js +0 -319
  28. package/dist/generated/words.js +0 -215
  29. package/dist/lexer/ExpressionMode.js +0 -44
  30. package/dist/lexer/FormatMode.js +0 -31
  31. package/dist/lexer/IdentifierMode.js +0 -12
  32. package/dist/lexer/LabelMode.js +0 -27
  33. package/dist/lexer/LexerContext.js +0 -76
  34. package/dist/lexer/LexerInput.js +0 -188
  35. package/dist/lexer/LexerMode.js +0 -24
  36. package/dist/lexer/LexerModes.js +0 -50
  37. package/dist/lexer/LineMode.js +0 -85
  38. package/dist/lexer/ReservedWords.js +0 -75
  39. package/dist/lexer/StageHeaderMode.js +0 -12
  40. package/dist/lexer/TemplateMode.js +0 -77
  41. package/dist/lexer/TemplateStartMode.js +0 -25
  42. /package/dist/{completion → efx2/completion}/Variables.js +0 -0
@@ -0,0 +1,318 @@
1
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
2
+ export const
3
+ space = 392,
4
+ Comment = 1,
5
+ FreeText = 2,
6
+ AssetType = 3,
7
+ LabelType = 4,
8
+ OtherAssetId = 5,
9
+ Semicolon = 6,
10
+ FormatShort = 7,
11
+ FormatMedium = 8,
12
+ FormatLong = 9,
13
+ FormatNoUnit = 10,
14
+ FormatNoFormatting = 11,
15
+ With = 12,
16
+ Compute = 13,
17
+ Select = 14,
18
+ Let = 15,
19
+ When = 16,
20
+ Otherwise = 17,
21
+ Display = 18,
22
+ Invoke = 19,
23
+ Index = 20,
24
+ By = 21,
25
+ Template = 22,
26
+ Dynamic = 23,
27
+ And = 24,
28
+ Or = 25,
29
+ Is = 26,
30
+ In = 27,
31
+ Like = 28,
32
+ Present = 29,
33
+ Empty = 30,
34
+ Unique = 31,
35
+ Has = 32,
36
+ No = 33,
37
+ Duplicates = 34,
38
+ Every = 35,
39
+ Some = 36,
40
+ Satisfies = 37,
41
+ If = 38,
42
+ Then = 39,
43
+ Else = 40,
44
+ For = 41,
45
+ Return = 42,
46
+ Distinct = 43,
47
+ Always = 44,
48
+ Never = 45,
49
+ True = 46,
50
+ False = 47,
51
+ At = 48,
52
+ AT = 49,
53
+ EVERY = 50,
54
+ Not = 51,
55
+ Text = 52,
56
+ Number = 53,
57
+ Indicator = 54,
58
+ Date = 55,
59
+ Time = 56,
60
+ Duration = 57,
61
+ ContextType = 58,
62
+ CountFunction = 59,
63
+ SubstringFunction = 60,
64
+ SubstringBeforeFunction = 61,
65
+ SubstringAfterFunction = 62,
66
+ ContainsFunction = 63,
67
+ StartsWithFunction = 64,
68
+ EndsWithFunction = 65,
69
+ StringLengthFunction = 66,
70
+ IndexOfSubstringFunction = 67,
71
+ SumFunction = 68,
72
+ MinFunction = 69,
73
+ MaxFunction = 70,
74
+ AverageFunction = 71,
75
+ AbsoluteFunction = 72,
76
+ RoundFunction = 73,
77
+ RoundDownFunction = 74,
78
+ RoundUpFunction = 75,
79
+ YearFunction = 76,
80
+ MonthFunction = 77,
81
+ DayFunction = 78,
82
+ HoursFunction = 79,
83
+ MinutesFunction = 80,
84
+ SecondsFunction = 81,
85
+ YearsFunction = 82,
86
+ MonthsFunction = 83,
87
+ DaysFunction = 84,
88
+ FormatNumberFunction = 85,
89
+ FormatShortFunction = 86,
90
+ FormatMediumFunction = 87,
91
+ FormatLongFunction = 88,
92
+ UpperCaseFunction = 89,
93
+ LowerCaseFunction = 90,
94
+ NormalizeSpaceFunction = 91,
95
+ TrimFunction = 92,
96
+ TrimLeftFunction = 93,
97
+ TrimRightFunction = 94,
98
+ PadLeftFunction = 95,
99
+ PadRightFunction = 96,
100
+ RepeatFunction = 97,
101
+ ReplaceFunction = 98,
102
+ ReplaceRegexFunction = 99,
103
+ UrlEncodeFunction = 100,
104
+ CapitalizeFirstFunction = 101,
105
+ ConcatFunction = 102,
106
+ StringJoinFunction = 103,
107
+ CurrentDateFunction = 104,
108
+ CurrentTimeFunction = 105,
109
+ DayTimeDurationFunction = 106,
110
+ YearMonthDurationFunction = 107,
111
+ AddDurationFunction = 108,
112
+ SubtractDurationFunction = 109,
113
+ DistinctValuesFunction = 110,
114
+ CountDuplicatesFunction = 111,
115
+ GetDuplicatesFunction = 112,
116
+ ValueUnionFunction = 113,
117
+ ValueIntersectFunction = 114,
118
+ ValueExceptFunction = 115,
119
+ SequenceEqualFunction = 116,
120
+ SortFunction = 117,
121
+ ReverseFunction = 118,
122
+ SubsequenceFunction = 119,
123
+ IndexOfFunction = 120,
124
+ PreferredLanguageFunction = 121,
125
+ PreferredLanguageTextFunction = 122,
126
+ SplitFunction = 123,
127
+ Endpoint = 124,
128
+ Call = 125,
129
+ Api = 126,
130
+ On = 127,
131
+ Warn = 128,
132
+ Reject = 129,
133
+ Error = 130,
134
+ Warning = 131,
135
+ Info = 132,
136
+ Assert = 133,
137
+ Report = 134,
138
+ OtherwiseAssert = 135,
139
+ OtherwiseReport = 136,
140
+ As = 137,
141
+ FOR = 138,
142
+ IN = 139,
143
+ Any = 140,
144
+ Scope = 141,
145
+ IncludeDirective = 142,
146
+ PublicationDate = 143,
147
+ JustificationCode = 144,
148
+ JustificationDescription = 145,
149
+ PrivacyCode = 146,
150
+ WasWithheld = 147,
151
+ IsWithheld = 148,
152
+ IsWithholdable = 149,
153
+ IsDisclosed = 150,
154
+ IsMasked = 151,
155
+ RawValue = 152,
156
+ PreferredLanguage = 153,
157
+ PreferredLanguageText = 154,
158
+ StartContextBlock = 155,
159
+ IncludePath = 156,
160
+ MixedIndent = 157,
161
+ Tabs = 158,
162
+ Spaces = 159,
163
+ OutlineNumber = 160,
164
+ SummarySectionHeader = 161,
165
+ NavigationSectionHeader = 162,
166
+ StageHeaderStart = 163,
167
+ StageIdentifier = 164,
168
+ StageHeaderEnd = 165,
169
+ NewLine = 166,
170
+ CharacterReference = 167,
171
+ CRLF = 168,
172
+ ShorthandFieldValueReferenceFromContextField = 169,
173
+ StartSelectorBlock = 170,
174
+ StartLabelBlock = 171,
175
+ StartHyperlinkBlock = 172,
176
+ Whitespace = 173,
177
+ OtherEscapeSequence = 174,
178
+ FormatDecimals = 175,
179
+ Pipe = 176,
180
+ OpenParenthesis = 177,
181
+ CloseParenthesis = 178,
182
+ OpenBracket = 179,
183
+ CloseBracket = 180,
184
+ ColonColon = 181,
185
+ StartExpressionBlock = 182,
186
+ EndBlock = 183,
187
+ DayTimeDurationLiteral = 184,
188
+ YearMonthDurationLiteral = 185,
189
+ BtId = 186,
190
+ FieldId = 187,
191
+ NodeId = 188,
192
+ RuleIdentifier = 189,
193
+ Pre = 190,
194
+ Post = 191,
195
+ VariablePrefix = 192,
196
+ AtPrefix = 193,
197
+ HashPrefix = 194,
198
+ FunctionPrefix = 195,
199
+ Identifier = 196,
200
+ IntegerLiteral = 197,
201
+ DecimalLiteral = 198,
202
+ StringLiteral = 199,
203
+ UuidV4Literal = 200,
204
+ DateLiteral = 201,
205
+ TimeLiteral = 202,
206
+ Assignment = 203,
207
+ Comparison = 204,
208
+ Star = 205,
209
+ Slash = 206,
210
+ Percent = 207,
211
+ Plus = 208,
212
+ Minus = 209,
213
+ Comma = 210,
214
+ Ellipsis = 211,
215
+ Colon = 212,
216
+ sharpValue = 213,
217
+ AttributeSlash = 214,
218
+ TemplateFile = 215,
219
+ GlobalDeclaration = 216,
220
+ VariableDeclaration = 217,
221
+ TypeDeclaration = 219,
222
+ PrimitiveType = 220,
223
+ LinkedFieldReference = 226,
224
+ SimpleFieldReference = 227,
225
+ LinkedFieldProperty = 228,
226
+ SimpleNodeReference = 230,
227
+ IteratorList = 247,
228
+ AbsoluteFieldReference = 251,
229
+ ContextBracket = 252,
230
+ Predicate = 253,
231
+ AbsoluteNodeReference = 255,
232
+ Literal = 259,
233
+ NumericLiteral = 260,
234
+ BooleanLiteral = 261,
235
+ TrueBooleanLiteral = 262,
236
+ FalseBooleanLiteral = 263,
237
+ DurationLiteral = 264,
238
+ Reference = 266,
239
+ FieldReference = 267,
240
+ NodeReference = 268,
241
+ VariableReference = 269,
242
+ FunctionInvocation = 270,
243
+ ArgumentList = 271,
244
+ Argument = 272,
245
+ FieldMention = 275,
246
+ CodelistReference = 282,
247
+ BuiltInFunction = 284,
248
+ DynamicFunctionInvocation = 286,
249
+ DictionaryDeclaration = 287,
250
+ DictionaryIndexClause = 288,
251
+ DictionaryKeyClause = 289,
252
+ FunctionDeclaration = 290,
253
+ ParameterList = 291,
254
+ ParameterDeclaration = 292,
255
+ TemplateDeclaration = 293,
256
+ Indentation = 294,
257
+ TemplateDefinition = 295,
258
+ ChooseTemplate = 296,
259
+ WhenBlock = 297,
260
+ WhenDisplayTemplate = 298,
261
+ DisplayTemplate = 299,
262
+ LineBreak = 301,
263
+ TextBlock = 303,
264
+ LinkBlock = 304,
265
+ ExpressionBlock = 308,
266
+ StandardExpressionBlock = 309,
267
+ AssetId = 310,
268
+ Pluraliser = 315,
269
+ FormatOptions = 319,
270
+ FormatStyle = 320,
271
+ WhenInvokeTemplate = 323,
272
+ InvokeTemplate = 324,
273
+ OtherwiseBlock = 325,
274
+ OtherwiseDisplayTemplate = 326,
275
+ OtherwiseInvokeTemplate = 327,
276
+ TemplateLine = 328,
277
+ ContextDeclarationBlock = 329,
278
+ VariableList = 330,
279
+ ContextDeclaration = 331,
280
+ ContextVariableInitializer = 332,
281
+ OtherSections = 333,
282
+ NavigationSection = 334,
283
+ SummarySection = 335,
284
+ RulesFile = 336,
285
+ ApiEndpointDeclaration = 337,
286
+ DynamicFunctionDeclaration = 338,
287
+ OnErrorClause = 339,
288
+ GlobalVariableDeclaration = 340,
289
+ ValidationStage = 341,
290
+ StageVariableDeclaration = 342,
291
+ RuleSet = 343,
292
+ WithClause = 344,
293
+ Rules = 345,
294
+ ConditionalRule = 346,
295
+ WhenClause = 347,
296
+ AssertClause = 348,
297
+ ReportClause = 349,
298
+ AsClause = 350,
299
+ Severity = 351,
300
+ RuleId = 352,
301
+ ForClause = 353,
302
+ InClause = 354,
303
+ NoticeTypeRange = 357,
304
+ NoticeType = 358,
305
+ ScopeClause = 359,
306
+ ScopeAnnotation = 360,
307
+ Flag = 361,
308
+ SimpleRule = 362,
309
+ ConditionalRules = 363,
310
+ FallbackRule = 364,
311
+ OtherwiseAssertClause = 365,
312
+ OtherwiseReportClause = 366,
313
+ SingleExpression = 367,
314
+ SelectorBlock = 368,
315
+ Selection = 369,
316
+ AttributeReference = 370,
317
+ BareExpression = 371,
318
+ Dialect_bare = 0
@@ -1,29 +1,78 @@
1
- // CodeMirror 6 language support for EFX. The grammar reads three kinds of EFX text, each from a top
2
- // of its own; an editor holds one kind, so there is one language per kind. The parser carries the
3
- // highlight tags (efxHighlighting.js); the EFX colours are the editor's default colours. The
4
- // language offers its completions (completion/EfxCompletions.js) to the editor's autocompletion,
5
- // which the application turns on.
6
- import { LRLanguage, LanguageSupport, syntaxHighlighting } from "@codemirror/language";
7
- import { EfxCompletions } from "./completion/EfxCompletions.js";
8
- import { parser } from "./efx-parser.js";
1
+ // CodeMirror 6 language support for EFX. Each version of EFX has its grammar: EFX-2, the language of
2
+ // the eForms SDK 2, and EFX-1, the language of the SDK 1. A grammar reads some kinds of EFX text,
3
+ // each from a top of its own; an editor holds one kind, so there is one language per kind and
4
+ // version. The parsers carry the highlight tags (efx2/efx2Highlighting.js, efx1/efx1Highlighting.js); the
5
+ // EFX colours are the editor's default colours. An EFX-2 language offers its completions
6
+ // (efx2/completion/EfxCompletions.js) to the editor's autocompletion, which the application turns on; EFX-1
7
+ // is highlighted only.
8
+ import { Language, LanguageSupport, defineLanguageFacet, languageDataProp, syntaxHighlighting } from "@codemirror/language";
9
+ import { EfxCompletions } from "./efx2/completion/EfxCompletions.js";
10
+ import { parser as efx1Parser } from "./efx1/parser.js";
11
+ import { parser as efx2Parser } from "./efx2/parser.js";
9
12
  import { efxHighlightStyle } from "./efxTheme.js";
13
+ import { EditorParser } from "./lexer/EditorParser.js";
10
14
 
11
- // The top of the grammar that reads each kind of EFX text.
12
- const TOPS = { template: "TemplateFile", rules: "RulesFile", expression: "SingleExpression" };
15
+ // How each grammar reads each kind of EFX text: its top, and the dialect of a bare expression; and
16
+ // whether it offers completions. EFX-1 has no rules files.
17
+ const READINGS = {
18
+ 2: {
19
+ parser: efx2Parser,
20
+ completions: true,
21
+ kinds: {
22
+ template: { top: "TemplateFile" },
23
+ rules: { top: "RulesFile" },
24
+ expression: { top: "SingleExpression" },
25
+ "bare-expression": { top: "BareExpression", dialect: "bare" },
26
+ },
27
+ },
28
+ 1: {
29
+ parser: efx1Parser,
30
+ completions: false,
31
+ kinds: {
32
+ template: { top: "TemplateFile" },
33
+ expression: { top: "SingleExpression" },
34
+ "bare-expression": { top: "BareExpression", dialect: "bare" },
35
+ },
36
+ },
37
+ };
13
38
 
14
- const LANGUAGES = new Map(Object.entries(TOPS).map(([kind, top]) =>
15
- [kind, LRLanguage.define({ name: "efx", parser: parser.configure({ top }) })]));
39
+ /**
40
+ * The language of a kind of text, read by a parser: the parser configured for the kind, which the
41
+ * completions also use, as the language's parser, which reuses an earlier tree only before the first
42
+ * change to the text (lexer/EditorParser.js).
43
+ */
44
+ function languageOf(versionParser, reading) {
45
+ const data = defineLanguageFacet();
46
+ const parser = versionParser.configure({ ...reading, props: [languageDataProp.add((type) => (type.isTop ? data : undefined))] });
47
+ return { parser, language: new Language(data, new EditorParser(parser), [], "efx") };
48
+ }
49
+
50
+ // The languages of each version, by kind, each with its parser.
51
+ const LANGUAGES = new Map(Object.entries(READINGS).map(([version, { parser: versionParser, kinds }]) =>
52
+ [Number(version), new Map(Object.entries(kinds).map(([kind, reading]) => [kind, languageOf(versionParser, reading)]))]));
16
53
 
17
54
  // The EFX colours, used where the application gives the editor no colours of its own.
18
55
  const DEFAULT_COLOURS = syntaxHighlighting(efxHighlightStyle, { fallback: true });
19
56
 
20
- /** EFX support for an editor that holds one kind of EFX text: "template", "rules" or "expression". */
21
- export function efx(kind) {
22
- const language = LANGUAGES.get(kind);
57
+ /**
58
+ * EFX support for an editor that holds one kind of EFX text of one version of EFX. The kinds are
59
+ * "template", "rules", "expression" and "bare-expression"; the version is 2, unless the options say
60
+ * `{ version: 1 }`, and EFX-1 has no rules files.
61
+ */
62
+ export function efx(kind, { version = 2 } = {}) {
63
+ const languages = LANGUAGES.get(version);
64
+ if (languages === undefined) {
65
+ throw new RangeError(`Unknown version of EFX: ${version}. The versions are ${[...LANGUAGES.keys()].join(", ")}.`);
66
+ }
67
+ const { language, parser } = languages.get(kind) ?? {};
23
68
  if (language === undefined) {
24
- throw new RangeError(`Unknown kind of EFX text: ${kind}. The kinds are ${[...LANGUAGES.keys()].join(", ")}.`);
69
+ throw new RangeError(`Unknown kind of EFX-${version} text: ${kind}. `
70
+ + `The kinds are ${[...languages.keys()].join(", ")}.`);
71
+ }
72
+ if (!READINGS[version].completions) {
73
+ return new LanguageSupport(language, [DEFAULT_COLOURS]);
25
74
  }
26
- const completions = new EfxCompletions(language.parser);
75
+ const completions = new EfxCompletions(parser);
27
76
  const autocomplete = language.data.of({ autocomplete: (context) => completions.complete(context) });
28
77
  return new LanguageSupport(language, [DEFAULT_COLOURS, autocomplete]);
29
78
  }
@@ -1,6 +1,8 @@
1
1
  // The field and node ids an application gives the editor, which it offers where the grammar takes
2
2
  // one: an extension, `efxSymbols.of({ fields, nodes })`, each a list of ids, for example those of
3
- // the SDK's fields.json. The ids of several such extensions add up.
3
+ // the SDK's fields.json. An entry is an id, or an id with its type, `{ id, type }`, such as a
4
+ // field's type in fields.json, which the editor shows beside the id. The ids of several such
5
+ // extensions add up, each entry as the application gave it.
4
6
 
5
7
  import { Facet } from '@codemirror/state';
6
8
 
@@ -0,0 +1,41 @@
1
+ // The types of the package's public surface (index.js), for applications written in TypeScript.
2
+
3
+ import type { HighlightStyle, LanguageSupport } from '@codemirror/language';
4
+ import type { Extension, Facet } from '@codemirror/state';
5
+
6
+ /** The kinds of EFX text an editor can hold. */
7
+ export type EfxKind = 'template' | 'rules' | 'expression' | 'bare-expression';
8
+
9
+ /** The kinds of EFX text that both versions of EFX have: EFX-1 has no rules files. */
10
+ export type EfxCommonKind = Exclude<EfxKind, 'rules'>;
11
+
12
+ /** EFX support for an editor that holds one kind of EFX-2 text: its parser, the EFX colours and the completions. */
13
+ export function efx(kind: EfxKind, options?: { version?: 2 }): LanguageSupport;
14
+ /** EFX support for an editor that holds one kind of EFX-1 text: its parser and the EFX colours. */
15
+ export function efx(kind: EfxCommonKind, options: { version: 1 }): LanguageSupport;
16
+ /** EFX support for a kind of text both versions have, in a version chosen when the application runs. */
17
+ export function efx(kind: EfxCommonKind, options?: { version?: 1 | 2 }): LanguageSupport;
18
+
19
+ /** A field or node id, with its type, such as a field's type in the SDK's fields.json, shown beside the id. */
20
+ export interface EfxSymbol {
21
+ id: string;
22
+ type?: string;
23
+ }
24
+
25
+ /** The field and node ids an application gives the editor: ids, or ids with their type. */
26
+ export interface EfxSymbols {
27
+ fields?: readonly (string | EfxSymbol)[];
28
+ nodes?: readonly (string | EfxSymbol)[];
29
+ }
30
+
31
+ /**
32
+ * The field and node ids the editor offers where the grammar takes one: `efxSymbols.of({ fields, nodes })`.
33
+ * The ids of several such extensions add up, each entry as the application gave it.
34
+ */
35
+ export const efxSymbols: Facet<EfxSymbols, { fields: (string | EfxSymbol)[]; nodes: (string | EfxSymbol)[] }>;
36
+
37
+ /** The EFX colours, which efx() gives the editor as its default colours. */
38
+ export const efxHighlightStyle: HighlightStyle;
39
+
40
+ /** A light look for the editor itself, which an application adds if it wants it. */
41
+ export const efxTheme: Extension;