PEG.js v0.10.0 Release Notes
Release Date: 2016-08-19 // about 8 years ago-
Major Changes
π Parsers can be generated in multiple module formats. The available
0οΈβ£ formats are: CommonJS (the default), AMD, UMD, globals, and bare (not
available from the command-line).The format can be specified using the
format
option of thepeg.generate
function or the--format
option on the command-line.π It is also possible to specify parser dependencies using the
dependencies
option of thepeg.generate
function or the--dependency
/-d
option on
the command-line. This is mainly useful for the UMD format, where the
dependencies are translated into both AMD dependencies and CommonJS
require
calls.π» Browser version of PEG.js is now in the UMD format. This means it will try
to detect AMD or Node.js/CommonJS module loader and define itself as a
module. If no loader is found, it will export itself using a global
variable.π API polishing. The
peg.buildParser
function was renamed to
π»peg.generate
. The global variable the browser version of PEG.js is
available in when no loader is detected was renamed fromPEG
topeg
.CLI improvements. There is new
--output
/-o
command-line option which
π allows to specify the output file. The old way of specifying the output file
π using a second argument was removed. To make room for the new-o
option
β‘οΈ the old one (a shortcut for--optimize
) was renamed to-O
. All these
π changes make PEG.js conform to traditional compiler command-line interface.It is now also possible to use
-
as a file name on the command-line (with
the usual meaning of standard input/output).π Improved error messages. Both messages produced by PEG.js and generated
π parsers were improved.Duplicate rule definitions are reported as errors.
Duplicate labels are reported as errors.
Minor Changes
- π¦ Exposed the AST node visitor builder as
peg.compiler.visitor
. This is
π useful mainly for plugins which manipulate the AST. - π¦ Exposed the function which builds messages of exceptions produced by
π generated parsers asSyntaxError.buildMessage
. This is useful mainly for
customizing these error messages. - The
error
andexpected
functions now accept an optionallocation
parameter. This allows to customize the location in which the resulting
syntax error is reported. - π¨ Refactored expectations reported in the
expected
property of exceptions
π produced by generated parsers. They are no longer de-duplicated and sorted,
their format changed to be more machine-readable, and they no longer contain
human-readable descriptions. - The
found
property of exceptions produced by theerror
function is now
set tonull
. - β Removed access to the parser object in parser code via the
parser
variable. - Made handling of optional parameters consistent with ES 2015. Specifically,
passingundefined
as a parameter value is now equivalent to not passing
the parameter at all. - π Renamed several compiler passes.
- π Generated parsers no longer consider
\r
,\u2028
, and\u2029
as
π newlines (only\n
and\r\n
). - Simplified the arithmetics example grammar.
- Switched from
first
/rest
tohead
/tail
in PEG.js grammar and example
grammars. - π Started using ESLint instead of JSHint and fixed various problems it found.
- β Added contribution
guidelines. - β Removed support for io.js.
π Bug Fixes
- π Fixed
bin/pegjs
so that invoking it with one non-option argument which is
an extension-less file doesnβt cause that file to be overwritten. - π Fixed label scoping so that labels in expressions like
(a:"a")
or(a:"a" b:"b" c:"c")
arenβt visible from the outside. - π Fixed escaping of generated JavaScript strings & regexps to also escape DEL
(U+007F). - π Fixed the JSON example grammar to correctly handle characters with code
points above U+10FF in strings. - π Fixed multiple compatibility issues of
tools/impact
on OS X. - π Fixed slow deduplication of expectation descriptions.
- π¦ Exposed the AST node visitor builder as
Previous changes from v0.9.0
-
Major Changes
- π Tracing support. Parsers can be compiled with support for tracing their
progress, which can help debugging complex grammars. This feature is
experimental and is expected to evolve over time as experience is gained.
More details - Infinite loop detection. Grammar constructs that could cause infinite
π loops in generated parsers are detected during compilation and cause errors. - π Improved location information API. The
line
,column
, andoffset
π functions available in parser code were replaced by a singlelocation
function which returns an object describing the current location. Similarly,
theline
,column
, andoffset
properties of exceptions were replaced by
a singlelocation
property. The location is no longer a single point but a
character range, which is meaningful mainly in actions where the range
covers actionβs expression.
More details - π Improved error reporting. All exceptions thrown when generating a parser
have associated location information. And all exceptions thrown by generated
π parser and PEG.js itself have a stack trace (thestack
property) in
π environments that supportError.captureStackTrace
. - Strict mode code. All PEG.js and generated parser code is written using
π JavaScript strict mode.
Minor Changes
- π Labels behave like block-scoped variables. This means parser code can see
labels defined outside expressions containing code. - Empty sequences are no longer allowed.
- Label names canβt be JavaScript reserved words.
- Rule and label names can contain Unicode characters like in JavaScript.
- Rules have to be separated either by
;
or a newline (until now, any
whitespace was enough). - The PEG.js grammar and all the example grammars were completely rewritten.
This rewrite included a number of cleanups, formatting changes, naming
π changes, and bug fixes. - π The parser object can now be accessed as
parser
in parser code. - Location information computation is faster.
- β Added support for Node.js >= 0.10.x, io.js, and Edge. Removed support for
Node.js < 0.10.x.
π Bug Fixes
- π Fixed left recursion detector which missed many cases.
- π Fixed escaping of U+0100βU+107F and U+1000βU+107F in generated code and
error messages. - π Renamed
parse
andSyntaxError
topeg$parse
andpeg$SyntaxError
to
mark them as internal identifiers.
- π Tracing support. Parsers can be compiled with support for tracing their