Save work. What work?

This commit is contained in:
Scott Richmond 2023-12-15 17:20:48 -05:00
parent 65a5fd6984
commit 4005a12358
4 changed files with 31 additions and 8 deletions

View File

@ -58,8 +58,12 @@ complex {
Repeat { silent<"repeat"> (Word | Number) Block } Repeat { silent<"repeat"> (Word | Number) Block }
// repeat 4 { thing () }
Each { silent<"each"> simple "do" (Fn_Clause | Fn_Clauses) } Each { silent<"each"> simple "do" (Fn_Clause | Fn_Clauses) }
// each [1, 2, 3] do (n) -> thing
Recur { silent<"recur"> Args } Recur { silent<"recur"> Args }
Loop { silent<"loop"> simple "with" (Fn_Clause | Fn_Clauses) } Loop { silent<"loop"> simple "with" (Fn_Clause | Fn_Clauses) }
@ -287,6 +291,6 @@ Nil { silent<"nil"> }
float { ("0" | int ) "." $[0-9]+} float { ("0" | int ) "." $[0-9]+}
Number { "-"? (int | float) } Number { "-"? (int | float) }
separator { $[,\n] } separator { $[,\n] }
terminator { $[;\n] | @eof } terminator { $[;\n] }
newline { "\n" } newline { "\n" }
} }

View File

@ -11,7 +11,7 @@
"@lezer/lr": "^1.0.0" "@lezer/lr": "^1.0.0"
}, },
"scripts": { "scripts": {
"prepare": "lezer-generator ludus.grammar -o parser.js" "build": "lezer-generator ludus.grammar -o parser.js"
}, },
"author": "Scott Richmond", "author": "Scott Richmond",
"license": "MIT" "license": "MIT"

View File

@ -10,7 +10,7 @@ export const parser = LRParser.deserialize({
maxTerm: 120, maxTerm: 120,
skippedNodes: [0], skippedNodes: [0],
repeatNodeCount: 16, repeatNodeCount: 16,
tokenData: "-j~RnXY#PYZ#_]^#Ppq#Prs#hst%Utu%avw%lxy&Tyz&Y|}&_}!O&d!O!P'h!Q!R&p!R!['W![!]'y!]!^(O!_!`(T!b!c(Y!}#O(e#P#Q(j#R#S(o#T#W(t#W#X)`#X#k(t#k#l*n#l#o(t#o#p-`#q#r-e~~(O~#UR!d~XY#P]^#Ppq#PV#hO#WS!pQ!fP~#kVOr#hrs$Qs#O#h#O#P$V#P;'S#h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;=`$`;=`O#e~$cWOr#ers#}s#O#e#O#P$S#P;'S#e;'S;=`${;=`<%l#e<%lO#e~%OP;=`<%l#e~%UP#o#p%X~%^O!x~~%aP#o#p%d~%iO!v~~%nS!e~OY%iZ;'S%i;'S;=`%z<%lO%i~%}P;=`<%l%i~&VO!o~~&[O!q~Q&aO!pQ~&dR!Q!R&m!R!['T!`!a'`~&rPW~!O!P&u~&xP!Q![&{~'QPW~!Q![&{~'YQW~!O!P&u!Q!['T~'eO#R~~'hP!O!P'k~'nP!O!P'q~'vO!t~~'{O!m~P(QO!fP~(VO#[~~(YP#o#p(]~(bO!{~~(gO!r~~(lO!u~~(qO#P~V(vVRVqr(q}!O(q!P!Q(q!a!b(q!c!}(q#R#S(q#T#o(q_)bXRVqr(q}!O(q!P!Q(q!a!b(q!c!}(q#R#S(q#T#c(q#c#d)}#d#o(q_*UV#eWRVqr(q}!O(q!P!Q(q!a!b(q!c!}(q#R#S(q#T#o(q_*pXRVqr(q}!O(q!P!Q(q!a!b(q!c!}(q#R#S(q#T#](q#]#^+]#^#o(q_+bXRVqr(q}!O(q!P!Q(q!a!b(q!c!}(q#R#S(q#T#h(q#h#i+}#i#o(q_,SXRVqr(q}!O(q!P!Q(q!a!b(q!c!}(q#R#S(q#T#[(q#[#],o#]#o(q_,vV#bWRVqr(q}!O(q!P!Q(q!a!b(q!c!}(q#R#S(q#T#o(q~-bO#U~~-gO!w~",
tokenizers: [0, 1, 2, 3], tokenizers: [0, 1, 2, 3],
topRules: {"Script":[0,1]}, topRules: {"Script":[0,1]},
specialized: [{term: 3, get: (value) => spec_Word[value] || -1}], specialized: [{term: 3, get: (value) => spec_Word[value] || -1}],

29
test.js
View File

@ -2,12 +2,31 @@ import {parser} from "./parser.js"
const source = ` const source = `
if foo if foo
then do abcd then bar else asdf
> xyz
>
else asdf
` `
const parse = (source) => parser.parse(source.concat("\n")) const parse = (source) => parser.parse(source.concat("\n"))
console.log(parse(source).toString()) const tree = parse(source)
const cursor = tree.cursor()
const report = (out) => {
console.log(out);
return true;
}
const visit = (node) => {
switch (node.type.name) {
case "Script": return report("Starting Script");
case "If": return report("Starting If");
case "Word": return report(node.)
}
}
cursor.iterate(
(node) => (console.log("Entering", node.type.name), true),
(node) => (console.log("Leaving", node.type.name))
)