wikipeg 2.0.6 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.6
1
+ 4.0.0
@@ -225,6 +225,11 @@ let javascript = {
225
225
  if (opts.params.length) {
226
226
  keyParts = keyParts.concat(opts.params);
227
227
  }
228
+ let storeRefs = opts.storeRefs.filter(function(part) {
229
+ return part !== '';
230
+ }).map(function(part) {
231
+ return ' ' + part;
232
+ }).join('\n');
228
233
  return {
229
234
  start: [
230
235
  `var key = [${keyParts.join(',')}].map(String).join(":");`,
@@ -241,7 +246,7 @@ let javascript = {
241
246
  ' nextPos: peg$currPos, ',
242
247
  ` result: ${opts.result}, `,
243
248
  '};',
244
- opts.storeRefs
249
+ storeRefs
245
250
  ].join('\n')
246
251
  };
247
252
  },
@@ -251,7 +256,8 @@ let javascript = {
251
256
  return ` if (cached.hasOwnProperty(${encName})) param_${name}.value = cached.$${name};`;
252
257
  },
253
258
 
254
- cacheStoreRef(name) {
259
+ cacheStoreRef(name, store) {
260
+ if (!store) return '';
255
261
  return `if (saved_${name} !== param_${name}.value) cached.$${name} = param_${name}.value;`;
256
262
  },
257
263
 
@@ -424,33 +424,38 @@ let php = {
424
424
  if (opts.params.length) {
425
425
  keyParts = keyParts.concat(opts.params);
426
426
  }
427
+ let storeRefs = opts.storeRefs.map(function(part) {
428
+ return ' ' + part;
429
+ }).join(',\n');
427
430
  return {
428
431
  start: [
429
432
  `$key = json_encode([${keyParts.join(',')}]);`,
430
433
  `$cached = $this->cache[$key] ?? null;`,
431
434
  `if ($cached) {`,
432
- ` $this->currPos = $cached['nextPos'];`,
435
+ ` $this->currPos = $cached->nextPos;`,
433
436
  opts.loadRefs,
434
- ` return $cached['result'];`,
437
+ ` return $cached->result;`,
435
438
  '}',
436
439
  opts.saveRefs,
437
440
  ].join('\n'),
438
441
  store: [
439
- `$cached = ['nextPos' => $this->currPos, 'result' => ${opts.result}];`,
440
- opts.storeRefs,
441
- `$this->cache[$key] = $cached;`
442
+ `$this->cache[$key] = new ${opts.className}CacheEntry(`,
443
+ ' $this->currPos,',
444
+ ` ${opts.result + (opts.storeRefs.length > 0 ? ',' : '')}`,
445
+ storeRefs,
446
+ `);`
442
447
  ].join('\n')
443
448
  };
444
449
  },
445
450
 
446
451
  cacheLoadRef(name) {
447
- let encName = php.stringify('$' + name);
448
- return `if (array_key_exists(${encName}, $cached)) $param_${name} = $cached[${encName}];`;
452
+ return `if ($cached->${name} !== self::$UNDEFINED) { $param_${name} = $cached->${name}; }`;
449
453
  },
450
454
 
451
- cacheStoreRef(name) {
452
- let encName = php.stringify('$' + name);
453
- return `if ($saved_${name} !== $param_${name}) $cached[${encName}] = $param_${name};`;
455
+ cacheStoreRef(name, store) {
456
+ return store ?
457
+ `$saved_${name} !== $param_${name} ? $param_${name} : self::$UNDEFINED` :
458
+ 'self::$UNDEFINED';
454
459
  },
455
460
 
456
461
  /**
@@ -80,6 +80,28 @@ function generateJavascript(ast, options) {
80
80
  language = js;
81
81
  }
82
82
 
83
+ var className = options.className || 'PEGParser';
84
+ var namespace = '';
85
+ var matches = className.match(/^(.*)\\([^\\]*)$/);
86
+ if (matches) {
87
+ className = matches[2];
88
+ namespace = `namespace ${matches[1]};`;
89
+ }
90
+
91
+ var refsSet = {};
92
+ var getRefs = visitor.build({
93
+ rule_ref: function(node) {
94
+ for (let i = 0; i < node.assignments.length; i++) {
95
+ let assignment = node.assignments[i];
96
+ if (assignment.isref) {
97
+ refsSet[assignment.name] = true;
98
+ }
99
+ }
100
+ }
101
+ });
102
+ getRefs(ast);
103
+ var references = Object.keys(refsSet);
104
+
83
105
  /**
84
106
  * The default init cache hook
85
107
  */
@@ -91,7 +113,6 @@ function generateJavascript(ast, options) {
91
113
  var generateCacheRule = language.generateCacheRule;
92
114
 
93
115
  function indent2(code) { return code.replace(/^(.+)$/gm, ' $1'); }
94
- function indent4(code) { return code.replace(/^(.+)$/gm, ' $1'); }
95
116
 
96
117
  /**
97
118
  * The Context class.
@@ -749,21 +770,23 @@ function generateJavascript(ast, options) {
749
770
  block.push(language.cacheLoadRef(name));
750
771
  }
751
772
  }
752
- return indent4(block.join('\n'));
773
+ return indent2(block.join('\n'));
753
774
  }
754
775
 
755
776
  /**
756
- * Get a block which determines which refs have changed, if any. Any changed
757
- * refs are stored in the `cached` object.
777
+ * Get the list of expressions or statements returned by cacheStoreRef() for
778
+ * refs which may have changed.
758
779
  */
759
780
  function getCacheStoreRefs(rule) {
760
- var block = [];
781
+ var store = {};
761
782
  for (let name in rule.passedParams) {
762
783
  if (rule.passedParams[name].type === 'reference') {
763
- block.push(language.cacheStoreRef(name));
784
+ store[name] = true;
764
785
  }
765
786
  }
766
- return indent2(block.join('\n'));
787
+ return references.map(function(name) {
788
+ return language.cacheStoreRef(name, store[name]);
789
+ });
767
790
  }
768
791
 
769
792
  /**
@@ -774,10 +797,10 @@ function generateJavascript(ast, options) {
774
797
  var parts = [];
775
798
  for (let name in rule.passedParams) {
776
799
  if (rule.passedParams[name].type === 'reference') {
777
- parts.push(indent2(language.cacheSaveRef(name)));
800
+ parts.push(language.cacheSaveRef(name));
778
801
  }
779
802
  }
780
- return indent2(parts.join('\n'));
803
+ return parts.join('\n');
781
804
  }
782
805
 
783
806
  function expandTemplate(template, vars) {
@@ -848,6 +871,7 @@ function generateJavascript(ast, options) {
848
871
  loadRefs: getCacheLoadRefs(node),
849
872
  saveRefs: getCacheSaveRefs(node),
850
873
  storeRefs: getCacheStoreRefs(node),
874
+ className: className,
851
875
  });
852
876
  body.push(cacheBits.start);
853
877
  }
@@ -1356,15 +1380,8 @@ function generateJavascript(ast, options) {
1356
1380
  }
1357
1381
  templateVars['/*GENERATED*/'] = generated.join('\n');
1358
1382
 
1359
- var className = options.className || 'PEGParser';
1360
- var matches = className.match(/^(.*)\\([^\\]*)$/);
1361
- if (matches) {
1362
- templateVars['CLASS_NAME'] = matches[2];
1363
- templateVars['/*NAMESPACE*/'] = `namespace ${matches[1]};`;
1364
- } else {
1365
- templateVars['CLASS_NAME'] = className;
1366
- templateVars['/*NAMESPACE*/'] = '';
1367
- }
1383
+ templateVars['CLASS_NAME'] = className;
1384
+ templateVars['/*NAMESPACE*/'] = namespace;
1368
1385
 
1369
1386
  var cacheInitCode = '';
1370
1387
  var cacheInitHook;
@@ -1390,6 +1407,22 @@ function generateJavascript(ast, options) {
1390
1407
  var template;
1391
1408
  if (options.language === 'php') {
1392
1409
  template = fs.readFileSync(__dirname + '/../../runtime/template.php', 'utf8');
1410
+ if (options.cache) {
1411
+ templateVars['/*CACHE_ENTRY_BEGIN*/'] = '';
1412
+ templateVars['/*CACHE_ENTRY_END*/'] = '';
1413
+ templateVars['/*CACHE_ENTRY_DECLARE*/'] = '';
1414
+ templateVars['/*CACHE_ENTRY_ARGS*/'] = '';
1415
+ templateVars['/*CACHE_ENTRY_INIT*/'] = '';
1416
+ references.forEach(function(name) {
1417
+ templateVars['/*CACHE_ENTRY_DECLARE*/'] += `\tpublic $${name};\n`;
1418
+ templateVars['/*CACHE_ENTRY_ARGS*/'] += `, $${name}`;
1419
+ templateVars['/*CACHE_ENTRY_INIT*/'] += `\t\t$this->${name} = $${name};\n`;
1420
+ });
1421
+ } else {
1422
+ template = template.replace(
1423
+ /\/\*CACHE_ENTRY_BEGIN\*\/[^]+?\/\*CACHE_ENTRY_END\*\//, ''
1424
+ );
1425
+ }
1393
1426
  } else {
1394
1427
  template = fs.readFileSync(__dirname + '/../../runtime/template.js', 'utf8');
1395
1428
  }
package/lib/parser.js CHANGED
@@ -5,6 +5,8 @@ module.exports = ( function () {
5
5
  * Generated by WikiPEG
6
6
  */
7
7
 
8
+
9
+
8
10
  function peg$subclass(child, parent) {
9
11
  function ctor() { this.constructor = child; }
10
12
  ctor.prototype = parent.prototype;
package/lib/peg.js CHANGED
@@ -5,7 +5,7 @@ var arrays = require("./utils/arrays"),
5
5
 
6
6
  var PEG = {
7
7
  /* WikiPEG version (uses semantic versioning). */
8
- VERSION: "2.0.6",
8
+ VERSION: "4.0.0",
9
9
 
10
10
  GrammarError: require("./grammar-error"),
11
11
  parser: require("./parser"),
@@ -4,6 +4,20 @@
4
4
 
5
5
  /*INITIALIZER0*/
6
6
 
7
+ /*CACHE_ENTRY_BEGIN*/
8
+ class CLASS_NAMECacheEntry {
9
+ public $nextPos;
10
+ public $result;
11
+ /*CACHE_ENTRY_DECLARE*/
12
+
13
+ public function __construct( $nextPos, $result/*CACHE_ENTRY_ARGS*/ ) {
14
+ $this->nextPos = $nextPos;
15
+ $this->result = $result;
16
+ /*CACHE_ENTRY_INIT*/
17
+ }
18
+ }
19
+ /*CACHE_ENTRY_END*/
20
+
7
21
  class CLASS_NAME extends \Wikimedia\WikiPEG\PEGParserBase {
8
22
  // initializer
9
23
  /*INITIALIZER*/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikipeg",
3
- "version": "2.0.6",
3
+ "version": "4.0.0",
4
4
  "description": "Parser generator for JavaScript and PHP",
5
5
  "license": "MIT",
6
6
  "homepage": "https://gerrit.wikimedia.org/r/plugins/gitiles/wikipeg/",
@@ -40,8 +40,8 @@
40
40
  "url": "https://gerrit.wikimedia.org/r/wikipeg"
41
41
  },
42
42
  "devDependencies": {
43
- "jasmine-node": "3.0.0",
44
- "eslint": "7.16.0"
43
+ "eslint": "8.31.0",
44
+ "jasmine-node": "3.0.0"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">= 6.0.0"
@@ -2,6 +2,8 @@
2
2
 
3
3
  namespace Wikimedia\WikiPEG;
4
4
 
5
+ use InvalidArgumentException;
6
+
5
7
  class DefaultTracer implements Tracer {
6
8
  private $indentLevel = 0;
7
9
 
@@ -23,7 +25,7 @@ class DefaultTracer implements Tracer {
23
25
  break;
24
26
 
25
27
  default:
26
- throw new \Exception( "Invalid event type {$event['type']}" );
28
+ throw new InvalidArgumentException( "Invalid event type {$event['type']}" );
27
29
  }
28
30
  }
29
31
 
@@ -69,6 +71,3 @@ class DefaultTracer implements Tracer {
69
71
  }
70
72
  }
71
73
  }
72
-
73
- // Retain the old namespace for backwards compatibility.
74
- class_alias( DefaultTracer::class, 'WikiPEG\DefaultTracer' );
@@ -45,7 +45,8 @@ class Expectation implements \JsonSerializable {
45
45
  * Emit a JSON serialization similar to JS, for testing
46
46
  * @return array
47
47
  */
48
- public function jsonSerialize() {
48
+ #[\ReturnTypeWillChange]
49
+ public function jsonSerialize(): array {
49
50
  return [
50
51
  'type' => $this->type,
51
52
  'value' => $this->value,
@@ -53,6 +54,3 @@ class Expectation implements \JsonSerializable {
53
54
  ];
54
55
  }
55
56
  }
56
-
57
- // Retain the old namespace for backwards compatibility.
58
- class_alias( Expectation::class, 'WikiPEG\Expectation' );
@@ -4,6 +4,3 @@ namespace Wikimedia\WikiPEG;
4
4
 
5
5
  class InternalError extends \Exception {
6
6
  }
7
-
8
- // Retain the old namespace for backwards compatibility.
9
- class_alias( InternalError::class, 'WikiPEG\InternalError' );
package/src/Location.php CHANGED
@@ -30,7 +30,8 @@ class Location implements \JsonSerializable {
30
30
  * Emit a JSON serialization similar to JS, for testing
31
31
  * @return array
32
32
  */
33
- public function jsonSerialize() {
33
+ #[\ReturnTypeWillChange]
34
+ public function jsonSerialize(): array {
34
35
  return [
35
36
  'offset' => $this->offset,
36
37
  'line' => $this->line,
@@ -38,6 +39,3 @@ class Location implements \JsonSerializable {
38
39
  ];
39
40
  }
40
41
  }
41
-
42
- // Retain the old namespace for backwards compatibility.
43
- class_alias( Location::class, 'WikiPEG\Location' );
@@ -27,16 +27,15 @@ class LocationRange implements \JsonSerializable {
27
27
  return "{$this->start}-{$this->end}";
28
28
  }
29
29
 
30
- /** Emit a JSON serialization similar to JS, for testing
30
+ /**
31
+ * Emit a JSON serialization similar to JS, for testing
31
32
  * @return array
32
33
  */
33
- public function jsonSerialize() {
34
+ #[\ReturnTypeWillChange]
35
+ public function jsonSerialize(): array {
34
36
  return [
35
37
  'start' => $this->start,
36
38
  'end' => $this->end,
37
39
  ];
38
40
  }
39
41
  }
40
-
41
- // Retain the old namespace for backwards compatibility.
42
- class_alias( LocationRange::class, 'WikiPEG\LocationRange' );
@@ -4,6 +4,7 @@ namespace Wikimedia\WikiPEG;
4
4
 
5
5
  abstract class PEGParserBase {
6
6
  protected static $FAILED;
7
+ protected static $UNDEFINED;
7
8
  protected $currPos;
8
9
  protected $savedPos;
9
10
  protected $input;
@@ -29,6 +30,9 @@ abstract class PEGParserBase {
29
30
  if ( !self::$FAILED ) {
30
31
  self::$FAILED = new \stdClass;
31
32
  }
33
+ if ( !self::$UNDEFINED ) {
34
+ self::$UNDEFINED = new \stdClass;
35
+ }
32
36
  }
33
37
 
34
38
  protected function traceCall( $parseFunc, $name, $argNames, $args ) {
@@ -69,6 +73,10 @@ abstract class PEGParserBase {
69
73
  return $this->computeLocation( $this->savedPos, $this->currPos );
70
74
  }
71
75
 
76
+ /**
77
+ * @param string $description
78
+ * @return never
79
+ */
72
80
  protected function expected( $description ) {
73
81
  throw $this->buildException(
74
82
  null,
@@ -78,6 +86,10 @@ abstract class PEGParserBase {
78
86
  );
79
87
  }
80
88
 
89
+ /**
90
+ * @param string $message
91
+ * @return never
92
+ */
81
93
  protected function error( $message ) {
82
94
  throw $this->buildException(
83
95
  $message,
@@ -289,6 +301,3 @@ abstract class PEGParserBase {
289
301
 
290
302
  abstract public function parse( $input, $options = [] );
291
303
  }
292
-
293
- // Retain the old namespace for backwards compatibility.
294
- class_alias( PEGParserBase::class, 'WikiPEG\PEGParserBase' );
@@ -24,7 +24,8 @@ class SyntaxError extends \Exception implements \JsonSerializable {
24
24
  * JSON serialization similar to the JavaScript SyntaxError, for testing
25
25
  * @return array
26
26
  */
27
- public function jsonSerialize() {
27
+ #[\ReturnTypeWillChange]
28
+ public function jsonSerialize(): array {
28
29
  return [
29
30
  'name' => 'SyntaxError',
30
31
  'message' => $this->message,
@@ -34,6 +35,3 @@ class SyntaxError extends \Exception implements \JsonSerializable {
34
35
  ];
35
36
  }
36
37
  }
37
-
38
- // Retain the old namespace for backwards compatibility.
39
- class_alias( SyntaxError::class, 'WikiPEG\SyntaxError' );
package/src/Tracer.php CHANGED
@@ -5,6 +5,3 @@ namespace Wikimedia\WikiPEG;
5
5
  interface Tracer {
6
6
  public function trace( $event );
7
7
  }
8
-
9
- // Retain the old namespace for backwards compatibility.
10
- class_alias( Tracer::class, 'WikiPEG\Tracer' );
package/HISTORY.md DELETED
@@ -1,503 +0,0 @@
1
- # Release History
2
-
3
- ## 2.0.6 (2021-08-07)
4
- * Changed package namespace from WikiPEG to Wikimedia\WikiPEG to match
5
- composer package name. PHP's `class_alias` has been used so that existing
6
- code using the old namespace will continue to work, but this is now
7
- deprecated; it is expected that the next major release of WikiPEG will
8
- remove the aliases.
9
- * Dependency updates.
10
- * Added a place in the template to add header comments.
11
- * Add phpcs and reformat PHP code to MediaWiki codestyle.
12
- * Add phan and fix minor issues.
13
-
14
- ## 2.0.5 (2020-12-17)
15
- * Add PHP 8.0 support plus better CI tests for the PHP code.
16
-
17
- ## 2.0.4 (2020-02-13)
18
- * Add .gitattributes file to reduce downloaded cruft when imported as a
19
- library.
20
- * Fix an obscure bug when the grammar contains cycles.
21
- * Fix DefaultTracer: the location is a LocationRange object now.
22
-
23
- ## 2.0.3 (2019-04-25)
24
- * Move spec to tests/jasmine.
25
- * Fix to error construction.
26
- * Fix expectation sorting.
27
- * Another fix for the ast.initializer format change.
28
- * SyntaxError: correctly call parent constructor.
29
- * Fix encoding of astral plane characters in string literals (PHP backend)
30
- * Fix missing bracket in matchLiteral() (PHP backend)
31
- * Add cross-language testing and fix JS generator bugs identified by it.
32
- * Classes for Location, LocationRange, and Expectation (PHP backend)
33
- * Fix TestRunner error() call
34
- * Simplify loops zero_or_more and one_or_more
35
- * Fix caching of reference rule variables.
36
- * Better default keys for PHP and JS.
37
-
38
- ## 2.0.2 (2019-04-25)
39
- There is no 2.0.2.
40
-
41
- ## 2.0.1 (2019-03-28)
42
- Fix visitor for new multiple initializer feature
43
-
44
- ast.initializer is now the same as before if there are 0 or 1
45
- initializers, and an array if there are 2 or more. Update visitor for
46
- this. During development I initially made it be an array
47
- unconditionally, but I changed it to this more compatible format shortly
48
- before merging in order to make the tests pass, but neglected to update
49
- visitor.
50
-
51
- ## 2.0.0 (2019-03-11)
52
- PHP backend
53
-
54
- Add a PHP code generation mode.
55
-
56
- Mapping overview:
57
-
58
- * File extension .pegphp hints to the binary that PHP is to be generated
59
- * Generated PHP code depends on a PSR-4 runtime library directory. I
60
- used "src" for this, and moved the one file that was there out to
61
- lib/.
62
- * JavaScript's enclosing scope is generally replaced by private and
63
- protected members of the generated class or its parent. For example,
64
- input becomes $this->input.
65
- * PHP's offsets are byte offsets, not UTF-16 offsets as in JS. Rules
66
- such as . (any) return a full UTF-8 character, by means of our own
67
- simple UTF-8 decoder.
68
- * The AST initializer is placed inside the definition of the generated
69
- class, so private function declarations are appropriate, and
70
- $this->input etc. is accessible.
71
- * Actions and semantic predicates become private methods.
72
-
73
- Changes:
74
-
75
- * Add ported examples for arithmetic and CSS
76
- * Remove the ability to run the generator in the browser. It is probably
77
- still possible to use generated parsers in the browser.
78
- * Merge common-helpers, trace-helpers and wrapper.js into a single
79
- template file. The helper files were mostly there to support the
80
- browser mode.
81
- * Give actions a separate namespace from consts, since it's not
82
- convenient in PHP to treat a function as a variable.
83
- * To run the start rule, instead of a hashtable of closures, use a
84
- switch statement. This is simpler and works in both languages. The
85
- hashtable of closures made more sense when it was possible to run
86
- start rules directly, but now we have to supply default parameters for
87
- them, so there was already an extra proxy closure.
88
- * Use template literals throughout, since they look very nice in this
89
- use case and are presumably efficient.
90
- * For streaming mode, use a generator instead of an iterator, since PHP
91
- has generators using similar syntax to ES6, whereas PHP's iterator
92
- syntax is quite different.
93
- * Make the version 2.0.0.
94
-
95
- ## 1.0.2 (2019-03-11)
96
- * Fix file list in package.json and increment version.
97
-
98
- ## 1.0.0 (2019-02-08)
99
- * Call this WikiPEG 1.0.0.
100
- * Rename the binary and NPM project.
101
- * Remove documentation of the browser target since this is
102
- now unmaintained.
103
- * Require Node.js 6+, like Parsoid. The upcoming feature commit will use
104
- some ES6 features.
105
- * Retain the file extension .pegjs for now.
106
-
107
- ## 0.8.0 (December 24, 2013)
108
-
109
- ### Big Changes
110
-
111
- * Completely rewrote the code generator. Among other things, it allows
112
- optimizing generated parsers for parsing speed or code size using the
113
- `optimize` option of the `PEG.buildParser` method or the `--optimize`/`-o`
114
- option on the command-line. All internal identifiers in generated code now
115
- also have a `peg$` prefix to discourage their use and avoid conflicts.
116
- [[#35](https://github.com/dmajda/pegjs/issues/35),
117
- [#92](https://github.com/dmajda/pegjs/issues/92)]
118
-
119
- * Completely redesigned error handling. Instead of returning `null` inside
120
- actions to indicate match failure, new `expected` and `error` functions can
121
- be called to trigger an error. Also, expectation inside the `SyntaxError`
122
- exceptions are now structured to allow easier machine processing.
123
- [[#198](https://github.com/dmajda/pegjs/issues/198)]
124
-
125
- * Implemented a plugin API. The list of plugins to use can be specified using
126
- the `plugins` option of the `PEG.buildParser` method or the `--plugin`
127
- option on the command-line. Also implemented the `--extra-options` and
128
- `--extra-options-file` command-line options, which are mainly useful to pass
129
- additional options to plugins.
130
- [[#106](https://github.com/dmajda/pegjs/issues/106)]
131
-
132
- * Made `offset`, `line` and `column` functions, not variables. They are now
133
- available in all parsers and return lazily-computed position data. Removed
134
- now useless `trackLineAndColumn` option of the `PEG.buildParser` method and
135
- the `--track-line-and-column` option on the command-line.
136
-
137
- * Added a new `text` function. When called inside an action, it returns the
138
- text matched by action's expression.
139
- [[#131](https://github.com/dmajda/pegjs/issues/131)]
140
-
141
- * Added a new `$` operator. It extracts matched strings from expressions.
142
-
143
- * The `?` operator now returns `null` on unsuccessful match.
144
-
145
- * Predicates now always return `undefined`.
146
-
147
- * Replaced the `startRule` parameter of the `parse` method in generated
148
- parsers with more generic `options` parameter. The start rule can now be
149
- specified as the `startRule` option. The `options` parameter can be also
150
- used to pass custom options to the parser because it is visible as the
151
- `options` variable inside parser code.
152
- [[#37](https://github.com/dmajda/pegjs/issues/37)]
153
-
154
- * The list of allowed start rules of a generated parser now has to be
155
- specified explicitly using the `allowedStartRules` option of the
156
- `PEG.buildParser` method or the `--allowed-start-rule` option on the
157
- command-line. This will make certain optimizations like rule inlining easier
158
- in the future.
159
-
160
- * Removed the `toSource` method of generated parsers and introduced a new
161
- `output` option of the `PEG.buildParser` method. It allows callers to
162
- specify whether they want to get back the parser object or its source code.
163
-
164
- * The source code is now a valid npm package. This makes using development
165
- versions easier.
166
- [[#32](https://github.com/dmajda/pegjs/issues/32)]
167
-
168
- * Generated parsers are now ~25% faster and ~62%/~3% smaller (when optimized
169
- for size/speed) than those generated by 0.7.0.
170
-
171
- * Requires Node.js 0.8.0+.
172
-
173
- ### Small Changes
174
-
175
- * `bin/pegjs` now outputs just the parser source if the value of the
176
- `--export-var` option is empty. This makes embedding generated parsers into
177
- other files easier.
178
- [[#143](https://github.com/dmajda/pegjs/issues/143)]
179
-
180
- * Changed the value of the `name` property of `PEG.GrammarError` instances
181
- from “PEG.GrammarError” to just “GrammarError”. This better reflects the
182
- fact that PEG.js can get required with different variable name than `PEG`.
183
-
184
- * Setup prototype chain for `PEG.GrammarError` correctly.
185
-
186
- * Setup prototype chain for `SyntaxError` in generated parsers correctly.
187
-
188
- * Fixed error messages in certain cases with trailing input
189
- [[#119](https://github.com/dmajda/pegjs/issues/119)]
190
-
191
- * Fixed code generated for classes starting with `\^`.
192
- [[#125](https://github.com/dmajda/pegjs/issues/125)]
193
-
194
- * Fixed too eager proxy rules removal.
195
- [[#137](https://github.com/dmajda/pegjs/issues/137)]
196
-
197
- * Added a license to all vendored libraries.
198
- [[#207](https://github.com/dmajda/pegjs/issues/207)]
199
-
200
- * Converted the test suite from QUnit to Jasmine, cleaning it up on the way.
201
-
202
- * Travis CI integration.
203
-
204
- * Various internal code improvements and fixes.
205
-
206
- * Various generated code improvements and fixes.
207
-
208
- * Various example grammar improvements and fixes.
209
-
210
- * Improved `README.md`.
211
-
212
- * Converted `CHANGELOG` to Markdown.
213
-
214
- ## 0.7.0 (April 18, 2012)
215
-
216
- ### Big Changes
217
-
218
- * Added ability to pass options to `PEG.buildParser`.
219
-
220
- * Implemented the `trackLineAndColumn` option for `PEG.buildParser` (together
221
- with the `--track-line-and-column` command-line option). It makes the
222
- generated parser track line and column during parsing. These are made
223
- available inside actions and predicates as `line` and `column` variables.
224
-
225
- * Implemented the `cache` option for `PEG.buildParser` (together with the
226
- `--cache` command-line option). This option enables/disables the results
227
- cache in generated parsers, resulting in dramatic speedup when the cache is
228
- disabled (the default now). The cost is breaking the linear parsing time
229
- guarantee.
230
-
231
- * The current parse position is visible inside actions and predicates as the
232
- `offset` variable.
233
-
234
- * Exceptions thrown by the parser have `offset`, `expected` and `found`
235
- properties containing machine-readable information about the parse failure
236
- (based on a patch by Marcin Stefaniuk).
237
-
238
- * Semantic predicates have access to preceding labels.
239
- [[GH-69](https://github.com/dmajda/pegjs/issues/69)]
240
-
241
- * Implemented case-insensitive literal and class matching.
242
- [[GH-34](https://github.com/dmajda/pegjs/issues/34)]
243
-
244
- * Rewrote the code generator — split some computations into separate passes
245
- and based it on a proper templating system (Codie).
246
-
247
- * Rewrote variable handling in generated parsers in a stack-like fashion,
248
- simplifying the code and making the parsers smaller and faster.
249
-
250
- * Adapted to Node.js 0.6.6+ (no longer supported in older versions).
251
-
252
- * Dropped support for IE < 8.
253
-
254
- * As a result of several optimizations, parsers generated by 0.7.0 are ~6.4
255
- times faster and ~19% smaller than those generated by 0.6.2 (as reported by
256
- `/tools/impact`).
257
-
258
- ### Small Changes
259
-
260
- * Fixed reported error position when part of the input is not consumed.
261
- [[GH-48](https://github.com/dmajda/pegjs/issues/48)]
262
-
263
- * Fixed incorrect disjunction operator in `computeErrorPosition` (original
264
- patch by Wolfgang Kluge).
265
-
266
- * Fixed regexp for detecting command-line options in `/bin/pegjs`.
267
- [[GH-51](https://github.com/dmajda/pegjs/issues/51)]
268
-
269
- * Generate more efficient code for empty literals (original patch by Wolfgang
270
- Kluge).
271
-
272
- * Fixed comment typos (patches by Wolfgang Kluge and Jason Davies).
273
- [[GH-59](https://github.com/dmajda/pegjs/issues/59)]
274
-
275
- * Fixed a typo in JavaScript example grammar.
276
- [[GH-62](https://github.com/dmajda/pegjs/issues/62)]
277
-
278
- * Made copy & paste inclusion of the PEG.js library into another code easier
279
- by changing how the library is exported.
280
-
281
- * Improved the copyright comment and the “Generated by...” header.
282
-
283
- * Replaced `Jakefile` with `Makefile`.
284
-
285
- * Added `make hint` task that checks all JavaScript files using JSHint and
286
- resolved all issues it reported. All JavaScript files and also generated
287
- parsers are JSHint-clean now.
288
-
289
- * Fixed output printed during test failures (expected value was being printed
290
- instead of the actual one). Original patch by Wolfgang Kluge.
291
-
292
- * Added a `/tools/impact` script to measure speed and size impact of commits.
293
-
294
- * Various generated code improvements and fixes.
295
-
296
- * Various internal code improvements and fixes.
297
-
298
- * Improved `README.md`.
299
-
300
- ## 0.6.2 (August 20, 2011)
301
-
302
- ### Small Changes
303
-
304
- * Reset parser position when action returns `null`.
305
-
306
- * Fixed typo in JavaScript example grammar.
307
-
308
- ## 0.6.1 (April 14, 2011)
309
-
310
- ### Small Changes
311
-
312
- * Use `--ascii` option when generating a minified version.
313
-
314
- ## 0.6.0 (April 14, 2011)
315
-
316
- ### Big Changes
317
-
318
- * Rewrote the command-line mode to be based on Node.js instead of Rhino — no
319
- more Java dependency. This also means that PEG.js is available as a Node.js
320
- package and can be required as a module.
321
-
322
- * Version for the browser is built separately from the command-line one in two
323
- flavors (normal and minified).
324
-
325
- * Parser variable name is no longer required argument of `bin/pegjs` — it is
326
- `module.exports` by default and can be set using the `-e`/`--export-var`
327
- option. This makes parsers generated by `/bin/pegjs` Node.js modules by
328
- default.
329
-
330
- * Added ability to start parsing from any grammar rule.
331
-
332
- * Added several compiler optimizations — 0.6 is ~12% faster than 0.5.1 in the
333
- benchmark on V8.
334
-
335
- ### Small Changes
336
-
337
- * Split the source code into multiple files combined together using a build
338
- system.
339
-
340
- * Jake is now used instead of Rake for build scripts — no more Ruby
341
- dependency.
342
-
343
- * Test suite can be run from the command-line.
344
-
345
- * Benchmark suite can be run from the command-line.
346
-
347
- * Benchmark browser runner improvements (users can specify number of runs,
348
- benchmarks are run using `setTimeout`, table is centered and fixed-width).
349
-
350
- * Added PEG.js version to “Generated by...” line in generated parsers.
351
-
352
- * Added PEG.js version information and homepage header to `peg.js`.
353
-
354
- * Generated code improvements and fixes.
355
-
356
- * Internal code improvements and fixes.
357
-
358
- * Rewrote `README.md`.
359
-
360
- ## 0.5.1 (November 28, 2010)
361
-
362
- ### Small Changes
363
-
364
- * Fixed a problem where “SyntaxError: Invalid range in character class.” error
365
- appeared when using command-line version on Widnows
366
- ([GH-13](https://github.com/dmajda/pegjs/issues/13)).
367
-
368
- * Fixed wrong version reported by `bin/pegjs --version`.
369
-
370
- * Removed two unused variables in the code.
371
-
372
- * Fixed incorrect variable name on two places.
373
-
374
- ## 0.5 (June 10, 2010)
375
-
376
- ### Big Changes
377
-
378
- * Syntax change: Use labeled expressions and variables instead of `$1`, `$2`,
379
- etc.
380
-
381
- * Syntax change: Replaced `:` after a rule name with `=`.
382
-
383
- * Syntax change: Allow trailing semicolon (`;`) for rules
384
-
385
- * Semantic change: Start rule of the grammar is now implicitly its first rule.
386
-
387
- * Implemented semantic predicates.
388
-
389
- * Implemented initializers.
390
-
391
- * Removed ability to change the start rule when generating the parser.
392
-
393
- * Added several compiler optimizations — 0.5 is ~11% faster than 0.4 in the
394
- benchmark on V8.
395
-
396
- ### Small Changes
397
-
398
- * `PEG.buildParser` now accepts grammars only in string format.
399
-
400
- * Added “Generated by ...” message to the generated parsers.
401
-
402
- * Formatted all grammars more consistently and transparently.
403
-
404
- * Added notes about ECMA-262, 5th ed. compatibility to the JSON example
405
- grammar.
406
-
407
- * Guarded against redefinition of `undefined`.
408
-
409
- * Made `bin/pegjs` work when called via a symlink
410
- ([issue #1](https://github.com/dmajda/pegjs/issues/1)).
411
-
412
- * Fixed bug causing incorrect error messages
413
- ([issue #2](https://github.com/dmajda/pegjs/issues/2)).
414
-
415
- * Fixed error message for invalid character range.
416
-
417
- * Fixed string literal parsing in the JavaScript grammar.
418
-
419
- * Generated code improvements and fixes.
420
-
421
- * Internal code improvements and fixes.
422
-
423
- * Improved `README.md`.
424
-
425
- ## 0.4 (April 17, 2010)
426
-
427
- ### Big Changes
428
-
429
- * Improved IE compatibility — IE6+ is now fully supported.
430
-
431
- * Generated parsers are now standalone (no runtime is required).
432
-
433
- * Added example grammars for JavaScript, CSS and JSON.
434
-
435
- * Added a benchmark suite.
436
-
437
- * Implemented negative character classes (e.g. `[^a-z]`).
438
-
439
- * Project moved from BitBucket to GitHub.
440
-
441
- ### Small Changes
442
-
443
- * Code generated for the character classes is now regexp-based (= simpler and
444
- more scalable).
445
-
446
- * Added `\uFEFF` (BOM) to the definition of whitespace in the metagrammar.
447
-
448
- * When building a parser, left-recursive rules (both direct and indirect) are
449
- reported as errors.
450
-
451
- * When building a parser, missing rules are reported as errors.
452
-
453
- * Expected items in the error messages do not contain duplicates and they are
454
- sorted.
455
-
456
- * Fixed several bugs in the example arithmetics grammar.
457
-
458
- * Converted `README` to GitHub Flavored Markdown and improved it.
459
-
460
- * Added `CHANGELOG`.
461
-
462
- * Internal code improvements.
463
-
464
- ## 0.3 (March 14, 2010)
465
-
466
- * Wrote `README`.
467
-
468
- * Bootstrapped the grammar parser.
469
-
470
- * Metagrammar recognizes JavaScript-like comments.
471
-
472
- * Changed standard grammar extension from `.peg` to `.pegjs` (it is more
473
- specific).
474
-
475
- * Simplified the example arithmetics grammar + added comment.
476
-
477
- * Fixed a bug with reporting of invalid ranges such as `[b-a]` in the
478
- metagrammar.
479
-
480
- * Fixed `--start` vs. `--start-rule` inconsistency between help and actual
481
- option processing code.
482
-
483
- * Avoided ugliness in QUnit output.
484
-
485
- * Fixed typo in help: `parserVar` → `parser_var`.
486
-
487
- * Internal code improvements.
488
-
489
- ## 0.2.1 (March 8, 2010)
490
-
491
- * Added `pegjs-` prefix to the name of the minified runtime file.
492
-
493
- ## 0.2 (March 8, 2010)
494
-
495
- * Added `Rakefile` that builds minified runtime using Google Closure Compiler
496
- API.
497
-
498
- * Removed trailing commas in object initializers (Google Closure does not like
499
- them).
500
-
501
- ## 0.1 (March 8, 2010)
502
-
503
- * Initial release.