Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parser-toolkit

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parser-toolkit

Toolkit to make streamable scanners and parsers.

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
decreased by-24.78%
Maintainers
1
Weekly downloads
 
Created
Source

parser-toolkit

Build status Dependencies devDependencies NPM version

parser-toolkit is a collection of scanner and parser components, which allows fast creation of efficient parser for custom languages. The main point of a toolkit is to support streamable chunked input.

A standard-compiant implementation of JSON is included as a test. This is how JSON is defined:

var ws           = {id: "ws",           pattern: /\s{1,256}/},
    // numeric tokens
    nonZero      = {id: "nonZero",      pattern: /[1-9]/},
    exponent     = {id: "exponent",     pattern: /[eE]/},
    numericChunk = {id: "numericChunk", pattern: /\d{1,256}/},
    // string tokens
    plainChunk   = {id: "plainChunk",   pattern: /[^\"\\]{1,256}/},
    escapedChars = {id: "escapedChars",
        pattern: /\\(?:[bfnrt\"\\\/]|u[0-9a-fA-F]{4})/};

var json = new Grammar({
    main:   [rule("ws"), rule("value")],
    ws:     repeat(ws),
    value:  [
        any(rule("object"), rule("array"), rule("string"),
            rule("number"), ["-", rule("number")],
            "true", "false", "null"),
        rule("ws")
    ],
    object: [
        "{",
            rule("ws"),
            maybe(rule("pair"),
                repeat(",", rule("ws"), rule("pair"))),
        "}"
    ],
    pair:   [
        rule("string"), rule("ws"), ":", rule("ws"), rule("value")
    ],
    array:  [
        "[",
            rule("ws"),
            maybe(rule("value"),
                repeat(",", rule("ws"), rule("value"))),
        "]"
    ],
    string: ["\"", repeat(any(plainChunk, escapedChars)), "\""],
    number: [
        any("0", [nonZero, repeat(numericChunk)]),
        maybe(".", repeat(numericChunk)),
        maybe(exponent, maybe(any("-", "+")),
            numericChunk, repeat(numericChunk))
    ]
});

The whole definition is taken verbatim from JSON.org.

The test file sample.json is copied as is from an open source project json-simple under Apache License 2.0.

Keywords

FAQs

Package last updated on 31 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc