@valtzu/codemirror-lang-el 0.1.13
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.
- package/.editorconfig +3 -0
- package/.github/workflows/publish.yml +31 -0
- package/LICENSE +21 -0
- package/README.md +18 -0
- package/dist/index.cjs +111 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +106 -0
- package/package.json +43 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Publish package to npm
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
packages: write
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v3
|
|
13
|
+
# Setup .npmrc file to publish to GitHub Packages
|
|
14
|
+
- uses: actions/setup-node@v3
|
|
15
|
+
with:
|
|
16
|
+
node-version: '16.x'
|
|
17
|
+
registry-url: 'https://registry.npmjs.org'
|
|
18
|
+
- run: npm install
|
|
19
|
+
- run: npm run test
|
|
20
|
+
- name: Upload binaries to release
|
|
21
|
+
uses: svenstaro/upload-release-action@v2
|
|
22
|
+
with:
|
|
23
|
+
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
|
24
|
+
file: dist/*
|
|
25
|
+
tag: ${{ github.ref_name }}
|
|
26
|
+
overwrite: true
|
|
27
|
+
file_glob: true
|
|
28
|
+
- run: npm --no-git-tag-version version from-git
|
|
29
|
+
- run: npm publish
|
|
30
|
+
env:
|
|
31
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2021 by Marijn Haverbeke <marijnh@gmail.com> and others
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Symfony Expression Language support for CodeMirror
|
|
2
|
+
|
|
3
|
+
```javascript
|
|
4
|
+
import {EditorView, basicSetup} from "codemirror";
|
|
5
|
+
import { expressionlanguage } from "@valtzu/codemirror-lang-el";
|
|
6
|
+
import {acceptCompletion} from "@codemirror/autocomplete";
|
|
7
|
+
import {keymap} from "@codemirror/view"
|
|
8
|
+
|
|
9
|
+
let editor = new EditorView({
|
|
10
|
+
extensions: [
|
|
11
|
+
keymap.of([{key: "Tab", run: acceptCompletion}]),
|
|
12
|
+
basicSetup,
|
|
13
|
+
expressionlanguage({ identifiers: ['foo', 'bar'], functions: {'smh': [], smash_my_head: ['object']} })
|
|
14
|
+
],
|
|
15
|
+
parent: document.body,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var lr = require('@lezer/lr');
|
|
6
|
+
var language = require('@codemirror/language');
|
|
7
|
+
var highlight = require('@lezer/highlight');
|
|
8
|
+
|
|
9
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
10
|
+
const parser = lr.LRParser.deserialize({
|
|
11
|
+
version: 14,
|
|
12
|
+
states: "$nQVQPOOO!QQQO'#ChO!VQPO'#CjO!^QPO'#CmOOQO'#Cs'#CsOOQO'#Cn'#CnQVQPOOO!eQQO,59SOOQO,59U,59UO!jQPO,59UOOQO,59X,59XO!rQPO,59XOOQO-E6l-E6lOVQPO1G.nOVQPO'#CoO!yQPO1G.pOOQO1G.p1G.pOOQO1G.s1G.sO#RQPO7+$YOOQO,59Z,59ZOOQO-E6m-E6mOOQO7+$[7+$[OOQO<<Gt<<GtO#ZQQO<<GtO#`QQOAN=`OVQPOG22zO#eQPOLD(fOOQO!$'LQ!$'LQ",
|
|
13
|
+
stateData: "#r~OfOS~OQSORSOSSOTSOUSOVSOWSOXSOYSOZSO`ROiPOmQO~O]VO~OlWO~PVO_YO~PVOj]O~Ok^Ol`O~O_aO~PVOk^OleO~OhfOkgO~O]hO~OjiO~OhkO~OQUTXWRW~",
|
|
14
|
+
goto: "!ghPPPPPPPPPPPPiPiPPis}PPP!TaSOQRUZ]^iQUOQZRT[UZQ_XRd_WTORUZQXQQb]Qc^Rji",
|
|
15
|
+
nodeNames: "⚠ Program Number Identifier String Boolean Null Operator OperatorKeyword Punctuation NullSafe NullCoalescing Object ObjectKey Array ClosingBracket OpeningBracket Application",
|
|
16
|
+
maxTerm: 29,
|
|
17
|
+
nodeProps: [
|
|
18
|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]#R#S,]#T#V,]#V#W9l#W#o,]R9sU]QRP!Q![,]!c!},]#R#S,]#T#[,]#[#]:V#]#o,]R:^U]QRP!Q![,]!c!},]#R#S,]#T#X,]#X#Y1n#Y#o,]R:wW]QRP!Q![,]!c!},]#R#S,]#T#c,]#c#d;a#d#i,]#i#j<p#j#o,]R;hU]QRP!Q![,]!c!},]#R#S,]#T#h,]#h#i;z#i#o,]R<TT]QWPRPpq<d!Q![,]!c!},]#R#S,]#T#o,]P<gP#]#^<jP<mP#b#c4vR<wU]QRP!Q![,]!c!},]#R#S,]#T#`,]#`#a=Z#a#o,]R=bU]QRP!Q![,]!c!},]#R#S,]#T#`,]#`#a=t#a#o,]R=}S]QUPRP!Q![,]!c!},]#R#S,]#T#o,]R>bU]QRP!Q![,]!c!},]#R#S,]#T#f,]#f#g.O#g#o,]R>{U]QRP!Q![,]!c!},]#R#S,]#T#h,]#h#i?_#i#o,]R?fT]QRP!Q![,]!c!},]#R#S,]#T#U?u#U#o,]R?|U]QRP!Q![,]!c!},]#R#S,]#T#f,]#f#g@`#g#o,]R@gU]QRP!Q![,]!c!},]#R#S,]#T#h,]#h#i3]#i#o,]RAQU]QRP!Q![,]!c!},]#R#S,]#T#f,]#f#gAd#g#o,]RAkU]QRP!Q![,]!c!},]#R#S,]#T#i,]#i#j6g#j#o,]~BSOi~~BXPV~#p#q$z~BaOh~",
|
|
24
|
+
tokenizers: [0, 1],
|
|
25
|
+
topRules: {"Program":[0,1]},
|
|
26
|
+
tokenPrec: 118
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const identifier = /^[a-zA-Z_]+[a-zA-Z_0-9]*$/;
|
|
30
|
+
const ELLanguage = language.LRLanguage.define({
|
|
31
|
+
parser: parser.configure({
|
|
32
|
+
props: [
|
|
33
|
+
language.indentNodeProp.add({
|
|
34
|
+
Application: language.delimitedIndent({ closing: ")", align: false })
|
|
35
|
+
}),
|
|
36
|
+
language.foldNodeProp.add({
|
|
37
|
+
Application: language.foldInside
|
|
38
|
+
}),
|
|
39
|
+
highlight.styleTags({
|
|
40
|
+
Identifier: highlight.tags.variableName,
|
|
41
|
+
Boolean: highlight.tags.bool,
|
|
42
|
+
String: highlight.tags.string,
|
|
43
|
+
Number: highlight.tags.number,
|
|
44
|
+
OpeningBracket: highlight.tags.paren,
|
|
45
|
+
ClosingBracket: highlight.tags.paren,
|
|
46
|
+
'[': highlight.tags.squareBracket,
|
|
47
|
+
']': highlight.tags.squareBracket,
|
|
48
|
+
OperatorKeyword: highlight.tags.operatorKeyword,
|
|
49
|
+
Operator: highlight.tags.operator,
|
|
50
|
+
NullSafe: highlight.tags.operator,
|
|
51
|
+
NullCoalescing: highlight.tags.operator,
|
|
52
|
+
Punctuation: highlight.tags.punctuation,
|
|
53
|
+
})
|
|
54
|
+
]
|
|
55
|
+
}),
|
|
56
|
+
languageData: {}
|
|
57
|
+
});
|
|
58
|
+
function completeOperatorKeyword(state, config, tree, from, to) {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
const text = state.sliceDoc(from, to);
|
|
61
|
+
return {
|
|
62
|
+
from,
|
|
63
|
+
to,
|
|
64
|
+
options: (_b = (_a = config.operatorKeywords) === null || _a === void 0 ? void 0 : _a.filter(value => value.startsWith(text)).map(keyword => ({ label: keyword, type: "property" }))) !== null && _b !== void 0 ? _b : [],
|
|
65
|
+
validFor: (text) => { var _a, _b; return (_b = (_a = config.operatorKeywords) === null || _a === void 0 ? void 0 : _a.some(value => value.startsWith(text))) !== null && _b !== void 0 ? _b : false; },
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function completeIdentifier(state, config, tree, from, to) {
|
|
69
|
+
var _a, _b, _c, _d, _e;
|
|
70
|
+
const text = state.sliceDoc(from, to);
|
|
71
|
+
const identifiers = (_b = (_a = config.identifiers) === null || _a === void 0 ? void 0 : _a.filter(i => i.startsWith(text))) !== null && _b !== void 0 ? _b : [];
|
|
72
|
+
const functions = Object.entries((_c = config.functions) !== null && _c !== void 0 ? _c : {}).filter(([fn]) => fn.startsWith(text));
|
|
73
|
+
return {
|
|
74
|
+
from,
|
|
75
|
+
to,
|
|
76
|
+
options: [
|
|
77
|
+
...((_d = identifiers.map(identifier => ({ label: identifier, type: "property" }))) !== null && _d !== void 0 ? _d : []),
|
|
78
|
+
...((_e = functions.map(([fn, args]) => ({ label: `${fn}(${args.join(',')})`, apply: `${fn}(${args.length == 0 ? ')' : ''}`, type: "function" }))) !== null && _e !== void 0 ? _e : []),
|
|
79
|
+
],
|
|
80
|
+
validFor: identifier,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function expressionLanguageCompletionFor(config, context) {
|
|
84
|
+
let { state, pos } = context;
|
|
85
|
+
let tree = language.syntaxTree(state).resolveInner(pos, -1);
|
|
86
|
+
// let around = tree.resolve(pos);
|
|
87
|
+
// for (let scan = pos, before; around == tree && (before = tree.childBefore(scan));) {
|
|
88
|
+
// let last = before.lastChild;
|
|
89
|
+
// if (!last || !last.type.isError || last.from < last.to) break;
|
|
90
|
+
// around = tree = before;
|
|
91
|
+
// scan = last.from;
|
|
92
|
+
// }
|
|
93
|
+
if (tree.prevSibling && !['Operator', 'OperatorKeyword', 'Punctuation', 'NullSafe', 'NullCoalescing'].includes(tree.prevSibling.name)) {
|
|
94
|
+
return completeOperatorKeyword(state, config, tree, tree.from, pos);
|
|
95
|
+
}
|
|
96
|
+
if (tree.name == "Identifier") {
|
|
97
|
+
return completeIdentifier(state, config, tree, tree.from, pos);
|
|
98
|
+
}
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
function expressionLanguageCompletionSourceWith(config) {
|
|
102
|
+
var _a;
|
|
103
|
+
(_a = config.operatorKeywords) !== null && _a !== void 0 ? _a : (config.operatorKeywords = ['starts with', 'ends with', 'contains', 'matches', 'not in', 'in', 'not', 'or', 'and']);
|
|
104
|
+
return (context) => expressionLanguageCompletionFor(config, context);
|
|
105
|
+
}
|
|
106
|
+
function expressionlanguage(config = {}, extensions = []) {
|
|
107
|
+
return new language.LanguageSupport(ELLanguage, [ELLanguage.data.of({ autocomplete: expressionLanguageCompletionSourceWith(config) }), ...extensions]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
exports.ELLanguage = ELLanguage;
|
|
111
|
+
exports.expressionlanguage = expressionlanguage;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LRLanguage, LanguageSupport } from "@codemirror/language";
|
|
2
|
+
interface ExpressionLanguageConfig {
|
|
3
|
+
identifiers?: readonly string[];
|
|
4
|
+
functions?: Record<string, readonly string[]>;
|
|
5
|
+
operatorKeywords?: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
declare const ELLanguage: LRLanguage;
|
|
8
|
+
declare function expressionlanguage(config?: ExpressionLanguageConfig, extensions?: Array<any>): LanguageSupport;
|
|
9
|
+
export { ExpressionLanguageConfig, ELLanguage, expressionlanguage };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LRLanguage, LanguageSupport } from "@codemirror/language";
|
|
2
|
+
interface ExpressionLanguageConfig {
|
|
3
|
+
identifiers?: readonly string[];
|
|
4
|
+
functions?: Record<string, readonly string[]>;
|
|
5
|
+
operatorKeywords?: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
declare const ELLanguage: LRLanguage;
|
|
8
|
+
declare function expressionlanguage(config?: ExpressionLanguageConfig, extensions?: Array<any>): LanguageSupport;
|
|
9
|
+
export { ExpressionLanguageConfig, ELLanguage, expressionlanguage };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { LRLanguage, indentNodeProp, delimitedIndent, foldNodeProp, foldInside, LanguageSupport, syntaxTree } from '@codemirror/language';
|
|
3
|
+
import { styleTags, tags } from '@lezer/highlight';
|
|
4
|
+
|
|
5
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
6
|
+
const parser = LRParser.deserialize({
|
|
7
|
+
version: 14,
|
|
8
|
+
states: "$nQVQPOOO!QQQO'#ChO!VQPO'#CjO!^QPO'#CmOOQO'#Cs'#CsOOQO'#Cn'#CnQVQPOOO!eQQO,59SOOQO,59U,59UO!jQPO,59UOOQO,59X,59XO!rQPO,59XOOQO-E6l-E6lOVQPO1G.nOVQPO'#CoO!yQPO1G.pOOQO1G.p1G.pOOQO1G.s1G.sO#RQPO7+$YOOQO,59Z,59ZOOQO-E6m-E6mOOQO7+$[7+$[OOQO<<Gt<<GtO#ZQQO<<GtO#`QQOAN=`OVQPOG22zO#eQPOLD(fOOQO!$'LQ!$'LQ",
|
|
9
|
+
stateData: "#r~OfOS~OQSORSOSSOTSOUSOVSOWSOXSOYSOZSO`ROiPOmQO~O]VO~OlWO~PVO_YO~PVOj]O~Ok^Ol`O~O_aO~PVOk^OleO~OhfOkgO~O]hO~OjiO~OhkO~OQUTXWRW~",
|
|
10
|
+
goto: "!ghPPPPPPPPPPPPiPiPPis}PPP!TaSOQRUZ]^iQUOQZRT[UZQ_XRd_WTORUZQXQQb]Qc^Rji",
|
|
11
|
+
nodeNames: "⚠ Program Number Identifier String Boolean Null Operator OperatorKeyword Punctuation NullSafe NullCoalescing Object ObjectKey Array ClosingBracket OpeningBracket Application",
|
|
12
|
+
maxTerm: 29,
|
|
13
|
+
nodeProps: [
|
|
14
|
+
["openedBy", 15,"OpeningBracket"],
|
|
15
|
+
["closedBy", 16,"ClosingBracket"]
|
|
16
|
+
],
|
|
17
|
+
skippedNodes: [0],
|
|
18
|
+
repeatNodeCount: 2,
|
|
19
|
+
tokenData: "Ba~R!QXY$XYZ$X]^$Xpq$Xqr$jrs%Puv$zvw&owx&wxy(`yz(ez{(j{|$z|}(r}!O$z!O!P(w!P!Q$z!Q![*Y![!]+i!^!_$r!_!`+p!`!a$r!a!b+v!c!},]!}#O,p#P#Q,u#Q#R$z#R#S,]#T#U,z#U#V,]#V#W.e#W#X,]#X#Y2X#Y#Z4{#Z#],]#]#^7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]!c!},]#R#S,]#T#`,]#`#a=t#a#o,]R=}S]QUPRP!Q![,]!c!},]#R#S,]#T#o,]R>bU]QRP!Q![,]!c!},]#R#S,]#T#f,]#f#g.O#g#o,]R>{U]QRP!Q![,]!c!},]#R#S,]#T#h,]#h#i?_#i#o,]R?fT]QRP!Q![,]!c!},]#R#S,]#T#U?u#U#o,]R?|U]QRP!Q![,]!c!},]#R#S,]#T#f,]#f#g@`#g#o,]R@gU]QRP!Q![,]!c!},]#R#S,]#T#h,]#h#i3]#i#o,]RAQU]QRP!Q![,]!c!},]#R#S,]#T#f,]#f#gAd#g#o,]RAkU]QRP!Q![,]!c!},]#R#S,]#T#i,]#i#j6g#j#o,]~BSOi~~BXPV~#p#q$z~BaOh~",
|
|
20
|
+
tokenizers: [0, 1],
|
|
21
|
+
topRules: {"Program":[0,1]},
|
|
22
|
+
tokenPrec: 118
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const identifier = /^[a-zA-Z_]+[a-zA-Z_0-9]*$/;
|
|
26
|
+
const ELLanguage = LRLanguage.define({
|
|
27
|
+
parser: parser.configure({
|
|
28
|
+
props: [
|
|
29
|
+
indentNodeProp.add({
|
|
30
|
+
Application: delimitedIndent({ closing: ")", align: false })
|
|
31
|
+
}),
|
|
32
|
+
foldNodeProp.add({
|
|
33
|
+
Application: foldInside
|
|
34
|
+
}),
|
|
35
|
+
styleTags({
|
|
36
|
+
Identifier: tags.variableName,
|
|
37
|
+
Boolean: tags.bool,
|
|
38
|
+
String: tags.string,
|
|
39
|
+
Number: tags.number,
|
|
40
|
+
OpeningBracket: tags.paren,
|
|
41
|
+
ClosingBracket: tags.paren,
|
|
42
|
+
'[': tags.squareBracket,
|
|
43
|
+
']': tags.squareBracket,
|
|
44
|
+
OperatorKeyword: tags.operatorKeyword,
|
|
45
|
+
Operator: tags.operator,
|
|
46
|
+
NullSafe: tags.operator,
|
|
47
|
+
NullCoalescing: tags.operator,
|
|
48
|
+
Punctuation: tags.punctuation,
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
}),
|
|
52
|
+
languageData: {}
|
|
53
|
+
});
|
|
54
|
+
function completeOperatorKeyword(state, config, tree, from, to) {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
const text = state.sliceDoc(from, to);
|
|
57
|
+
return {
|
|
58
|
+
from,
|
|
59
|
+
to,
|
|
60
|
+
options: (_b = (_a = config.operatorKeywords) === null || _a === void 0 ? void 0 : _a.filter(value => value.startsWith(text)).map(keyword => ({ label: keyword, type: "property" }))) !== null && _b !== void 0 ? _b : [],
|
|
61
|
+
validFor: (text) => { var _a, _b; return (_b = (_a = config.operatorKeywords) === null || _a === void 0 ? void 0 : _a.some(value => value.startsWith(text))) !== null && _b !== void 0 ? _b : false; },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function completeIdentifier(state, config, tree, from, to) {
|
|
65
|
+
var _a, _b, _c, _d, _e;
|
|
66
|
+
const text = state.sliceDoc(from, to);
|
|
67
|
+
const identifiers = (_b = (_a = config.identifiers) === null || _a === void 0 ? void 0 : _a.filter(i => i.startsWith(text))) !== null && _b !== void 0 ? _b : [];
|
|
68
|
+
const functions = Object.entries((_c = config.functions) !== null && _c !== void 0 ? _c : {}).filter(([fn]) => fn.startsWith(text));
|
|
69
|
+
return {
|
|
70
|
+
from,
|
|
71
|
+
to,
|
|
72
|
+
options: [
|
|
73
|
+
...((_d = identifiers.map(identifier => ({ label: identifier, type: "property" }))) !== null && _d !== void 0 ? _d : []),
|
|
74
|
+
...((_e = functions.map(([fn, args]) => ({ label: `${fn}(${args.join(',')})`, apply: `${fn}(${args.length == 0 ? ')' : ''}`, type: "function" }))) !== null && _e !== void 0 ? _e : []),
|
|
75
|
+
],
|
|
76
|
+
validFor: identifier,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function expressionLanguageCompletionFor(config, context) {
|
|
80
|
+
let { state, pos } = context;
|
|
81
|
+
let tree = syntaxTree(state).resolveInner(pos, -1);
|
|
82
|
+
// let around = tree.resolve(pos);
|
|
83
|
+
// for (let scan = pos, before; around == tree && (before = tree.childBefore(scan));) {
|
|
84
|
+
// let last = before.lastChild;
|
|
85
|
+
// if (!last || !last.type.isError || last.from < last.to) break;
|
|
86
|
+
// around = tree = before;
|
|
87
|
+
// scan = last.from;
|
|
88
|
+
// }
|
|
89
|
+
if (tree.prevSibling && !['Operator', 'OperatorKeyword', 'Punctuation', 'NullSafe', 'NullCoalescing'].includes(tree.prevSibling.name)) {
|
|
90
|
+
return completeOperatorKeyword(state, config, tree, tree.from, pos);
|
|
91
|
+
}
|
|
92
|
+
if (tree.name == "Identifier") {
|
|
93
|
+
return completeIdentifier(state, config, tree, tree.from, pos);
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
function expressionLanguageCompletionSourceWith(config) {
|
|
98
|
+
var _a;
|
|
99
|
+
(_a = config.operatorKeywords) !== null && _a !== void 0 ? _a : (config.operatorKeywords = ['starts with', 'ends with', 'contains', 'matches', 'not in', 'in', 'not', 'or', 'and']);
|
|
100
|
+
return (context) => expressionLanguageCompletionFor(config, context);
|
|
101
|
+
}
|
|
102
|
+
function expressionlanguage(config = {}, extensions = []) {
|
|
103
|
+
return new LanguageSupport(ELLanguage, [ELLanguage.data.of({ autocomplete: expressionLanguageCompletionSourceWith(config) }), ...extensions]);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { ELLanguage, expressionlanguage };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@valtzu/codemirror-lang-el",
|
|
3
|
+
"description": "Symfony Expression Language language support for CodeMirror",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"test": "mocha test/test.js test/test-complete.js",
|
|
6
|
+
"prepare": "rollup -c"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "dist/index.cjs",
|
|
10
|
+
"module": "dist/index.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"types": "dist/index.d.ts",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@codemirror/autocomplete": "^6.9.0",
|
|
19
|
+
"@codemirror/language": "^6.0.0",
|
|
20
|
+
"@lezer/highlight": "^1.0.0",
|
|
21
|
+
"@lezer/lr": "^1.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@lezer/generator": "^1.0.0",
|
|
25
|
+
"@types/mocha": "^10.0.1",
|
|
26
|
+
"ist": "^1.1.7",
|
|
27
|
+
"mocha": "^9.0.1",
|
|
28
|
+
"rollup": "^2.60.2",
|
|
29
|
+
"rollup-plugin-dts": "^4.0.1",
|
|
30
|
+
"rollup-plugin-ts": "^3.0.2",
|
|
31
|
+
"typescript": "^4.3.4"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/valtzu/codemirror-lang-el"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"registry": "https://registry.npmjs.org/"
|
|
41
|
+
},
|
|
42
|
+
"version": "0.1.13"
|
|
43
|
+
}
|