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 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-xsyn

v1.3.24

Published

a parser generator implemented in node

Readme

node-xsyn

Extensible syntax for node

(or: A DSL package for node)

This project provides the possibility to define new languages (DSLs) by means of context-free grammars. Node-xsyn works similarly as some well-known tools lex/yacc/bison by allowing to attach processing rules to each of the grammar production rules. Node-xsyn uses the LALR(1) method to generate a parser and is fully integrated into the node module system; language parsers can be compiled into node modules and re-used as needed.

Hello (World) Example

In order to illustrate how the package works, let first look at a HelloWorld "Language". Assume, we have the following grammar definition in a file called "hello.gra":

Greeting : Greeting_en
           {% $$ = 'Hello, how are you?'; %}
         | Greeting_de
           {% $$ = 'Hallo, wie geht es Dir?'; %}
         ;
         
Greeting_en : 'Hello';
Greeting_de : 'Hallo';

The "language" defined by the above grammar consists of three nonterminal symbols (Greeting, Greeting_en, and Greeting_de) with corresponding production rules. The code in {% ... %} represents the associated action for the respective production rule. Those familiar with lex and yacc will immediately recognize the dollar syntax in the associated production rule; '$$' stands for the result of the action, while $1, $2, ... refer to the corresponding elements of the production rule's right-hand-side (starting with index 1; not used in this example). The only possible input strings that this language accepts are "Hello" or "Hallo"; the parsing/processing "responds" to the input with the English or the German answer sentence depending on the input.

This hello language can now be compiled into a node module, which can be "require-d" in your node application as follows:

var xsyn = require('node-xsyn'); // load the node-xsyn package

var HelloLang = require(xsyn.languageModule('hello.gra')); // load the 'Hello' language

The last line in the above listing triggers the generation of the parser into a node module and loads the generated javascript file as a node module. (Without any option the generated file will reside in the directory ".xsyn_gen/"; the parser generation is only triggered if the grammar files has changed since the last use.)

Your language can now be used in the following way inside your node application:

...
var hello = new HelloLang();
console.log(hello.parser.run('Hello')); // prints 'Hello, how are you?'
console.log(hello.parser.run('Hallo')); // prints 'Hallo, wie geht es Dir?'

Alternatively, instead of supplying the input in form of a string, you could write it into a file and process that instead. Let's assume the file 'foo.hello' would contain just one line consisting of 'Hello' or 'Hallo'; the function call would then look slightly different:

...
console.log(hello.parser.run( { inputFile : 'foo.hello' } ));
...

to be continued