Skip to content

Commit e3e3c39

Browse files
committed
Merge branch 'release/0.4.0'. This closes #3.
2 parents dd617ef + 52447a5 commit e3e3c39

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,18 @@ Then you only need to write: `require("./parser.pegjs")`.
4444

4545
You can pass options to PEG.js as [query parameters](http://webpack.github.io/docs/using-loaders.html#query-parameters). The following options are supported:
4646

47-
* `cache`if `true`, makes the parser cache results, avoiding exponential
47+
* `cache`If `true`, makes the parser cache results, avoiding exponential
4848
parsing time in pathological cases but making the parser slower (default:
49-
`false`)
49+
`false`).
5050

51-
* `optimize` - whether to optimize the built parser either for `speed` or
52-
`size` (default: `speed`)
51+
* `optimize` - Whether to optimize the built parser either for `speed` or
52+
`size` (default: `speed`).
53+
54+
* `allowedStartRules` - The rules the built parser will be allowed to start
55+
parsing from (default: the first rule in the grammar).
56+
57+
* `trace` - If `true`, the tracing support in the built parser is enabled
58+
(default: `false`).
5359

5460
``` js
5561
module.exports = {
@@ -58,7 +64,7 @@ module.exports = {
5864
loaders: [
5965
{
6066
test: /\.pegjs$/,
61-
loader: 'pegjs-loader?cache=true&optimize=size'
67+
loader: 'pegjs-loader?cache=true&optimize=size&allowedStartRules[]=RuleA,allowedStartRules[]=RuleB&trace=true'
6268
}
6369
]
6470
}
@@ -74,6 +80,7 @@ Every release, along with the migration instructions, if any, is documented on t
7480

7581
* [Victor Homyakov](https://github.com/victor-homyakov) for the propagation of the `cache` option.
7682
* [VladimirTechMan](https://github.com/VladimirTechMan) for the propagation of the `optimize` option.
83+
* [ragtime](https://github.com/ragtime) for the propagation of the `allowedStartRules` and `trace` options.
7784

7885
## License
7986

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pegjs-loader",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "PEG.js loader for webpack",
55
"authors": [
66
"Andrey Subbotin <[email protected]> (https://github.com/eploko)",

src/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,27 @@ export default function loader(source) {
99
const query = loaderUtils.parseQuery(this.query);
1010
const cacheParserResults = !!query.cache;
1111
const optimizeParser = query.optimize || 'speed';
12+
const trace = !!query.trace;
13+
14+
let allowedStartRules;
15+
if (typeof query.allowedStartRules === 'string') {
16+
allowedStartRules = [ query.allowedStartRules ];
17+
} else if (Array.isArray(query.allowedStartRules)) {
18+
allowedStartRules = query.allowedStartRules;
19+
} else {
20+
allowedStartRules = [];
21+
}
1222

1323
// Description of PEG.js options: https://github.com/pegjs/pegjs#javascript-api
1424
const pegOptions = {
1525
output: 'source',
1626
cache: cacheParserResults,
1727
optimize: optimizeParser,
28+
trace: trace,
1829
};
30+
if (allowedStartRules.length > 0) {
31+
pegOptions.allowedStartRules = allowedStartRules;
32+
}
1933

2034
return `module.exports = ${pegjs.buildParser(source, pegOptions)};`;
2135
}

0 commit comments

Comments
 (0)