Start work; smol parser

This commit is contained in:
Scott Richmond 2023-11-26 13:32:25 -05:00
parent 376c39f5ee
commit f1554ef2e3
4 changed files with 34 additions and 19 deletions

View File

@ -1,10 +1,20 @@
@top File { (Identifier | Number | String)+ } @top Script { terminator* line+ }
@skip { space } @skip { space | comment }
line { expression terminator+ }
expression { Boolean | Nil | String | Number }
@tokens { @tokens {
space { @whitespace+ } space { $[ \t\r]+ }
Identifier { $[A-Za-z_]+ } comment { "&" ![\n]* }
Number { $[0-9]+ } Boolean { "true" | "false" }
String { '"' !["]* '"' } Nil { "nil" }
String { '"' (!["\\] | "\\" _)* '"' }
int { $[1-9]$[0-9]* }
float { ("0" | int ) $[0.9]+}
Number { int | float }
separator { $[,\n] }
terminator { $[;\n] }
} }

View File

@ -2,15 +2,15 @@
import {LRParser} from "@lezer/lr" import {LRParser} from "@lezer/lr"
export const parser = LRParser.deserialize({ export const parser = LRParser.deserialize({
version: 14, version: 14,
states: "hOVQPOOOOQO'#Ca'#CaQVQPOOOOQO-E6_-E6_", states: "!WOYQPOOOOQO'#Cb'#CbOYQPOOOOQO'#Ci'#CiQkQPOOOfQPO'#CcOOQO-E6`-E6`OOQO-E6a-E6aOyQPO,58}",
stateData: "b~OWOS~OQPORPOSPO~O", stateData: "!_~OYOSZOS~OQRORROSROTRO[PO~OQRORROSROTRO~O[POQVaRVaSVaTVaWVa~O",
goto: "]UPPPPPVQQORRQ", goto: "u^PPPPPP_iPPPPPpQQOSUQWRWTSSOQRVSVTOQS",
nodeNames: "⚠ File Identifier Number String", nodeNames: "⚠ Script Boolean Nil String Number",
maxTerm: 8, maxTerm: 13,
skippedNodes: [0], skippedNodes: [0],
repeatNodeCount: 1, repeatNodeCount: 2,
tokenData: "#z~R_X^!Qpq!Qrs!u!Q![#d!c!}#l#R#S#l#T#o#l#y#z!Q$f$g!Q#BY#BZ!Q$IS$I_!Q$I|$JO!Q$JT$JU!Q$KV$KW!Q&FU&FV!Q~!VYW~X^!Qpq!Q#y#z!Q$f$g!Q#BY#BZ!Q$IS$I_!Q$I|$JO!Q$JT$JU!Q$KV$KW!Q&FU&FV!Q~!xTOr!urs#Xs;'S!u;'S;=`#^<%lO!u~#^OS~~#aP;=`<%l!u~#iPR~!Q![#d~#qRQ~!c!}#l#R#S#l#T#o#l", tokenData: "&j~R[XYwYZ!V]^wpqwrs![vw#x!Q!R$a!R![${!]!^!V#Y#Z%^#b#c%{#h#i&^~|RY~XYw]^wpqw~![O[~~!_VOr![rs!ts#O![#O#P!y#P;'S![;'S;=`#r<%lO![~!yOS~~!|RO;'S![;'S;=`#V;=`O![~#YWOr![rs!ts#O![#O#P!y#P;'S![;'S;=`#r;=`<%l![<%lO![~#uP;=`<%l![~#}SZ~OY#xZ;'S#x;'S;=`$Z<%lO#x~$^P;=`<%l#x~$dR!O!P$m!Q!R$m!Z![$m~$rRT~!O!P$m!Q!R$m!Z![$m~%QST~!O!P$m!Q!R${!R!Z${!Z![${~%aP#T#U%d~%gP#`#a%j~%mP#g#h%p~%sP#X#Y%v~%{OQ~~&OP#]#^&R~&UP#`#a&X~&^OR~~&aP#f#g&d~&gP#i#j%p",
tokenizers: [0], tokenizers: [0],
topRules: {"File":[0,1]}, topRules: {"Script":[0,1]},
tokenPrec: 0 tokenPrec: 0
}) })

View File

@ -1,6 +1,7 @@
// This file was generated by lezer-generator. You probably shouldn't edit it. // This file was generated by lezer-generator. You probably shouldn't edit it.
export const export const
File = 1, Script = 1,
Identifier = 2, Boolean = 2,
Number = 3, Nil = 3,
String = 4 String = 4,
Number = 5

View File

@ -1,3 +1,7 @@
import {parser} from "./parser.js" import {parser} from "./parser.js"
console.log(parser.parse('one 2 "three"').toString()) const source = "nil; true; false; 12; \"foo\""
const parse = (source) => parser.parse(source.concat("\n"))
console.log(parse(source).toString())