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

jacek

v0.2.0

Published

A simple, lightweight parser generator

Downloads

6

Readme

jacek

jacek is yet another compiler compiler for javascript. The produced code is a simple recursive descent parser.

Installation

npm intsall --save-dev gcnew/jacek

Why yet another lexer / parser generator?

jacek was created because I wanted a simple, easy to use and set-up parser generator. .. and beause it was easy to write one.

The grammar

The syntax is EBNF inspired.

Blocks

Blocks are literal text in between %{ and }% copy-pasted in the output. Useful for imports, exports, function and type definitions. There can be any number of blocks and can be placed anywhere inside the grammar file, but their contents is concatanated and printed before any generated code. By convention, blocks should be placed before the first rule.

%{
export type Id      = { kind: 'id',      start: number, end: number, text: string }

function mkId(start: number, end: number, text: string): Id {
    return { kind: 'id', start, end, text };
}
}%

Rules

Rules are a means for grouping patterns and giving them a name.

In it's simplest form, the syntax is as follows

               ;

All elements are required. E.g

matchHelloWorld = 'Hello World!'
                ;

Rules are compiled to parser functions that can be imported and used to parse text.

Basic Patterns

  • literals Literals are any quoted text. An exact, case-sensitive match is performed.

    literal = 'literals are any quoted text'
            ;
  • RegExps The usual Perl / JS syntax is used. The behaviour can be altered by using flags - i for case-insensitive and s for dot-all.

    regExp = /\w+/
           ;
    
    caseInsensitive = /aaa/i
                    ;
    
    dotAll = /the dot . matches any char including new lines/s
           ;
  • any Matches any single character. Might be removed in the future, as it's just a shortcut for /./s.

    matchesAnyCharacter = .
                        ;
  • not Matches a single character if the pattern inside the not is not met. The possible patterns are: literal, regexp, any and rule.

    notPattern = not('can be any simple pattern')
               ;
    
  • rule reference Rules can be invoked by referencing their name.

    statement = expression ';'
              ;

Repetition patterns

Just like in regular expressions, the modifiers *, + and ? are used to match a pettern many, one-or-more or maybe-one times.

  • repetition To match a pattern many times (zero or more), use *.

    many = somePattern*
         ;
  • one or more To match a pattern one or more times use +.

    oneOrMore = somePattern+
              ;
  • maybe match To match an optional pattern use ?.

    maybePresent = somePattern?
                 ;

Rules - mapping

Oftentimes, the aim for parsing is generating an AST (abstract syntax tree). In the same fashions as Yacc, jacek uses mapping expressions (actions in Yacc). Mapping expressions are simple code that modifies the parsing result, by running an arbitrary JavaScript expression. This expression has access to the parsed results (e.g. $0 - the result of the first pattern, $1 - the result of the second one, etc) and the computed value becomes the result of the rule.

Example

A simple Lambda Calculus parser

%{
type Id          = { kind: 'id', value: string, start: number, end: number }
type Lambda      = { kind: 'fn', arg: Id, body: Expr, start: number }
type Application = { kind: 'ap', fn: Expr, arg: Expr }

type Expr        = Lambda
                 | Application
}%


id = /\w+/                   %% { kind: 'id', value: text(), start, end } as Id
   ;

lambda = 'λ' id '.' expr     %% { kind: 'fn', arg: $1, body: $3, start } as Lambda
       ;

application = expr ' ' expr  %% { kind: 'ap', fn: $1, arg: $3 } as Application
            ;

expr = lambda
     | application
     ;