0.5.4 • Published 4 years ago

typescript-parser-combinator v0.5.4

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

TypeScript Parser Combinator

A simple parser combinator in TypeScript.

It has been built with the sole aim of learning parser combinators and npm package management.

Getting Started

Consider the following

import { text, digits, takeUntil, char, unit, space, word, newLineToken, between } from 'typescript-parser-combinator'

let input = "Weather (today): Sunny\r\n" +
            "Weather (yesterday): Cloudy\r\n" +
            "Weather (one week ago): Rainy"

let parser = text('Weather')
                .then(space)
                .then(between(text('('),text(')')))            .take()
                .then(text(': '))                              .drop()
                .then(word)
                .then(newLineToken.maybe())                    .drop()
                .map(([date, weather]) => ({ date, weather }))
                .many1()

let result = parser(input)

if (result.success) {
    expect(result.value[0].date).to.equal('today')
    expect(result.value[0].weather).to.equal('Sunny')
    expect(result.value[1].date).to.equal('yesterday')
    expect(result.value[1].weather).to.equal('Cloudy')
    expect(result.value[2].date).to.equal('one week ago')
    expect(result.value[2].weather).to.equal('Rainy')
}
0.5.4

4 years ago

0.5.3

4 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago