npm.io
0.1.0 • Published 8 years ago

miam

Licence
BSD-3-Clause
Version
0.1.0
Deps
1
Vulns
0
Weekly
0
Stars
9

Miam • JS

miam.js is a parser combinator framework written in TypeScript. It is highly inspired by the excellent nom project. A special focus is brough on the type system to provide as much safety as possible, and to avoid consuming too much memory. Thus, the goal of miam.js is to provide a safe and relatively fast framework to build parsers.

miam.js is written in TypeScript, a language that compiles into JavaScript.

Features

  • Zero-copy: The parsers do not copy the string being analysed despite the fact that they are all pure,
  • Safe parsing: We commit to bring as much safety as possible regarding the current tooling and languages we have. All means (like type system) are used to provide a safe framework to develop new parsers,
  • Speed: No benchmark yet, but we hope that our approach with zero-copy will help to be fast,
  • Lightweight: All the type system disappears at compile-time (from TypeScript to JavaScript); the resulting files are small (≈5Kb).

List of parsers

Parser name Description Example
tag consumes a given constant value
tag("abc")
concat concatenates two or more parsers together
concat(tag("abc"), tag("def"))
alt tests all given parsers until one succeed
alt(tag("abc"), tag("def"))
opt tries a parser
opt(tag("abc"))
regex consumes a given regular-expression based value
regex(/a[bc]/)
map transforms the consumed value from a parser into something else with a function
map(
    tag("abc"),
    abc => abc.toUpperCase()
)
label_do gives a name (“label”) to all parser values, and passes them into a function for a final transformation (“do”)
label_do(
    {
        first: tag("abc"),
        second: tag("def")
    },
    ({first, second}) => {
        return {
            head: first,
            tail: second
        }
    )
)
precede consumes a prefix and a subject, returns the subject
precede(tag("prefix"), tag("subject"))
terminate consumes a subject and a suffix, returns the subject
terminate(tag("subject"), tag("suffix"))

Example

See the examples/ directory for some examples.

The test/unit/ directory contains a nice overview of the API too.

Status

Still under development. Please don't use it right now :-). API is under stabilisation.

Keywords