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

pegex

v0.1.7

Published

Acmeist PEG Parser Framework

Downloads

20

Readme

Pegex

An Acmeist PEG Framework

Description

Pegex is a PEG (Parser Expression Grammar) framework where each low level match is a regular expression call. It is intended to work in all programming languages the support regular expressions.

Pegex attempts to make it very easy to write a Parser for a DSL (like JSON) and have it quickly work in every modern programming language.

Pegex uses a Pegex grammar to parse Pegex. This means it is "self-hosting". The current Pegex grammar for Pegex lives here.

Pegex grammars can be precompiled to simple data structures that can be dumped to YAML or JSON. Here is the above Pegex Grammar (for Pegex) as YAML, and here it is as JSON.

As Pegex parsers match things, they call back the results to a "Receiver" class. The default receiver class will turn the parse events into a parse tree, also known as an AST. Receiver classes often organize parse data into structures needed by the next downstream process, however they are not limited to this.

Pegex Implementations

Pegex is currently implemented in Perl, Ruby and CoffeeScript (thus JavaScript) and available on CPAN, RubyGems, and NPM respectively. A project called CafeScript is under way to make the CoffeeScript implementation, compile to many other languages.

An Example Pegex Grammar

The JSON Pegex Grammar is small enough to show inline:

# A simple grammar for the simple JSON data language.
# See https://github.com/ingydotnet/pegex-json-pm for a Parser implementation
# that uses this grammar.

%grammar json
%version 0.0.1

json: map | seq

node: map | seq | scalar

map:
  / ~ LCURLY ~ /
  pair* % / ~ COMMA ~ /
  / ~ RCURLY ~ /

pair:
  string
  / ~ COLON ~ /
  node

seq:
  / ~ LSQUARE ~ /
  node* % / ~ COMMA ~ /
  / ~ RSQUARE ~ /

scalar:
  string |
  number |
  boolean |
  null

string: / # XXX Need to code this to spec.
  DOUBLE  # This works for simple cases,
    ((: # but doesn't handle all escaping yet.
      BACK BACK |
      BACK DOUBLE |
      [^ DOUBLE BREAK ]
    )*)
  DOUBLE
/

number: /(
  DASH?
  (: 0 | [1-9] DIGIT* )
  (: DOT DIGIT* )?
  (: [eE] [ DASH PLUS ]? DIGIT+ )?
)/

boolean: true | false

true: /true/

false: /false/

null: /null/

The Pegex::JSON Perl JSON parsing module, uses this Receiver class:

##
# name: Pegex::JSON::Data
# abstract: Pegex Data Structure Builder for JSON
# author: Ingy döt Net <[email protected]>
# license: perl
# copyright: 2018

package Pegex::JSON::Data;
use Pegex::Mo;
extends 'Pegex::Receiver';

use boolean;

sub got_map { +{map @$_, map @$_, @{(pop)}} }
sub got_seq { [map @$_, @{(pop)}] }

sub got_string {
  my $string = pop;
  # XXX need to decode other string escapes here
  $string =~ s/\\n/\n/g;
  return $string;
}

sub got_number { $_[1] + 0 }
sub got_true { &boolean::true }
sub got_false { &boolean::false }
sub got_null { undef }

Full documentation coming soon.