Skip to content

Commit

Permalink
Merge pull request #1 from zaach/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
benbenbenbenbenben authored Sep 17, 2016
2 parents a9e58a6 + 7653842 commit 43cbeea
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 40 deletions.
65 changes: 33 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,39 @@ Usage from a CommonJS module

You can generate parsers programatically from JavaScript as well. Assuming Jison is in your commonjs environment's load path:

// 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");

```javascript
// 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");
```

More Documentation
------------------
Expand Down
2 changes: 2 additions & 0 deletions examples/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ exports.grammar = {

"bnf": {
"JSONString": [ "STRING" ],

"JSONNullLiteral": [ "NULL" ],

"JSONNumber": [ "NUMBER" ],

Expand Down
10 changes: 3 additions & 7 deletions lib/jison.js
Original file line number Diff line number Diff line change
Expand Up @@ -1359,13 +1359,9 @@ function parseError (str, hash) {
if (hash.recoverable) {
this.trace(str);
} else {
function _parseError (msg, hash) {
this.message = msg;
this.hash = hash;
}
_parseError.prototype = new Error();

throw new _parseError(str, hash);
var error = new Error(str);
error.hash = hash;
throw error;
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Zach Carter <[email protected]> (http://zaa.ch)",
"name": "jison",
"description": "A parser generator with Bison's API",
"version": "0.4.15",
"version": "0.4.17",
"license": "MIT",
"keywords": [
"jison",
Expand Down

0 comments on commit 43cbeea

Please sign in to comment.