Skip to content

Commit fdbec07

Browse files
committed
Added lezer to language definition
1 parent 1f113d2 commit fdbec07

7 files changed

Lines changed: 412 additions & 163 deletions

File tree

‎lib/mathjs-parser.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This file was generated by lezer-generator. You probably shouldn't edit it.
2+
import {LRParser} from "@lezer/lr"
3+
const spec_Identifier = {__proto__:null,to:42, in:44, and:46, not:48, or:50, xor:52, mod:54}
4+
export const parser = LRParser.deserialize({
5+
version: 14,
6+
states: "!vQVQPOOO!ZQPO'#C_O!bQPO'#C_O!iQPO'#C_OOQO'#Cb'#CbOOQO'#C^'#C^OOQO'#Cg'#CgQVQPOOOOQO,58y,58yO!pQPO,58yO!wQPO,58yO#OQPO,58yOOQO-E6e-E6eOOQO1G.e1G.e",
7+
stateData: "#V~O^OS~OSTOTTOVTOWTOXTOYTO_POaQOcROeSOfSOgSOhSOiSOjSOkSO~O`WO~PVObWO~PVOdWO~PVO`]O~PVOb]O~PVOd]O~PVO",
8+
goto: "!T[PP]gPPgPPPPqaUOPQRVXYZaTOPQRVXYZQVOQXPQYQQZRX[VXYZ",
9+
nodeNames: "⚠ Program Item Group Number String Keyword Identifier Operator LineComment BlockComment",
10+
maxTerm: 27,
11+
skippedNodes: [0],
12+
repeatNodeCount: 1,
13+
tokenData: ".V~RpXY#VYZ#V]^#Vpq#Vqr#hrs#ust$juv#pvw#pwx'Oxy([yz(az{#p{|#p}!O#p!O!P(f!P!Q#p!Q!R(x!R![+R!^!_,b!_!`,u!`!a,{!c!}-`!}#O-q#P#Q-v#Q#R#p#R#S-`#T#o-`#o#p-{#p#q#p#q#r.Q#r#s#p~#[S^~XY#VYZ#V]^#Vpq#V~#mPW~!_!`#p~#uOW~~#xUOY#uZr#urs$[s;'S#u;'S;=`$d<%lO#u~$aPT~rs#u~$gP;=`<%l#u~$mUOY%PZ#o%P#o#p%h#p;'S%P;'S;=`%b<%lO%P~%USX~OY%PZ;'S%P;'S;=`%b<%lO%P~%eP;=`<%l%P~%kVOs%hst&Qt#q%h#q#r&o#r;'S%h;'S;=`&i<%lO%h~&TTO#q%h#q#r&d#r;'S%h;'S;=`&i<%lO%h~&iOY~~&lP;=`<%l%h~&rSOs%ht;'S%h;'S;=`&i<%lO%h~'TUW~OY'gZw'gwx'|x;'S'g;'S;=`(U<%lO'g~'jUOY'gZw'gwx'|x;'S'g;'S;=`(U<%lO'g~(RPT~wx'g~(XP;=`<%l'g~(aO_~~(fO`~~(iTz{#p{|#p}!O#p!P!Q#p#Q#R#p~(}XS~!O!P)j!Q![+R!f!g*[!g!h*[#W#X*[#X#Y*[#]#^*|#^#_*|#l#m+p~)mP!Q![)p~)uVS~!Q![)p!f!g*[!g!h*[#W#X*[#X#Y*[#]#^*|#^#_*|~*_R{|*h}!O*h!Q![*n~*kP!Q![*n~*sRS~!Q![*n#]#^*|#^#_*|~+ROS~~+WWS~!O!P)j!Q![+R!f!g*[!g!h*[#W#X*[#X#Y*[#]#^*|#^#_*|~+sR!Q![+|!c!i+|#T#Z+|~,RTS~!Q![+|!c!i+|#T#Z+|#]#^*|#^#_*|~,gQW~!^!_,m!_!`#p~,rPW~!^!_#p~,xP!_!`#p~-QQW~!_!`#p!`!a-W~-]PW~!`!a#p~-eSV~!Q![-`!c!}-`#R#S-`#T#o-`~-vOa~~-{Ob~~.QOc~~.VOd~",
14+
tokenizers: [0],
15+
topRules: {"Program":[0,1]},
16+
specialized: [{term: 7, get: (value) => spec_Identifier[value] || -1}],
17+
tokenPrec: 0
18+
})

‎lib/mathjs-parser.terms.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This file was generated by lezer-generator. You probably shouldn't edit it.
2+
export const
3+
Program = 1,
4+
Item = 2,
5+
Group = 3,
6+
Number = 4,
7+
String = 5,
8+
Keyword = 6,
9+
Identifier = 7,
10+
Operator = 8,
11+
LineComment = 9,
12+
BlockComment = 10

‎lib/mathjs.grammar‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@top Program { Item* }
2+
3+
@skip { space }
4+
5+
Item {
6+
Group |
7+
Number |
8+
String |
9+
Keyword |
10+
Identifier |
11+
Operator |
12+
LineComment |
13+
BlockComment
14+
}
15+
16+
Keyword {
17+
@specialize<Identifier, "to"> |
18+
@specialize<Identifier, "in"> |
19+
@specialize<Identifier, "and"> |
20+
@specialize<Identifier, "not"> |
21+
@specialize<Identifier, "or"> |
22+
@specialize<Identifier, "xor"> |
23+
@specialize<Identifier, "mod">
24+
}
25+
26+
Group {
27+
"(" Item* ")" |
28+
"[" Item* "]" |
29+
"{" Item* "}"
30+
}
31+
32+
@tokens {
33+
space { $[\u0009\u000a\u000d\u0020]+ }
34+
35+
Number {
36+
"0x" $[0-9a-fA-F]+ $[ij]? |
37+
$[0-9]+ ("." $[0-9]+)? (("e"|"E"|"d"|"D") $[+\-]? $[0-9]+)? $[ij]?
38+
}
39+
40+
DoubleString { '"' (!["\n] | '""')* '"' }
41+
SingleString { "'" (![\'\n] | "''")* "'" }
42+
String { DoubleString | SingleString }
43+
44+
BlockComment { "#{" (![#}] | "#" ![}] | "}" ![#])* "#}" }
45+
LineComment { "#" ![\{\n] ![\n]* }
46+
47+
Identifier { $[_A-Za-z] $[_A-Za-z0-9]* }
48+
49+
Operator {
50+
"==" | "!=" | "<=" | ">=" | "<<" | ">>" | ">>>" | "<<<" |
51+
".+" | ".-" | ".*" | "./" | ".^" |
52+
"+" | "-" | "*" | "/" | "&" | "|" | "^" | "~" | "<" | ">" | "!" | "%" | "'"
53+
}
54+
55+
}

‎main.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import initialState from "./ext/initialState.js"
44

55
import { EditorState } from "@codemirror/state"
66

7-
import { StreamLanguage } from '@codemirror/language'
8-
97
import { EditorView, basicSetup } from "codemirror"
108

119
import { mathjs } from './mathjs.js'
@@ -254,7 +252,7 @@ function createState(ID) {
254252
doc: getSessionText(ID),
255253
extensions: [
256254
basicSetup,
257-
StreamLanguage.define(mathjs(() => workerState, () => parserState)),
255+
mathjs(() => workerState, () => parserState),
258256
EditorView.lineWrapping,
259257
EditorView.updateListener.of(update => {
260258
if (update.docChanged) {

0 commit comments

Comments
 (0)