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

arpeggiojs

v0.0.1-alpha.2

Published

```typescript abstract class ParsingExpression { // Base class for any parsing expression. // It contains the main options that are common for all expressions. // It handles the highlevel parsing logic, and the cache mechanism.

Readme

ParsingExpression

abstract class ParsingExpression {
    // Base class for any parsing expression.
    // It contains the main options that are common for all expressions.
    // It handles the highlevel parsing logic, and the cache mechanism.

    // By default, expressions should be kept as is, and not reduced.
    // If this is set to true by any subclass, it should be reduced.
    // This is used to reduce the expression tree to a simpler form.
    // i.e. some expressions are just useless if they have only one child element
    // e.g. Sequence with only one child, or Choice with only one child.
    // I that case, that one child will be used directly instead of the parent.
    readonly preReducible: boolean = false;

    // While refining and visiting the parse-tree,
    //   by default, parse-tree nodes should be kept as is, and not reduced.
    // If this is set to true by any subclass,
    //   parse-tree nodes of this expression should be reduced.
    // For some expressions, they won't return more than one child-node at most,
    // i.e. Optional and Choice.
    // In that case, the child-node will be used directly instead of the parent.
    // NOTE: This is not considered if the expression has a refiner or a ruleName.
    readonly autoReduce: boolean = false;

    constructor(
        readonly elements: GrammarDef[],
        readonly options: PEOptions = {}
    ) {
        //
    }
}

ParsingExpression

Options:

  • ruleName: string (default: "")
  • refiner: Function | SUPPRESS | REDUCE (default: "")

Match

The only expressions that return Terminal PTNode

Options:

  • ignoreCase: boolean (default: undefined)

StringMatch

RegexMatch

SyntaxPredicate

Doesn't have any options, it's always suppressed, and doesn't consume


skipWS

  • string: skip any of these characters.
  • null: don't skip whitespaces.
  • undefined: not configured, use default "\r\n\t ".

ignoreCase

  • true: force ignore case for all rules.
  • false: case-sensitive except for RegExp instances with i flag set explicitly.
  • undefined: not configured, use default false.

Caches:

  • ruleCache: stores the normalized rules
    (i.e. strings, RegExp's, arrays, or functions that are parsed to Index)
  • resultCache: given a Index and a position, return result and next position if the expression succeeded matching before at this position.

Challenge:

How to handle this?

def expr():
    return Choice(Sequence(expr, "+", term), term)

def term():
    return RegExMatch(r'\d+')

Elements

Errors

GrammarError

Normal class extends Error.

Used only when there is an expression that's not extending ParsingExpresion or not convertable to it.

NoMatch

Used when there is no match for the next rule when it's expected to match.

If it's not required to match (i.e. Optional), it's not an error. It should return a PTNode with null value instead.

NoMatch error should provide information about the position of the error (using context format), and what rules are expected (if set)

Parsing Expressions

Index

The base class of all expressions, it contains the main (generic) options:

  • root: boolean (not clear so far)
  • ruleName: string
  • suppress: boolean
  • visitor: (node, children) => any

Methods:

  • parse(ctx: Parser)
    1. log(">> Matching rule {ruleName} at position {line:col} => {context}", indent=1)
    2. Check cache
      • If cached:
        • set position to new position
        • increase cache hits
        • log("** Cache hit for {ruleName} as {line:col} = '{result}' : new_pos={line:col}")
        • log("<<+ Matched rule {ruleName} at position {line:col}")
        • if result is NOMATCH_MARKER, raise ctx.nm, otherwise return the result
      • else:
        • increase cache misses
  • mjnkbh