Skip to content

Minor features and optimizations

Choose a tag to compare

@hildjj hildjj released this 02 Jun 22:23
· 808 commits to main since this release
a556299

Minor Changes

  • Infrastructural rebake @StoneCypher

    • Builds with typescript, removes babel
    • Bundles with rollup, removes browserify
    • Tests with jest, removes mocha
    • Minifies with terser, removes uglify
    • Adds rimraf for portable pre-build cleanup
    • Extends CI testing to windows, macintosh
    • Increases node testing range to include node 16
  • Option to select optimization mode removed as it had no significant effect on the
    majority of generated parsers and as such represented only academic interest. You should
    use minifiers to get smaller parsers. Option optimize is deleted from the generate()
    options, flag --optimize is deleted from the CLI (you still can supply it, but the CLI
    will issue a warning that the option is removed).
    @Mingun

  • location()s now will have additional source property which value is taken
    from the options.grammarSource property. That property can contain arbitrary
    data, for example, path to the currently parsed file.
    @Mingun

  • Made usage of GrammarError and peg$SyntaxError more consistent. Use the
    format method to get pretty string outputs. Updated the peggy binary to
    make pretty errors. Slight breaking change: the format of a few error
    messages have changed; use the toString() method on GrammarError to get
    something close to the old text.
    @hildjj

  • The code generator was slightly reworked to simplify reusing the bytecode generator
    (generate.generateBytecode pass). Property consts on the grammar AST node,
    has been creating by the pass in the past, was decoupled into 4 other properties
    with the structured information:

    • literals
    • classes
    • expectations
    • functions
  • Added missing type definitions to the peg.d.ts file. Added definitions for the
    compiler and visitor modules, AST, and plugins option in the generate() function.
    @Mingun

    Now bytecode generation pass is independent from the JavaScript backend.
    @Mingun

  • Some opcodes from compiler/opcode.js were deprecated. Although you shouldn't use
    them directly because they are not considered as a public API, some plugins use them.
    For that reason backward compatibility is preserved:

    • Opcode MATCH_REGEXP is deprecated and replaced by MATCH_CHAR_CLASS with the same value.
    • Added new opcode PUSH_EMPTY_STRING that puts a new empty string on the stack.
    • Opcode PUSH is deprecated because it was used only for pushing empty string constants
      and they now pushed with PUSH_EMPTY_STRING.

    Instead of relying on the library opcodes it is better to have a copy of
    them, especially if your plugin replaces both the generateBytecode and
    the generateJs passes. @Mingun

  • Default visitor functions, returned by the visitor.build(), that just forward
    call to node.expression, now return the result of underlying visit call.
    @Mingun

    Affected functions:

    • rule
    • named
    • action
    • labeled
    • text
    • simple_and
    • simple_not
    • optional
    • zero_or_more
    • one_or_more
    • group
  • Parsers now can use two new functions to get location information:
    offset() and range(). Use them if you don't need the whole
    location information, because it is expensive to compute.
    These two new functions are always very efficient (back-ported pegjs/pegjs#528).
    @felix9 and @Mingun

  • Add a new option config.reservedWords: string[], avalible for plugins in their
    use() method. Using this option, a plugin can change the list of words that
    cannot be used.

    By default this new option contains an array with reserved JavaScript words
    @Mingun

  • Several optimizations in the generator. Generated parsers should now be faster and smaller
    @Mingun

Bug fixes

  • #112: "group" node in the AST now have location information (back-ported)
  • #143: peg.d.ts had some errors in the type descriptions, which were fixed