@qrvey/formula-lang 0.0.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.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/dist/grammar/generated/qformula.lang.d.ts +4 -0
- package/dist/grammar/generated/qformula.lang.js +42 -0
- package/dist/grammar/qformula.grammar.d.ts +1 -0
- package/dist/grammar/qformula.grammar.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +37 -0
- package/rollup.config.js +12 -0
- package/src/grammar/generated/qformula.lang.cjs +48 -0
- package/src/grammar/generated/qformula.lang.d.cts +4 -0
- package/src/grammar/generated/qformula.lang.d.ts +4 -0
- package/src/grammar/generated/qformula.lang.js +45 -0
- package/src/grammar/qformula.grammar.ts +1 -0
- package/src/grammar/qformula.lang.ts +26 -0
- package/src/grammar/syntax.grammar +89 -0
- package/src/grammar/syntax.grammar.d.ts +3 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { LRLanguage, LanguageSupport } from '@codemirror/language';
|
|
3
|
+
import { styleTags, tags } from '@lezer/highlight';
|
|
4
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
5
|
+
const spec_identifier = { __proto__: null, true: 14, false: 14 };
|
|
6
|
+
const parser = LRParser.deserialize({
|
|
7
|
+
version: 14,
|
|
8
|
+
states: "%jO]QPOOOwQPO'#CdOOQO'#C`'#C`OOQO'#Cf'#CfO!YQPO'#CeO!_QQO'#ChO]QPO'#CiQ!dQPOOO]QPO'#CnOOQO'#C_'#C_O!oQPO'#CxO!wQPO,59OO!|QPO,59PO#TQPO,59SOOQO,59T,59TO]QPO,59VO]QPO,59VO#YQPO,59YO#hQPO'#CoO#|QPO,59dOOQO1G.j1G.jO$UQPO'#C|OOQO'#Cg'#CgO$gQPO1G.kOOQO1G.n1G.nOOQO1G.q1G.qO$lQPO1G.qOOQO1G.t1G.tOOQO,59Z,59ZOOQO-E6m-E6mO%QQPO'#CpO%[QPO,59hOOQO7+$V7+$VO%dQPO,59[OOQO-E6n-E6n",
|
|
9
|
+
stateData: "%|~OgOShOSPOS~OTQOUQOVQO^UOiROkPOoWOrTO~OTQOUQOVQOkPOjlP~Oo[O~Os]O~O^`O`_Oa_O~OmbOjlX~OjdO~OnpP~P]OqhO~O^`O`_Oa_OnkO~OTQOUQOVQOkPOjcXmcX~OmbOjla~O^`O`_Oa_OmnOnpX~OnpO~O`_Oa_O^_ie_in_im_i~OmdXndX~P]OmnOnpa~O^`O`_Oa_Omdanda~OP`ghig~",
|
|
10
|
+
goto: "#lqPPPr!XPPP!h!s!|#V!s!sP!sPP!s#Y#`PPPPPPP#fPPP#iQVOQ^UQaWQe[Qi_Qj`Rqn^XOUW[_`nQYPRlbcQOPUW[_`bn_XOUW[_`n_SOUW[_`nRg[QcYRmcQoeRroRZPRf[",
|
|
11
|
+
nodeNames: "⚠ LineComment Program Expression Value Number String Boolean Array Function FunctionIdentifier FunctionArguments Variable UnaryExpression ArithOp BinaryExpression ArithOp ArithOp ParenthesizedExpression",
|
|
12
|
+
maxTerm: 35,
|
|
13
|
+
skippedNodes: [0, 1],
|
|
14
|
+
repeatNodeCount: 2,
|
|
15
|
+
tokenData: ")o~RoXY#SYZ#wZ[#S]^#wpq#Srs#|xy%jyz%oz{%t{|%y|}&{}!O%y!O!P'Q!P!Q'c!Q![(S!^!_(p!`!a(u!c!}(z!}#O)e#P#Q)j#R#S&d#T#o(z$f$g#S#BY#BZ#S$IS$I_#S$I|$I}#w$I}$JO#w$JT$JU#S$KV$KW#S&FU&FV#S?HT?HU#S~#XYg~XY#SZ[#Spq#S$f$g#S#BY#BZ#S$IS$I_#S$JT$JU#S$KV$KW#S&FU&FV#S?HT?HU#S~#|Oh~~$PVOr#|rs$fs#O#|#O#P$k#P;'S#|;'S;=`%d<%lO#|~$kOU~~$nRO;'S#|;'S;=`$w;=`O#|~$zWOr#|rs$fs#O#|#O#P$k#P;'S#|;'S;=`%d;=`<%l#|<%lO#|~%gP;=`<%l#|~%oOo~~%tOn~~%yOa~R&QU^PsQ{|&d}!O&d!Q![&d!c!}&d#R#S&d#T#o&dQ&iUsQ{|&d}!O&d!Q![&d!c!}&d#R#S&d#T#o&d~'QOm~P'TP!Q!['WP']QTP!Q!['W#R#S'W~'hP`~!P!Q'k~'pSP~OY'kZ;'S'k;'S;=`'|<%lO'k~(PP;=`<%l'kR(ZVTPsQ{|&d}!O&d!O!P'W!Q![(S!c!}&d#R#S(S#T#o&d~(uOk~~(zOj~R)RUsQiP{|&d}!O&d!Q![(z!c!}(z#R#S(z#T#o(z~)jOr~~)oOq~",
|
|
16
|
+
tokenizers: [0, 1],
|
|
17
|
+
topRules: { "Program": [0, 2] },
|
|
18
|
+
specialized: [{ term: 25, get: value => spec_identifier[value] || -1 }],
|
|
19
|
+
tokenPrec: 221
|
|
20
|
+
});
|
|
21
|
+
const QFormulaLang = LRLanguage.define({
|
|
22
|
+
parser: parser.configure({
|
|
23
|
+
props: [
|
|
24
|
+
styleTags({
|
|
25
|
+
Boolean: tags.bool,
|
|
26
|
+
String: tags.string,
|
|
27
|
+
Number: tags.number,
|
|
28
|
+
Variable: tags.keyword,
|
|
29
|
+
LineComment: tags.lineComment,
|
|
30
|
+
FunctionIdentifier: tags.lineComment,
|
|
31
|
+
"( )": tags.paren
|
|
32
|
+
})
|
|
33
|
+
]
|
|
34
|
+
}),
|
|
35
|
+
languageData: {
|
|
36
|
+
commentTokens: { line: "//" }
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
function QFormula() {
|
|
40
|
+
return new LanguageSupport(QFormulaLang);
|
|
41
|
+
}
|
|
42
|
+
export { QFormula, QFormulaLang };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./generated/qformula.lang.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./generated/qformula.lang.js";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./grammar/qformula.grammar";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./grammar/qformula.grammar";
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qrvey/formula-lang",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "QFormula support for qrvey projects",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"build:watch": "tsc -w",
|
|
12
|
+
"prepare-lang": "rollup -c --bundleConfigAsCjs"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://bitbucket.org/qrvey/qrvey_formula_lang.git"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"formula",
|
|
20
|
+
"language",
|
|
21
|
+
"qrvey"
|
|
22
|
+
],
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": "Qrvey Inc",
|
|
25
|
+
"homepage": "https://bitbucket.org/qrvey/qrvey_formula_lang#readme",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@codemirror/language": "^6.6.0",
|
|
28
|
+
"@lezer/highlight": "^1.1.4"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@lezer/generator": "^1.2.2",
|
|
32
|
+
"rollup": "^3.20.2",
|
|
33
|
+
"rollup-plugin-dts": "^5.3.0",
|
|
34
|
+
"rollup-plugin-ts": "^3.2.0",
|
|
35
|
+
"typescript": "^5.0.4"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import typescript from "rollup-plugin-ts"
|
|
2
|
+
import { lezer } from "@lezer/generator/rollup"
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
input: "src/grammar/qformula.lang.ts",
|
|
6
|
+
external: id => id != "tslib" && !/^(\.?\/|\w:)/.test(id),
|
|
7
|
+
output: [
|
|
8
|
+
{ file: "src/grammar/generated/qformula.lang.cjs", format: "cjs" },
|
|
9
|
+
{ dir: "./src/grammar/generated", format: "es" }
|
|
10
|
+
],
|
|
11
|
+
plugins: [lezer(), typescript()]
|
|
12
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var lr = require('@lezer/lr');
|
|
4
|
+
var language = require('@codemirror/language');
|
|
5
|
+
var highlight = require('@lezer/highlight');
|
|
6
|
+
|
|
7
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
8
|
+
const spec_identifier = {__proto__:null,true:14, false:14};
|
|
9
|
+
const parser = lr.LRParser.deserialize({
|
|
10
|
+
version: 14,
|
|
11
|
+
states: "%jO]QPOOOwQPO'#CdOOQO'#C`'#C`OOQO'#Cf'#CfO!YQPO'#CeO!_QQO'#ChO]QPO'#CiQ!dQPOOO]QPO'#CnOOQO'#C_'#C_O!oQPO'#CxO!wQPO,59OO!|QPO,59PO#TQPO,59SOOQO,59T,59TO]QPO,59VO]QPO,59VO#YQPO,59YO#hQPO'#CoO#|QPO,59dOOQO1G.j1G.jO$UQPO'#C|OOQO'#Cg'#CgO$gQPO1G.kOOQO1G.n1G.nOOQO1G.q1G.qO$lQPO1G.qOOQO1G.t1G.tOOQO,59Z,59ZOOQO-E6m-E6mO%QQPO'#CpO%[QPO,59hOOQO7+$V7+$VO%dQPO,59[OOQO-E6n-E6n",
|
|
12
|
+
stateData: "%|~OgOShOSPOS~OTQOUQOVQO^UOiROkPOoWOrTO~OTQOUQOVQOkPOjlP~Oo[O~Os]O~O^`O`_Oa_O~OmbOjlX~OjdO~OnpP~P]OqhO~O^`O`_Oa_OnkO~OTQOUQOVQOkPOjcXmcX~OmbOjla~O^`O`_Oa_OmnOnpX~OnpO~O`_Oa_O^_ie_in_im_i~OmdXndX~P]OmnOnpa~O^`O`_Oa_Omdanda~OP`ghig~",
|
|
13
|
+
goto: "#lqPPPr!XPPP!h!s!|#V!s!sP!sPP!s#Y#`PPPPPPP#fPPP#iQVOQ^UQaWQe[Qi_Qj`Rqn^XOUW[_`nQYPRlbcQOPUW[_`bn_XOUW[_`n_SOUW[_`nRg[QcYRmcQoeRroRZPRf[",
|
|
14
|
+
nodeNames: "⚠ LineComment Program Expression Value Number String Boolean Array Function FunctionIdentifier FunctionArguments Variable UnaryExpression ArithOp BinaryExpression ArithOp ArithOp ParenthesizedExpression",
|
|
15
|
+
maxTerm: 35,
|
|
16
|
+
skippedNodes: [0,1],
|
|
17
|
+
repeatNodeCount: 2,
|
|
18
|
+
tokenData: ")o~RoXY#SYZ#wZ[#S]^#wpq#Srs#|xy%jyz%oz{%t{|%y|}&{}!O%y!O!P'Q!P!Q'c!Q![(S!^!_(p!`!a(u!c!}(z!}#O)e#P#Q)j#R#S&d#T#o(z$f$g#S#BY#BZ#S$IS$I_#S$I|$I}#w$I}$JO#w$JT$JU#S$KV$KW#S&FU&FV#S?HT?HU#S~#XYg~XY#SZ[#Spq#S$f$g#S#BY#BZ#S$IS$I_#S$JT$JU#S$KV$KW#S&FU&FV#S?HT?HU#S~#|Oh~~$PVOr#|rs$fs#O#|#O#P$k#P;'S#|;'S;=`%d<%lO#|~$kOU~~$nRO;'S#|;'S;=`$w;=`O#|~$zWOr#|rs$fs#O#|#O#P$k#P;'S#|;'S;=`%d;=`<%l#|<%lO#|~%gP;=`<%l#|~%oOo~~%tOn~~%yOa~R&QU^PsQ{|&d}!O&d!Q![&d!c!}&d#R#S&d#T#o&dQ&iUsQ{|&d}!O&d!Q![&d!c!}&d#R#S&d#T#o&d~'QOm~P'TP!Q!['WP']QTP!Q!['W#R#S'W~'hP`~!P!Q'k~'pSP~OY'kZ;'S'k;'S;=`'|<%lO'k~(PP;=`<%l'kR(ZVTPsQ{|&d}!O&d!O!P'W!Q![(S!c!}&d#R#S(S#T#o&d~(uOk~~(zOj~R)RUsQiP{|&d}!O&d!Q![(z!c!}(z#R#S(z#T#o(z~)jOr~~)oOq~",
|
|
19
|
+
tokenizers: [0, 1],
|
|
20
|
+
topRules: {"Program":[0,2]},
|
|
21
|
+
specialized: [{term: 25, get: value => spec_identifier[value] || -1}],
|
|
22
|
+
tokenPrec: 221
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const QFormulaLang = language.LRLanguage.define({
|
|
26
|
+
parser: parser.configure({
|
|
27
|
+
props: [
|
|
28
|
+
highlight.styleTags({
|
|
29
|
+
Boolean: highlight.tags.bool,
|
|
30
|
+
String: highlight.tags.string,
|
|
31
|
+
Number: highlight.tags.number,
|
|
32
|
+
Variable: highlight.tags.keyword,
|
|
33
|
+
LineComment: highlight.tags.lineComment,
|
|
34
|
+
FunctionIdentifier: highlight.tags.lineComment,
|
|
35
|
+
"( )": highlight.tags.paren
|
|
36
|
+
})
|
|
37
|
+
]
|
|
38
|
+
}),
|
|
39
|
+
languageData: {
|
|
40
|
+
commentTokens: { line: "//" }
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
function QFormula() {
|
|
44
|
+
return new language.LanguageSupport(QFormulaLang);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.QFormula = QFormula;
|
|
48
|
+
exports.QFormulaLang = QFormulaLang;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { LRLanguage, LanguageSupport } 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 spec_identifier = {__proto__:null,true:14, false:14};
|
|
7
|
+
const parser = LRParser.deserialize({
|
|
8
|
+
version: 14,
|
|
9
|
+
states: "%jO]QPOOOwQPO'#CdOOQO'#C`'#C`OOQO'#Cf'#CfO!YQPO'#CeO!_QQO'#ChO]QPO'#CiQ!dQPOOO]QPO'#CnOOQO'#C_'#C_O!oQPO'#CxO!wQPO,59OO!|QPO,59PO#TQPO,59SOOQO,59T,59TO]QPO,59VO]QPO,59VO#YQPO,59YO#hQPO'#CoO#|QPO,59dOOQO1G.j1G.jO$UQPO'#C|OOQO'#Cg'#CgO$gQPO1G.kOOQO1G.n1G.nOOQO1G.q1G.qO$lQPO1G.qOOQO1G.t1G.tOOQO,59Z,59ZOOQO-E6m-E6mO%QQPO'#CpO%[QPO,59hOOQO7+$V7+$VO%dQPO,59[OOQO-E6n-E6n",
|
|
10
|
+
stateData: "%|~OgOShOSPOS~OTQOUQOVQO^UOiROkPOoWOrTO~OTQOUQOVQOkPOjlP~Oo[O~Os]O~O^`O`_Oa_O~OmbOjlX~OjdO~OnpP~P]OqhO~O^`O`_Oa_OnkO~OTQOUQOVQOkPOjcXmcX~OmbOjla~O^`O`_Oa_OmnOnpX~OnpO~O`_Oa_O^_ie_in_im_i~OmdXndX~P]OmnOnpa~O^`O`_Oa_Omdanda~OP`ghig~",
|
|
11
|
+
goto: "#lqPPPr!XPPP!h!s!|#V!s!sP!sPP!s#Y#`PPPPPPP#fPPP#iQVOQ^UQaWQe[Qi_Qj`Rqn^XOUW[_`nQYPRlbcQOPUW[_`bn_XOUW[_`n_SOUW[_`nRg[QcYRmcQoeRroRZPRf[",
|
|
12
|
+
nodeNames: "⚠ LineComment Program Expression Value Number String Boolean Array Function FunctionIdentifier FunctionArguments Variable UnaryExpression ArithOp BinaryExpression ArithOp ArithOp ParenthesizedExpression",
|
|
13
|
+
maxTerm: 35,
|
|
14
|
+
skippedNodes: [0,1],
|
|
15
|
+
repeatNodeCount: 2,
|
|
16
|
+
tokenData: ")o~RoXY#SYZ#wZ[#S]^#wpq#Srs#|xy%jyz%oz{%t{|%y|}&{}!O%y!O!P'Q!P!Q'c!Q![(S!^!_(p!`!a(u!c!}(z!}#O)e#P#Q)j#R#S&d#T#o(z$f$g#S#BY#BZ#S$IS$I_#S$I|$I}#w$I}$JO#w$JT$JU#S$KV$KW#S&FU&FV#S?HT?HU#S~#XYg~XY#SZ[#Spq#S$f$g#S#BY#BZ#S$IS$I_#S$JT$JU#S$KV$KW#S&FU&FV#S?HT?HU#S~#|Oh~~$PVOr#|rs$fs#O#|#O#P$k#P;'S#|;'S;=`%d<%lO#|~$kOU~~$nRO;'S#|;'S;=`$w;=`O#|~$zWOr#|rs$fs#O#|#O#P$k#P;'S#|;'S;=`%d;=`<%l#|<%lO#|~%gP;=`<%l#|~%oOo~~%tOn~~%yOa~R&QU^PsQ{|&d}!O&d!Q![&d!c!}&d#R#S&d#T#o&dQ&iUsQ{|&d}!O&d!Q![&d!c!}&d#R#S&d#T#o&d~'QOm~P'TP!Q!['WP']QTP!Q!['W#R#S'W~'hP`~!P!Q'k~'pSP~OY'kZ;'S'k;'S;=`'|<%lO'k~(PP;=`<%l'kR(ZVTPsQ{|&d}!O&d!O!P'W!Q![(S!c!}&d#R#S(S#T#o&d~(uOk~~(zOj~R)RUsQiP{|&d}!O&d!Q![(z!c!}(z#R#S(z#T#o(z~)jOr~~)oOq~",
|
|
17
|
+
tokenizers: [0, 1],
|
|
18
|
+
topRules: {"Program":[0,2]},
|
|
19
|
+
specialized: [{term: 25, get: value => spec_identifier[value] || -1}],
|
|
20
|
+
tokenPrec: 221
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const QFormulaLang = LRLanguage.define({
|
|
24
|
+
parser: parser.configure({
|
|
25
|
+
props: [
|
|
26
|
+
styleTags({
|
|
27
|
+
Boolean: tags.bool,
|
|
28
|
+
String: tags.string,
|
|
29
|
+
Number: tags.number,
|
|
30
|
+
Variable: tags.keyword,
|
|
31
|
+
LineComment: tags.lineComment,
|
|
32
|
+
FunctionIdentifier: tags.lineComment,
|
|
33
|
+
"( )": tags.paren
|
|
34
|
+
})
|
|
35
|
+
]
|
|
36
|
+
}),
|
|
37
|
+
languageData: {
|
|
38
|
+
commentTokens: { line: "//" }
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
function QFormula() {
|
|
42
|
+
return new LanguageSupport(QFormulaLang);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { QFormula, QFormulaLang };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./generated/qformula.lang.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { parser } from "./syntax.grammar"
|
|
2
|
+
import { LRLanguage, LanguageSupport } from "@codemirror/language"
|
|
3
|
+
import { styleTags, tags as t } from "@lezer/highlight"
|
|
4
|
+
|
|
5
|
+
export const QFormulaLang = LRLanguage.define({
|
|
6
|
+
parser: parser.configure({
|
|
7
|
+
props: [
|
|
8
|
+
styleTags({
|
|
9
|
+
Boolean: t.bool,
|
|
10
|
+
String: t.string,
|
|
11
|
+
Number: t.number,
|
|
12
|
+
Variable: t.keyword,
|
|
13
|
+
LineComment: t.lineComment,
|
|
14
|
+
FunctionIdentifier: t.lineComment,
|
|
15
|
+
"( )": t.paren
|
|
16
|
+
})
|
|
17
|
+
]
|
|
18
|
+
}),
|
|
19
|
+
languageData: {
|
|
20
|
+
commentTokens: { line: "//" }
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
export function QFormula() {
|
|
25
|
+
return new LanguageSupport(QFormulaLang)
|
|
26
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
@precedence{
|
|
2
|
+
prefix,
|
|
3
|
+
times @left,
|
|
4
|
+
plus @left
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
@top Program { Expression }
|
|
8
|
+
|
|
9
|
+
@skip { spaces | newline | LineComment}
|
|
10
|
+
|
|
11
|
+
Expression {
|
|
12
|
+
Value |
|
|
13
|
+
Function |
|
|
14
|
+
Variable |
|
|
15
|
+
UnaryExpression |
|
|
16
|
+
BinaryExpression |
|
|
17
|
+
ParenthesizedExpression
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Value {
|
|
21
|
+
Number |
|
|
22
|
+
String |
|
|
23
|
+
boolean |
|
|
24
|
+
Array
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
UnaryExpression{
|
|
28
|
+
!prefix (ArithOp<"+" | "-">) Expression
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
BinaryExpression{
|
|
32
|
+
Expression !times (divide | ArithOp<"*">) Expression |
|
|
33
|
+
Expression !plus ArithOp<"+" | "-"> Expression
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
ParenthesizedExpression { "(" Expression ")" }
|
|
37
|
+
|
|
38
|
+
Function {
|
|
39
|
+
FunctionIdentifier "(" FunctionArguments ")"
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
FunctionIdentifier {
|
|
43
|
+
identifier
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
FunctionArguments{
|
|
47
|
+
commaSepAllowEmpty<Expression>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
Array{
|
|
51
|
+
"<" commaSepAllowEmpty<Value> ">"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Variable { "\[" variableId "\]" }
|
|
55
|
+
|
|
56
|
+
commaSepAllowEmpty<content> {
|
|
57
|
+
"" | content ("," content?)*
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
boolean { @specialize[@name=Boolean]<identifier, "true" | "false"> }
|
|
61
|
+
|
|
62
|
+
@tokens {
|
|
63
|
+
String { '"' (!["\\] | "\\" _)* '"' }
|
|
64
|
+
|
|
65
|
+
Number {
|
|
66
|
+
(@digit ("_" | @digit)* ("." ("_" | @digit)*)? | "." @digit ("_" | @digit)*)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
LineComment { "//" ![\n]* }
|
|
70
|
+
|
|
71
|
+
spaces[@export] { $[\u0009 \u000b\u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+ }
|
|
72
|
+
newline[@export] { $[\r\n\u2028\u2029] }
|
|
73
|
+
|
|
74
|
+
variableId { (@asciiLetter | @digit | $[_\-\+])+ }
|
|
75
|
+
|
|
76
|
+
divide[@name=ArithOp] { "/" }
|
|
77
|
+
|
|
78
|
+
@precedence { LineComment, divide }
|
|
79
|
+
|
|
80
|
+
identifier { word }
|
|
81
|
+
|
|
82
|
+
word { @asciiLetter (@asciiLetter | @digit | $[_])* }
|
|
83
|
+
|
|
84
|
+
ArithOp<expr> { expr }
|
|
85
|
+
|
|
86
|
+
@precedence { spaces, newline, identifier }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@detectDelim
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./grammar/qformula.grammar";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"strict": true,
|
|
4
|
+
"moduleResolution": "node",
|
|
5
|
+
"module": "esnext",
|
|
6
|
+
"target": "es2017",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"outDir": "./dist",
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"sourceMap": false,
|
|
11
|
+
"allowJs": true
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"src"
|
|
15
|
+
],
|
|
16
|
+
"exclude": [
|
|
17
|
+
"src/grammar/qformula.lang.ts"
|
|
18
|
+
]
|
|
19
|
+
}
|