npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ts-jison/lexer-generator

v0.4.1-alpha.2

Published

A lightly-typescriptified version of jison-lex

Downloads

31,661

Readme

@ts-jison/lexer-generator:

A lightly-typescriptified API for creating parsers in JavaScript

A lexical analyzer generator used by @ts-jison/parser-generator. It takes a lexical grammar definition (either in JSON or Bison's lexical grammar format) and outputs a JavaScript lexer.

This is a fork of Zach Carter [email protected]'s jison module tweaked to use just enough templates to make typescript compilers tollerate the generated parser. Additional work has gone into passing YY objects through both the parser constructor and the parse(text, yyobject) methods.

Installation

@ts-jison/lexer-generator can be installed for Node using npm

Using npm:

npm install @ts-jison/lexer-generator

add a package.json script for a javascript file for e.g. an LR parser for "ShEx":

"build-parser": "ts-jison -n ShExJison -t javascript -p lr -o ./lib/ShExJison.js ./lib/ShExJison.jison"

or e.g. an LALR typescript parser:

"build-parser": "ts-jison -n ShExJison -t typescript -p lalr -o ./lib/ShExJison.ts ./lib/ShExJison.jison"

Status:

This works (I'm using it in a few javascript and typescritp projects) and runs the original tests. If you want to geek about this, ping ericP on discord or ericprud on gitter.

Changes from jison

Most changes are in the output. Specifically, the constructed regular expressions (mostly) elide unnecessary () and eliminate capture groups on semanticly-necessary (?:), e.g.:

/^(?:\s+|(#[^\u000a\u000d]*|\/\*([^*]|\*([^/]|\\\/))*\*\/))/

is now:

/^(?:\s+|#[^\u000a\u000d]*|\/\*(?:[^*]|\*(?:[^/]|\\\/))*\*\/)/

This resulted in a ~300X speedup for the ShExC parser and kept the stack from blowing up on large input like the FHIR ShEx.

When invoking the lexer through the API, the old convetion for rules was an optional array of start conditions, followed by a string for the pattern and a string for the action:

[ "enter-test", "this.begin('test');" ],
[ ["INITIIAL", "test"], "x", "return 'T';" },

Those are now distinguised by properties in an object:

{ pattern: "enter-test", action: "this.begin('test');" },
{ start: ["INITIAL", "test"], pattern: "x", action: "return 'T';" },

Components:

  • parser-generator - A lightly-typescriptified version of jison
  • lexer-generator - A lightly-typescriptified version of jison-lex
  • parser - runtime library for parsers
  • lexer - runtime library for lexers
  • common - functions needed by parser and lexer

usage

Usage: ts-lex [file] [options]

file     file containing a lexical grammar

Options:
   -o FILE, --outfile FILE       Filename and base module name of the generated parser
   -t TYPE, --module-type TYPE   The type of module to generate (commonjs, js)
   --version                     print version and exit

programatic usage

var JisonLex = require(@ts-jison/lexer-generator');

var grammar = {
  rules: [
    ["x", "return 'X';" ],
    ["y", "return 'Y';" ],
    ["$", "return 'EOF';" ]
  ]
};

// or load from a file
// var grammar = fs.readFileSync('mylexer.l', 'utf8');

// generate source
var lexerSource = JisonLex.generate(grammar);

// or create a parser in memory
var lexer = new JisonLex(grammar);
lexer.setInput('xyxxy');
lexer.lex();
// => 'X'
lexer.lex();
// => 'Y'

## license
MIT