Created
July 12, 2013 17:46
-
-
Save rauhryan/5986322 to your computer and use it in GitHub Desktop.
# Jison
Your friendly JavaScript parser generator! > http://jison.org
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
// mygenerator.js | |
var Parser = require("jison").Parser; | |
// a grammar in JSON | |
var grammar = { | |
"lex": { | |
"rules": [ | |
["\\s+", "/* skip whitespace */"], | |
["[a-f0-9]+", "return 'HEX';"] | |
] | |
}, | |
"bnf": { | |
"hex_strings" :[ "hex_strings HEX", | |
"HEX" ] | |
} | |
}; | |
// `grammar` can also be a string that uses jison's grammar format | |
var parser = new Parser(grammar); | |
// generate source, ready to be written to disk | |
var parserSource = parser.generate(); | |
// you can also use the parser directly from memory | |
// returns true | |
parser.parse("adfe34bc e82a"); | |
// throws lexical error | |
parser.parse("adfe34bc zxg"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment