Created
February 8, 2019 05:41
-
-
Save ponyatov/5ea59887404a57e9ec9cccac1fe20c03 to your computer and use it in GitHub Desktop.
ESD parser grammar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
splitter "parse words divided by spaces" | |
= _? x:(y:word _? { return y } )* { return x } | |
word | |
= number | |
/ w:[^ \t\n\r]+ { return w.join('') } | |
_ "space" | |
= s:[ \t\n\r]+ { return s.join('') } | |
number | |
= hex / bin | |
/ e:exponent { return parseFloat(e) } | |
/ f:float { return parseFloat(f) } | |
/ n:integer { return parseInt(n) } | |
hex = "0x" h:[0-9a-fA-F]+ { return parseInt(h.join(''),0x10) } | |
bin = "0b" b:[01]+ { return parseInt(b.join(''),0x02) } | |
integer = s:[\+\-]? n:[0-9]+ { n = n.join(''); if (s) n=s+n; return n } | |
float = n:integer '.' f:[0-9]* { return n+'.'+f.join('') } | |
exponent = a:float [eE] b:integer { return a+'e'+b } | |
/ a:integer [eE] b:integer { return a+'e'+b } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment