Code Monkey home page Code Monkey logo

miam.js's Introduction

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"))
fold_many_m_n consumes a parser between m and n times, and fold each of them
fold_many_m_n(
    1,
    3,
    [],
    (accumulator: Array, item: string) => {
        accumulator.push(item);
        return accumulator;
    },
    tag("abc")
);
fold_many_0 alias for fold_many_m_n(0, Infinity, …, …)
fold_many_1 alias for fold_many_m_n(1, Infinity, …, …)
many_0 alias for fold_many_0([], …) where the result is an array of all items
many_0(tag("abc"))
many_1 alias for fold_many_1([], …) where the result is an array of all items
many_1(tag("abc"))

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.

miam.js's People

Contributors

hywan avatar

Stargazers

Wes Roberts avatar Maximilian Klein avatar Piotr Szlachciak avatar Julien BIANCHI avatar Andrejs Agejevs avatar  avatar Geoffroy Couprie avatar Javier Diaz avatar Rasmus Schultz avatar

Watchers

Riad Benguella avatar James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.