Comparing version 0.6.2 to 0.7.0
{ | ||
"name": "pegjs", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"description": "Parser generator for JavaScript", | ||
@@ -18,8 +18,8 @@ "homepage": "http://pegjs.majda.cz/", | ||
"devDependencies": { | ||
"jake": ">= 0.1.10", | ||
"uglify-js": ">= 0.0.5" | ||
"uglify-js": ">= 1.2.4", | ||
"jshint": ">= 0.5.5" | ||
}, | ||
"engines": { | ||
"node": ">= 0.4.4" | ||
"node": ">= 0.6.6" | ||
} | ||
} | ||
} |
@@ -23,13 +23,17 @@ PEG.js | ||
### Command Line / Server-side | ||
### Node.js | ||
To use command-line version, install [Node.js](http://nodejs.org/) and [npm](http://npmjs.org/) first. You can then install PEG.js: | ||
To use the `pegjs` command, install PEG.js globally: | ||
$ npm install -g pegjs | ||
To use the JavaScript API, install PEG.js locally: | ||
$ npm install pegjs | ||
Once installed, you can use the `pegjs` command to generate your parser from a grammar and use the JavaScript API from Node.js. | ||
If you need both the `pegjs` command and the JavaScript API, install PEG.js both ways. | ||
### Browser | ||
[Download](http://pegjs.majda.cz/#download) the PEG.js library (regular or minified version) and include it in your web page or application using the `<script>` tag. | ||
[Download](http://pegjs.majda.cz/#download) the PEG.js library (regular or minified version). | ||
@@ -55,2 +59,7 @@ Generating a Parser | ||
You can tweak the generated parser with two options: | ||
* `--cache` — makes the parser cache results, avoiding exponential parsing time in pathological cases but making the parser slower | ||
* `--track-line-and-column` — makes the parser track line and column (available as `line` and `column` variables in the actions and predicates) | ||
### JavaScript API | ||
@@ -62,3 +71,3 @@ | ||
In browser, include the PEG.js library in your web page or application using the `<script>` tag. The API will be available through the `PEG` global object. | ||
In browser, include the PEG.js library in your web page or application using the `<script>` tag. The API will be available in the `PEG` global object. | ||
@@ -73,6 +82,11 @@ To generate a parser, call the `PEG.buildParser` method and pass your grammar as a parameter: | ||
You can tweak the generated parser by passing a second parameter with an options object to `PEG.buildParser`. The following options are supported: | ||
* `cache` — if `true`, makes the parser cache results, avoiding exponential parsing time in pathological cases but making the parser slower (default: `false`) | ||
* `trackLineAndColumn` — if `true`, makes the parser track line and column (available as `line` and `column` variables in the actions and predicates) (default: `false`) | ||
Using the Parser | ||
---------------- | ||
Using the generated parser is simple — just call its `parse` method and pass an input string as a parameter. The method will return a parse result (the exact value depends on the grammar used to build the parser) or throw an exception if the input is invalid. The exception will contain `line`, `column` and `message` properties with more details about the error. | ||
Using the generated parser is simple — just call its `parse` method and pass an input string as a parameter. The method will return a parse result (the exact value depends on the grammar used to build the parser) or throw an exception if the input is invalid. The exception will contain `offset`, `line`, `column`, `expected`, `found` and `message` properties with more details about the error. | ||
@@ -135,3 +149,3 @@ parser.parse("abba"); // returns ["a", "b", "b", "a"] | ||
Match exact literal string and return it. The string syntax is the same as in JavaScript. | ||
Match exact literal string and return it. The string syntax is the same as in JavaScript. Appending `i` right after the literal makes the match case-insensitive. | ||
@@ -144,3 +158,3 @@ #### . | ||
Match one character from a set and return it as a string. The characters in the list can be escaped in exactly the same way as in JavaScript string. The list of characters can also contain ranges (e.g. `[a-z]` means “all lowercase letters”). Preceding the characters with `^` inverts the matched set (e.g. `[^a-z]` means “all character but lowercase letters”). | ||
Match one character from a set and return it as a string. The characters in the list can be escaped in exactly the same way as in JavaScript string. The list of characters can also contain ranges (e.g. `[a-z]` means “all lowercase letters”). Preceding the characters with `^` inverts the matched set (e.g. `[^a-z]` means “all character but lowercase letters”). Appending `i` right after the right bracket makes the match case-insensitive. | ||
@@ -177,12 +191,20 @@ #### *rule* | ||
The predicate is a piece of JavaScript code that is executed as if it was inside a function. It should return some JavaScript value using the `return` statement. If the returned value evaluates to `true` in boolean context, just return an empty string and do not advance the parser position; otherwise consider the match failed. | ||
The predicate is a piece of JavaScript code that is executed as if it was inside a function. It gets the match results of labeled expressions in preceding expression as its arguments. It should return some JavaScript value using the `return` statement. If the returned value evaluates to `true` in boolean context, just return an empty string and do not advance the parser position; otherwise consider the match failed. | ||
The code inside the predicate has access to all variables and functions defined in the initializer at the beginning of the grammar. Curly braces in the predicate code must be balanced. | ||
The code inside the predicate can access all variables and functions defined in the initializer at the beginning of the grammar. | ||
The code inside the predicate can also access the current parse position using the `offset` variable. It is a zero-based character index into the input string. If the `trackLineAndColumn` option was set to `true` when the parser was generated (or `--track-line-and-column` was used on the command line), the code can also access the current line and column using the `line` and `column` variables. Both are one-based indexes. | ||
Note that curly braces in the predicate code must be balanced. | ||
#### ! { *predicate* } | ||
The predicate is a piece of JavaScript code that is executed as if it was inside a function. It should return some JavaScript value using the `return` statement. If the returned value evaluates to `false` in boolean context, just return an empty string and do not advance the parser position; otherwise consider the match failed. | ||
The predicate is a piece of JavaScript code that is executed as if it was inside a function. It gets the match results of labeled expressions in preceding expression as its arguments. It should return some JavaScript value using the `return` statement. If the returned value evaluates to `false` in boolean context, just return an empty string and do not advance the parser position; otherwise consider the match failed. | ||
The code inside the predicate has access to all variables and functions defined in the initializer at the beginning of the grammar. Curly braces in the predicate code must be balanced. | ||
The code inside the predicate can access all variables and functions defined in the initializer at the beginning of the grammar. | ||
The code inside the predicate can also access the current parse position using the `offset` variable. It is a zero-based character index into the input string. If the `trackLineAndColumn` option was set to `true` when the parser was generated (or `--track-line-and-column` was used on the command line), the code can also access the current line and column using the `line` and `column` variables. Both are one-based indexes. | ||
Note that curly braces in the predicate code must be balanced. | ||
#### *label* : *expression* | ||
@@ -204,4 +226,8 @@ | ||
The code inside the action has access to all variables and functions defined in the initializer at the beginning of the grammar. Curly braces in the action code must be balanced. | ||
The code inside the action can access all variables and functions defined in the initializer at the beginning of the grammar. Curly braces in the action code must be balanced. | ||
The code inside the action can also access the parse position at the beginning of the action's expression using the `offset` variable. It is a zero-based character index into the input string. If the `trackLineAndColumn` option was set to `true` when the parser was generated (or `--track-line-and-column` was used on the command line), the code can also access the line and column at the beginning of the action's expression using the `line` and `column` variables. Both are one-based indexes. | ||
Note that curly braces in the action code must be balanced. | ||
#### *expression<sub>1</sub>* / *expression<sub>2</sub>* / ... / *expression<sub>n</sub>* | ||
@@ -216,4 +242,4 @@ | ||
* Node.js 0.4.4+ | ||
* IE 6+ | ||
* Node.js 0.6.6+ | ||
* IE 8+ | ||
* Firefox | ||
@@ -233,4 +259,4 @@ * Chrome | ||
PEG.js is developed by [David Majda](http://majda.cz/) ([@dmajda](http://twitter.com/dmajda)). You are welcome to contribute code. Unless your contribution is really trivial you should get in touch with me first — this can prevent wasted effort on both sides. You can send code both as patch or GitHub pull request. | ||
PEG.js is developed by [David Majda](http://majda.cz/) ([@dmajda](http://twitter.com/dmajda)). You are welcome to contribute code. Unless your contribution is really trivial you should get in touch with me first — this can prevent wasted effort on both sides. You can send code both as a patch or a GitHub pull request. | ||
Note that PEG.js is still very much work in progress. There are no compatibility guarantees until version 1.0. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
253
0
280017
4227
1