Created
March 21, 2016 21:55
-
-
Save RangerMauve/493e510d78df8496f46b to your computer and use it in GitHub Desktop.
S Expressions in PEG.js
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
( | |
( | |
[] 1337 "cats" dogs) | |
(+ 1 0xFF) | |
) |
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
expression = whitespace? "(" whitespace? atoms:atom* ")" whitespace? {return {type:"expression",value:atoms}} | |
atom = content:(string / number / identifier / expression) whitespace? {return {type:"atom",value:content}} | |
string = '"' chars:[^"]* '"' {return {type:"string",value:chars.join("")}} | |
number = hex / decimal | |
decimal = digits:[0-9]+ {return {type:"number",base: 10, value:parseInt(digits.join(""),10)};} | |
hex = "0x" digits:[0-9A-Fa-f]+ {return {type:"number",base: 16, value:parseInt(digits.join(""),16)};} | |
identifier = content:[^ \t\n\r()]+ {return {type:"identifier",value:content.join("")}} | |
whitespace | |
= [ \t\n\r]* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment