@op-ted/efx-syntax-highlighter 0.2.1 → 0.4.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.
@@ -0,0 +1,26 @@
1
+ // The EFX-1 lexer: ANTLR's lexer of EfxLexer.g4 of the SDK 1, run from its table
2
+ // (generated/lexer.js) as the tokenizer and the context of grammar/efx1.grammar
3
+ // (src/lexer/EditorLexer.js).
4
+
5
+ import { editorLexer } from '../lexer/EditorLexer.js';
6
+ import { lexerTable } from './generated/lexer.js';
7
+ import * as terms from './parser.terms.js';
8
+
9
+ // The grammar's skip token for each rule the lexer skips or hides.
10
+ const SKIP_TOKENS = { Comment: 'Comment', EmptyLine: 'space', SWS: 'space', EndOfLineComment: 'Comment', WS: 'space' };
11
+
12
+ /**
13
+ * The token types the grammar takes in no rule: words Efx.g4 never uses, a time zone on its own, and
14
+ * the types of rules that never make a token, since a rule before them always matches the same text.
15
+ */
16
+ export const UNUSED_TYPES = ['ValueKeyword', 'Codelist', 'Self', 'Parent', 'ZONE', 'Colon', 'IdentifierPart',
17
+ 'Preceding', 'Following', 'PrecedingSibling', 'FollowingSibling', 'Ancestor', 'AncestorOrSelf', 'Descendant',
18
+ 'DescendantOrSelf', 'Child', ...['BT', 'FIELD', 'NODE', 'DISPLAY_GROUP', 'VIEW_TEMPLATE', 'NOTICE', 'CODE_LIST',
19
+ 'CODE', 'INDICATOR', 'AUXILIARY', 'RULE', 'EXPRESSION', 'INTERVAL', 'PATTERN'].map((name) => `ASSET_TYPE_${name}`),
20
+ ...['NAME', 'WHEN_TRUE', 'WHEN_FALSE', 'DESCRIPTION', 'TOOLTIP', 'TEXT', 'TEMPLATE'].map((name) => `LABEL_TYPE_${name}`)];
21
+
22
+ export const { lexerModes } = editorLexer(lexerTable, terms, {
23
+ skipTokens: SKIP_TOKENS,
24
+ unusedTypes: UNUSED_TYPES,
25
+ bare: { dialect: 'bare', mode: 'EXPRESSION' },
26
+ });
@@ -0,0 +1,23 @@
1
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
2
+ import {LRParser} from "@lezer/lr"
3
+ import {lexerModes} from "./lexer.js"
4
+ import {efx1Highlighting} from "./efx1Highlighting.js"
5
+ export const parser = LRParser.deserialize({
6
+ version: 14,
7
+ states: ";SQYQQOOOkQQOOOpQQOOO%_QQO'#EeO(|QQO'#EdOfQQO'#EdO)bQQO'#EdOOQQ'#FZ'#FZQYQQOOO)jQQOOO%_QQO'#EfQ)rQQOOOpQQO'#EjOOQQ'#Fd'#FdOpQQO'#EkO%_QQO'#EvO*sQQO'#EwO*sQQO'#EzOOQQ'#Fe'#FeO+_QQO'#E{O+dQQO'#E}O+iQQO'#E|O+nQQO'#FOOOQQ'#FP'#FPOOQQ'#Fc'#FcO,tQQO,5;PO%_QQO'#FSOOQQ'#FS'#FSO,{QQO'#FROOQQ'#FR'#FROOQQ'#F^'#F^O-^QQO'#FQO-eQQO,5;OO(|QQO,5;OOfQQO,5;OOOQQ-E9X-E9XO-jQQOOO-rQQO,5;QO%_QQO,5;ROpQQO,5;SO-|QQO,5;TOpQQO,5;WOpQQO,5;XOpQQO,5;YOpQQO,5;ZO.RQQO,5;ZO.ZQQO,5;[O.`QQO,5;]OpQQO,5;`OpQQO,5;aO/lQRO,5;UO0tQRO,5;VO1OQQO,5;bO1VQQO'#EyO1[QQO'#ExO1gQQO,5;cO1lQQO,5;fO1qQQO,5;gO%_QQO,5;iOpQQO,5;hO1xQQO,5;jOOQQ1G0k1G0kO1}QQO,5;UO2nQQO,5;VO3_QQO,5;nO3fQQO'#FfO3kQQO'#FfO3pQQO'#FfOOQQ'#Ff'#FfO3xQQO,5;mOOQQ-E9[-E9[OOQQ1G0j1G0jO3}QQO1G0jO(|QQO1G0jO4SQQOOO*sQQOOO%_QQO'#F[O4_QQO1G0lOOQQ1G0l1G0lO4gQQO1G0mOOQQ1G0n1G0nOOQQ1G0o1G0oO5lQRO1G0rO6kQRO1G0sO7mQRO1G0tO8uQRO1G0uO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R!]!x#V#W#z$`$bY!V`a#T%X%YS#n!m$^!]$qRY_jv!Z![!n#R#l#|$p$q$r$s$t$u$v$w$x$y$z${$|$}%O%P%]%_#PcQRY[^_jvwyz{|!Q!R!Z![!]!n!x#R#V#W#l#z#|$`$b$p$q$r$s$t$u$v$w$x$y$z${$|$}%O%P%]%_R!gl",
10
+ nodeNames: "⚠ Comment MixedIndent Tabs Spaces OutlineNumber CRLF FreeText ShorthandFieldValueReferenceFromContextField ShorthandIndirectLabelReferenceFromContextField StartExpression StartLabel StartSelector Whitespace Pipe EndLabel AssetType LabelType OtherAssetId OpenParenthesis CloseParenthesis OpenBracket CloseBracket ColonColon EndExpression And Or Is In Like Present Empty Unique Every Some Satisfies If Then Else For Return Always Never True False Notice BooleanTypeCast NumericTypeCast TextTypeCast CodeTypeCast DateTypeCast TimeTypeCast DurationTypeCast ContextTypeCast Axis Not CountFunction SubstringFunction StringFunction NumberFunction ContainsFunction StartsWithFunction EndsWithFunction StringLengthFunction SumFunction FormatNumberFunction ConcatFunction DateFunction TimeFunction DayTimeDurationFunction YearMonthDurationFunction AddMeasure SubtractMeasure DistinctValuesFunction UnionFunction IntersectFunction ExceptFunction SequenceEqualFunction BtId FieldId NodeId Variable DayTimeDurationLiteral YearMonthDurationLiteral Identifier INTEGER DECIMAL STRING UUIDV4 DATE TIME Comparison Star Slash Percent Plus Minus Comma SlashAt TemplateFile TemplateLine ContextDeclarationBlock ParenthesizedExpression PredicateExpression ContextOverrideExpression AttributeReference AbsoluteReference CastExpression MultiplicativeExpression AdditiveExpression ComparisonExpression InListCondition LikePatternCondition EmptinessCondition PresenceCondition UniqueValueCondition LogicalAndCondition LogicalOrCondition ConditionalExpression QuantifiedExpression IteratorList Iterator IterationExpression FunctionCall ReferenceInOtherNotice NoticeReference AxisReference Literal Template LabelBlock ExpressionBlock AssetId SingleExpression ParameterList ParameterDeclaration SelectorBlock BareExpression",
11
+ maxTerm: 148,
12
+ nodeProps: [
13
+ ["group", -27,79,80,81,84,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,122,123,124,126,127,"Expression"]
14
+ ],
15
+ propSources: [efx1Highlighting],
16
+ skippedNodes: [0,1],
17
+ repeatNodeCount: 5,
18
+ tokenData: "RORO",
19
+ tokenizers: [0, lexerModes],
20
+ topRules: {"TemplateFile":[0,99],"SingleExpression":[1,132],"BareExpression":[2,136]},
21
+ dialects: {bare: 0},
22
+ tokenPrec: 0
23
+ })
@@ -0,0 +1,118 @@
1
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
2
+ export const
3
+ space = 143,
4
+ Comment = 1,
5
+ MixedIndent = 2,
6
+ Tabs = 3,
7
+ Spaces = 4,
8
+ OutlineNumber = 5,
9
+ CRLF = 6,
10
+ FreeText = 7,
11
+ ShorthandFieldValueReferenceFromContextField = 8,
12
+ ShorthandIndirectLabelReferenceFromContextField = 9,
13
+ StartExpression = 10,
14
+ StartLabel = 11,
15
+ StartSelector = 12,
16
+ Whitespace = 13,
17
+ Pipe = 14,
18
+ EndLabel = 15,
19
+ AssetType = 16,
20
+ LabelType = 17,
21
+ OtherAssetId = 18,
22
+ OpenParenthesis = 19,
23
+ CloseParenthesis = 20,
24
+ OpenBracket = 21,
25
+ CloseBracket = 22,
26
+ ColonColon = 23,
27
+ EndExpression = 24,
28
+ And = 25,
29
+ Or = 26,
30
+ Is = 27,
31
+ In = 28,
32
+ Like = 29,
33
+ Present = 30,
34
+ Empty = 31,
35
+ Unique = 32,
36
+ Every = 33,
37
+ Some = 34,
38
+ Satisfies = 35,
39
+ If = 36,
40
+ Then = 37,
41
+ Else = 38,
42
+ For = 39,
43
+ Return = 40,
44
+ Always = 41,
45
+ Never = 42,
46
+ True = 43,
47
+ False = 44,
48
+ Notice = 45,
49
+ BooleanTypeCast = 46,
50
+ NumericTypeCast = 47,
51
+ TextTypeCast = 48,
52
+ CodeTypeCast = 49,
53
+ DateTypeCast = 50,
54
+ TimeTypeCast = 51,
55
+ DurationTypeCast = 52,
56
+ ContextTypeCast = 53,
57
+ Axis = 54,
58
+ Not = 55,
59
+ CountFunction = 56,
60
+ SubstringFunction = 57,
61
+ StringFunction = 58,
62
+ NumberFunction = 59,
63
+ ContainsFunction = 60,
64
+ StartsWithFunction = 61,
65
+ EndsWithFunction = 62,
66
+ StringLengthFunction = 63,
67
+ SumFunction = 64,
68
+ FormatNumberFunction = 65,
69
+ ConcatFunction = 66,
70
+ DateFunction = 67,
71
+ TimeFunction = 68,
72
+ DayTimeDurationFunction = 69,
73
+ YearMonthDurationFunction = 70,
74
+ AddMeasure = 71,
75
+ SubtractMeasure = 72,
76
+ DistinctValuesFunction = 73,
77
+ UnionFunction = 74,
78
+ IntersectFunction = 75,
79
+ ExceptFunction = 76,
80
+ SequenceEqualFunction = 77,
81
+ BtId = 78,
82
+ FieldId = 79,
83
+ NodeId = 80,
84
+ Variable = 81,
85
+ DayTimeDurationLiteral = 82,
86
+ YearMonthDurationLiteral = 83,
87
+ Identifier = 84,
88
+ INTEGER = 85,
89
+ DECIMAL = 86,
90
+ STRING = 87,
91
+ UUIDV4 = 88,
92
+ DATE = 89,
93
+ TIME = 90,
94
+ Comparison = 91,
95
+ Star = 92,
96
+ Slash = 93,
97
+ Percent = 94,
98
+ Plus = 95,
99
+ Minus = 96,
100
+ Comma = 97,
101
+ SlashAt = 98,
102
+ TemplateFile = 99,
103
+ TemplateLine = 100,
104
+ ContextDeclarationBlock = 101,
105
+ IteratorList = 120,
106
+ Iterator = 121,
107
+ NoticeReference = 125,
108
+ Literal = 127,
109
+ Template = 128,
110
+ LabelBlock = 129,
111
+ ExpressionBlock = 130,
112
+ AssetId = 131,
113
+ SingleExpression = 132,
114
+ ParameterList = 133,
115
+ ParameterDeclaration = 134,
116
+ SelectorBlock = 135,
117
+ BareExpression = 136,
118
+ Dialect_bare = 0
@@ -0,0 +1,51 @@
1
+ // The toolkit's completion list (src/efx2/generated/completions.js) by word: the option for a word the
2
+ // editor offers. A function is offered as a call where an expression can start, which is where the
3
+ // parser can take `(`: its word, then the required parameters of its first signature as fields to
4
+ // fill in, with all its signatures as information. Elsewhere its word is offered bare, as `not` and
5
+ // `empty` after `is`. The list writes a property with its colon; its word is offered after the
6
+ // colon. A word the list does not have is offered as a keyword.
7
+
8
+ import { snippetCompletion } from '@codemirror/autocomplete';
9
+
10
+ // The type of option of each kind of item, which picks its icon.
11
+ const TYPES = { FUNCTION: 'function', KEYWORD: 'keyword', PROPERTY: 'property' };
12
+
13
+ export class CompletionItems {
14
+ #byWord = new Map();
15
+
16
+ constructor(items) {
17
+ for (const item of items) {
18
+ const word = item.label.replace(/^:/, '');
19
+ this.#byWord.set(word, [...(this.#byWord.get(word) ?? []), item]);
20
+ }
21
+ }
22
+
23
+ /** The option for a word, as a call when an expression can start where it goes. */
24
+ optionFor(word, expressionStarts) {
25
+ const items = this.#byWord.get(word) ?? [];
26
+ const functions = items.filter(({ kind }) => kind === 'FUNCTION');
27
+ if (expressionStarts && functions.length > 0) {
28
+ return CompletionItems.#call(word, functions);
29
+ }
30
+ const item = items.find(({ kind }) => kind !== 'FUNCTION');
31
+ return { label: word, type: TYPES[item?.kind ?? 'KEYWORD'], detail: item?.dataType };
32
+ }
33
+
34
+ static #call(word, functions) {
35
+ const [first] = functions;
36
+ const fields = first.parameters.filter(({ optional }) => !optional).map(({ name }) => `\${${name}}`);
37
+ return snippetCompletion(`${word}(${fields.join(', ')})`, {
38
+ label: word,
39
+ type: TYPES.FUNCTION,
40
+ detail: first.dataType,
41
+ info: functions.map((item) => CompletionItems.#signature(item)).join('\n'),
42
+ });
43
+ }
44
+
45
+ /** A signature as the toolkit's list writes it: `label(name TYPE, name TYPE?, name TYPE...) -> TYPE`. */
46
+ static #signature({ label, parameters, dataType }) {
47
+ const mark = ({ optional, variadic }) => (optional ? '?' : variadic ? '...' : '');
48
+ const written = parameters.map((parameter) => `${parameter.name} ${parameter.dataType}${mark(parameter)}`);
49
+ return `${label}(${written.join(', ')}) -> ${dataType}`;
50
+ }
51
+ }
@@ -0,0 +1,86 @@
1
+ // What the editor offers at the cursor, a completion source of @codemirror/autocomplete for the
2
+ // language of one kind of EFX text: the words the lexer reads there as tokens the parser can take
3
+ // (ExpectedTokens), as the toolkit's completion list describes them (CompletionItems); the field and
4
+ // node ids the application gives (efxSymbols) where the parser takes one; and the variables of the
5
+ // text (Variables) where it takes a `$`. The options replace the word before the cursor: a name, a
6
+ // field id with its part in parentheses (BT-26(m)-Lot) or a variable with its `$`. Nothing is offered
7
+ // inside a comment or a string. Template text takes any word, so where it can go the options are
8
+ // offered only when asked for, not while typing.
9
+
10
+ import { syntaxTree } from '@codemirror/language';
11
+ import * as terms from '../parser.terms.js';
12
+ import { efxSymbols } from '../../efxSymbols.js';
13
+ import { completionItems } from '../generated/completions.js';
14
+ import { CompletionItems } from './CompletionItems.js';
15
+ import { ExpectedTokens } from './ExpectedTokens.js';
16
+ import { Variables } from './Variables.js';
17
+
18
+ // The word before the cursor: a name, which starts with a letter as the lexer's Identifier does, or a
19
+ // field id with its part in parentheses; with the `$` of a variable or without. A number or a minus
20
+ // starts no word, so typing one opens no list and an option never replaces it.
21
+ const NAME = String.raw`[A-Za-z_][\w-]*`;
22
+ const FIELD_ID_WITH_PART = String.raw`(?:BT|OPP|OPT|OPA)-\d+\((?:BT-\d*|[a-z])?\)?[\w-]*`;
23
+ const WORD = new RegExp(String.raw`\$?(?:${FIELD_ID_WITH_PART}|${NAME})?`);
24
+ const WHOLE_WORD = new RegExp(`^${WORD.source}$`);
25
+
26
+ // The tokens that decide the options besides the words: an expression can start, a field id, a
27
+ // node id, a variable, template text.
28
+ const ASKED = [terms.OpenParenthesis, terms.FieldId, terms.NodeId, terms.VariablePrefix, terms.FreeText];
29
+
30
+ // The nodes inside which nothing is offered.
31
+ const QUIET = new Set(['Comment', 'StringLiteral']);
32
+
33
+ const ITEMS = new CompletionItems(completionItems);
34
+
35
+ export class EfxCompletions {
36
+ #parser;
37
+
38
+ /** The completions of the language a parser reads. */
39
+ constructor(parser) {
40
+ this.#parser = parser;
41
+ }
42
+
43
+ /** The options for the word before the cursor of a CompletionContext, or null when there are none to offer. */
44
+ complete(context) {
45
+ const word = context.matchBefore(WORD);
46
+ if ((word.from === word.to && !context.explicit) || EfxCompletions.#isQuiet(context.state, word.from)) {
47
+ return null;
48
+ }
49
+ const expected = new ExpectedTokens(this.#parser, context.state, word.from, ASKED);
50
+ if (expected.has(terms.FreeText) && !context.explicit) {
51
+ return null;
52
+ }
53
+ const options = [
54
+ ...EfxCompletions.#wordOptions(expected),
55
+ ...EfxCompletions.#symbolOptions(expected, context.state),
56
+ ...EfxCompletions.#variableOptions(expected, context.state, word.from),
57
+ ];
58
+ return { from: word.from, options, validFor: WHOLE_WORD };
59
+ }
60
+
61
+ static #isQuiet(state, pos) {
62
+ const node = syntaxTree(state).resolveInner(pos, -1);
63
+ return QUIET.has(node.name) && node.from < pos;
64
+ }
65
+
66
+ static #wordOptions(expected) {
67
+ const expressionStarts = expected.has(terms.OpenParenthesis);
68
+ return expected.words().map((word) => ITEMS.optionFor(word, expressionStarts));
69
+ }
70
+
71
+ static #symbolOptions(expected, state) {
72
+ const { fields, nodes } = state.facet(efxSymbols);
73
+ const options = (ids, type, detail) => ids.map((id) => ({ label: id, type, detail }));
74
+ return [
75
+ ...(expected.has(terms.FieldId) ? options(fields, 'constant', 'field') : []),
76
+ ...(expected.has(terms.NodeId) ? options(nodes, 'namespace', 'node') : []),
77
+ ];
78
+ }
79
+
80
+ static #variableOptions(expected, state, pos) {
81
+ if (!expected.has(terms.VariablePrefix)) {
82
+ return [];
83
+ }
84
+ return new Variables(state).usableAt(pos).map((name) => ({ label: name, type: 'variable' }));
85
+ }
86
+ }
@@ -0,0 +1,64 @@
1
+ // What the parser can take at a position of an editor's text: the tokens it is asked about and the
2
+ // words the lexer reads there as tokens it can take. The text before the position is parsed as the
3
+ // editor parses it, reusing the editor's tree, with the tokenizer wrapped: where a parse stack
4
+ // stands at the position, the wrapper asks it which tokens it can take (Stack.canShift) and which
5
+ // mode the lexer is in there (the top of the stack of modes the parser keeps), whose words
6
+ // (generated/words.js) are those the lexer reads there. The parse is strict, so every stack asked is
7
+ // one of the parser's own readings of the text and never one of its recoveries from an error: after
8
+ // an error the parser takes nothing.
9
+
10
+ import { syntaxTree } from '@codemirror/language';
11
+ import { TreeFragment } from '@lezer/common';
12
+ import { ExternalTokenizer } from '@lezer/lr';
13
+ import { modeWords } from '../generated/words.js';
14
+ import { lexerModes, modeAt } from '../lexer.js';
15
+ import * as terms from '../parser.terms.js';
16
+
17
+ export class ExpectedTokens {
18
+ // One for each time a parse stack at the position is tokenized: the words its lexer mode reads
19
+ // as tokens it can take, and the tokens asked about that it can take.
20
+ #readings = [];
21
+
22
+ /** What a language's parser can take at a position of an editor state, asked about some tokens. */
23
+ constructor(parser, state, pos, tokens) {
24
+ const probe = new ExternalTokenizer((input, stack) => {
25
+ if (input.pos === pos) {
26
+ this.#readings.push(ExpectedTokens.#reading(modeAt(input, stack), stack, tokens));
27
+ }
28
+ lexerModes.token(input, stack);
29
+ }, { contextual: true });
30
+ const parse = parser.configure({ strict: true, tokenizers: [{ from: lexerModes, to: probe }] })
31
+ .startParse(state.doc.sliceString(0, pos), ExpectedTokens.#fragments(state, pos));
32
+ try {
33
+ while (parse.advance() === null) {
34
+ // On to the end of the text, or to the first error.
35
+ }
36
+ } catch (error) {
37
+ if (!(error instanceof SyntaxError)) {
38
+ throw error;
39
+ }
40
+ }
41
+ }
42
+
43
+ /** Whether the parser can take the token there. */
44
+ has(token) {
45
+ return this.#readings.some(({ tokens }) => tokens.has(token));
46
+ }
47
+
48
+ /** The words the lexer reads there as tokens the parser can take, each once. */
49
+ words() {
50
+ return [...new Set(this.#readings.flatMap(({ words }) => words))];
51
+ }
52
+
53
+ static #reading(mode, stack, tokens) {
54
+ const words = [...modeWords.get(mode) ?? []].filter(([, type]) => terms[type] !== undefined
55
+ && stack.canShift(terms[type])).map(([word]) => word);
56
+ return { words, tokens: new Set(tokens.filter((token) => stack.canShift(token))) };
57
+ }
58
+
59
+ /** The editor's tree before the position, for the parse to reuse. */
60
+ static #fragments(state, pos) {
61
+ const cut = { fromA: pos, toA: state.doc.length, fromB: pos, toB: pos };
62
+ return TreeFragment.applyChanges(TreeFragment.addTree(syntaxTree(state)), [cut]);
63
+ }
64
+ }
@@ -0,0 +1,60 @@
1
+ // The variables declared in an editor's text, read from its tree, and those a position can use. The
2
+ // variable of an iterator is used in the expression that iterates, and a parameter in the
3
+ // declaration that lists it, after their own declaration. Any other variable, declared with LET, in
4
+ // a context or as a dictionary, is taken as usable everywhere: the editor does not follow how far
5
+ // each of those reaches.
6
+
7
+ import { syntaxTree } from '@codemirror/language';
8
+
9
+ const ITERATIONS = ['QuantifiedExpression', 'IterationExpression'];
10
+ const WITH_PARAMETERS = ['FunctionDeclaration', 'DynamicFunctionDeclaration', 'TemplateDeclaration', 'SingleExpression'];
11
+
12
+ // The nodes that declare a variable, each with the nodes where its variable is used; none: everywhere.
13
+ const DECLARATIONS = new Map([
14
+ ['TypedVariableInitializer', []],
15
+ ['DynamicVariableInitializer', []],
16
+ ['ContextVariableInitializer', []],
17
+ ['DictionaryDeclaration', []],
18
+ ['ValueIterator', ITERATIONS],
19
+ ['ContextIterator', ITERATIONS],
20
+ ['ParameterDeclaration', WITH_PARAMETERS],
21
+ ]);
22
+
23
+ export class Variables {
24
+ // Each declared variable: its name with its `$`, and the part of the text that can use it.
25
+ #variables = [];
26
+
27
+ constructor(state) {
28
+ syntaxTree(state).iterate({
29
+ enter: ({ name, node }) => {
30
+ if (DECLARATIONS.has(name)) {
31
+ this.#declare(node, DECLARATIONS.get(name), state.doc);
32
+ }
33
+ },
34
+ });
35
+ }
36
+
37
+ /** The names of the variables usable at a position, each once, with their `$`. */
38
+ usableAt(pos) {
39
+ const usable = ({ from, to }) => from <= pos && pos <= to;
40
+ return [...new Set(this.#variables.filter(usable).map(({ name }) => name))];
41
+ }
42
+
43
+ #declare(declaration, users, doc) {
44
+ const name = declaration.getChild('VariablePrefix')?.nextSibling;
45
+ const usedIn = users.length === 0 ? { from: 0, to: doc.length } : Variables.#usedIn(declaration, users);
46
+ if (name?.name === 'Identifier' && usedIn !== null) {
47
+ this.#variables.push({ name: `$${doc.sliceString(name.from, name.to)}`, ...usedIn });
48
+ }
49
+ }
50
+
51
+ /** From the end of a declaration to the end of the nearest node above it of the given names; null when none is. */
52
+ static #usedIn(declaration, users) {
53
+ for (let node = declaration.parent; node !== null; node = node.parent) {
54
+ if (users.includes(node.name)) {
55
+ return { from: declaration.to, to: node.to };
56
+ }
57
+ }
58
+ return null;
59
+ }
60
+ }
@@ -0,0 +1,82 @@
1
+ // The highlight tags of the grammar: which tag each kind of node carries, read by the parser
2
+ // (grammar/efx2.grammar, @external propSource). The colours of the tags are in src/efxTheme.js.
3
+ import { styleTags, tags as t } from "@lezer/highlight";
4
+
5
+ // The highlight tag of each kind of node of the grammar (grammar/efx2.grammar), named by the node or by
6
+ // the node and its parent (Parent/Node). A node that is not listed is plain text.
7
+ export const EFX2_STYLES = {
8
+ // The words that start a line, a part of a line or a clause of a rule, and the headers.
9
+ "Let With EVERY When Otherwise Display Invoke Index By Compute Select": t.keyword,
10
+ "Endpoint AT Call Api On OnErrorClause/Error": t.keyword,
11
+ "Assert Report OtherwiseAssert OtherwiseReport As FOR IN Scope": t.keyword,
12
+ "IncludeDirective SummarySectionHeader NavigationSectionHeader StageHeaderStart StageHeaderEnd": t.keyword,
13
+
14
+ // The words of expressions.
15
+ "And Or Not Is In Like Present Empty Unique Has No Duplicates Every Some Satisfies If Then Else For Return": t.className,
16
+ "Distinct At": t.className,
17
+ // The words chosen from a fixed list: asset and label types, format options, field properties,
18
+ // severities, what a failed call does, any notice type and the scope annotations.
19
+ "AssetType LabelType FormatDecimals FormatShort FormatMedium FormatLong FormatNoUnit FormatNoFormatting": t.className,
20
+ "PublicationDate JustificationCode JustificationDescription WasWithheld IsWithheld IsWithholdable IsDisclosed": t.className,
21
+ "IsMasked PrivacyCode RawValue PreferredLanguage PreferredLanguageText": t.className,
22
+ "Error Warning Info Warn Reject Any AnyNoticeTypes/Star Pre Post": t.className,
23
+
24
+ // Types, with the colon after them in a declaration.
25
+ "Text Number Indicator Date Time Duration ContextType Template Dynamic TypeDeclaration/Star": t.typeName,
26
+ "TypedVariableInitializer/Colon DynamicVariableInitializer/Colon ContextVariableInitializer/Colon": t.typeName,
27
+ "ParameterDeclaration/Colon ValueIterator/Colon ContextIterator/Colon": t.typeName,
28
+ "FunctionDeclaration/Colon DynamicFunctionDeclaration/Colon TemplateDefinition/Colon": t.typeName,
29
+
30
+ // The built-in functions.
31
+ "BuiltInFunction/Not BuiltInFunction/Indicator BuiltInFunction/Empty BuiltInFunction/Number": t.function(t.keyword),
32
+ "BuiltInFunction/Text BuiltInFunction/Date BuiltInFunction/Time": t.function(t.keyword),
33
+ "CountFunction SubstringFunction SubstringBeforeFunction SubstringAfterFunction ContainsFunction": t.function(t.keyword),
34
+ "StartsWithFunction EndsWithFunction StringLengthFunction IndexOfSubstringFunction SumFunction": t.function(t.keyword),
35
+ "MinFunction MaxFunction AverageFunction AbsoluteFunction RoundFunction RoundDownFunction": t.function(t.keyword),
36
+ "RoundUpFunction YearFunction MonthFunction DayFunction HoursFunction MinutesFunction SecondsFunction": t.function(t.keyword),
37
+ "YearsFunction MonthsFunction DaysFunction FormatNumberFunction FormatShortFunction FormatMediumFunction": t.function(t.keyword),
38
+ "FormatLongFunction UpperCaseFunction LowerCaseFunction NormalizeSpaceFunction TrimFunction": t.function(t.keyword),
39
+ "TrimLeftFunction TrimRightFunction PadLeftFunction PadRightFunction RepeatFunction ReplaceFunction": t.function(t.keyword),
40
+ "ReplaceRegexFunction UrlEncodeFunction CapitalizeFirstFunction ConcatFunction StringJoinFunction": t.function(t.keyword),
41
+ "CurrentDateFunction CurrentTimeFunction DayTimeDurationFunction YearMonthDurationFunction": t.function(t.keyword),
42
+ "AddDurationFunction SubtractDurationFunction DistinctValuesFunction CountDuplicatesFunction": t.function(t.keyword),
43
+ "GetDuplicatesFunction ValueUnionFunction ValueIntersectFunction ValueExceptFunction SequenceEqualFunction": t.function(t.keyword),
44
+ "SubsequenceFunction IndexOfFunction PreferredLanguageFunction PreferredLanguageTextFunction": t.function(t.keyword),
45
+ "SortFunction ReverseFunction SplitFunction": t.function(t.keyword),
46
+
47
+ // Literals, and the notice types of a rule and the path of an include.
48
+ "StringLiteral UuidV4Literal IntegerLiteral DecimalLiteral True False Always Never DateLiteral TimeLiteral": t.literal,
49
+ "DayTimeDurationLiteral YearMonthDurationLiteral NumericLiteral/Minus NoticeType/Identifier NoticeTypeRange/Minus": t.literal,
50
+ IncludePath: t.literal,
51
+
52
+ // The data of a notice: fields, nodes and attributes.
53
+ "FieldId NodeId BtId SimpleFieldReference/Identifier FieldMention/Identifier SingleExpression/Identifier": t.propertyName,
54
+ "AttributeReference/AtPrefix AttributeReference/Identifier": t.propertyName,
55
+ "AttributeExpression/AtPrefix AttributeExpression/Identifier": t.propertyName,
56
+
57
+ // Variables, and the field value and label of the context in a template.
58
+ "VariablePrefix VariableReference/Identifier TypedVariableInitializer/Identifier": t.variableName,
59
+ "DynamicVariableInitializer/Identifier ContextVariableInitializer/Identifier ParameterDeclaration/Identifier": t.variableName,
60
+ "ValueIterator/Identifier ContextIterator/Identifier DictionaryDeclaration/Identifier": t.variableName,
61
+ "ShorthandFieldValueReferenceFromContextField ShorthandIndirectLabelReferenceFromContextField": t.variableName,
62
+
63
+ // Functions and templates that a file declares.
64
+ "FunctionPrefix FunctionInvocation/Identifier FunctionDeclaration/Identifier": t.function(t.name),
65
+ "DynamicFunctionDeclaration/Identifier TemplateDefinition/Identifier InvokeTemplate/Identifier": t.function(t.name),
66
+
67
+ // Names of assets: asset ids in a label, codelists, flags, rules and stages.
68
+ "OtherAssetId AssetId/AssetType AssetId/LabelType RuleIdentifier StageIdentifier": t.special(t.name),
69
+ "CodelistReference/HashPrefix CodelistReference/Identifier Flag/HashPrefix Flag/Identifier": t.special(t.name),
70
+
71
+ // Template text.
72
+ "FreeText OtherEscapeSequence CharacterReference NewLine": t.special(t.string),
73
+
74
+ "Assignment Comparison Plus Minus Star Slash Percent ColonColon": t.operator,
75
+ "OpenParenthesis CloseParenthesis OpenBracket CloseBracket Pipe Colon Ellipsis": t.punctuation,
76
+ "AttributeReference/Slash AttributeExpression/Slash": t.punctuation,
77
+ "StartContextBlock StartExpressionBlock StartLabelBlock StartHyperlinkBlock StartSelectorBlock EndBlock": t.bracket,
78
+ Comment: t.lineComment,
79
+ Identifier: t.name,
80
+ };
81
+
82
+ export const efx2Highlighting = styleTags(EFX2_STYLES);