1.2.2 • Published 5 months ago

sprache v1.2.2

Weekly downloads
311
License
MIT
Repository
github
Last release
5 months ago

Sprache.js

sprache.js is a TypeScript port of Sprache, a simple parser for C#

<Sprache> codecov

npm install sprache --save

Usage

Unlike most parser-building frameworks, you use Sprache from your program code, and don't need to set up any build-time code generation tasks.

A simple parser might parse a sequence of characters:

import { Parse } from 'sprache';

// Parse any number of capital 'A's in a row
var parseA = Parse.char('A').atLeastOnce();

Sprache provides a number of built-in functions that can make bigger parsers from smaller ones, often callable via generators:

import { Parse } from 'sprache';

const identifier = Parse.query(function*() {
    const leading  = yield Parse.whiteSpace.many();
    const first    = yield Parse.letter.once();
    const rest     = yield Parse.letterOrDigit.many();
    const trailing = yield Parse.whiteSpace.many();

    return Parse.return([first].concat(rest).join(''));
});

var id = identifier.parse(" abc123  ");

Assert.isEqual("abc123", id);

More Examples

More examples are available in src/examples/

Building / Running examples

Requirements:

  • NodeJS
  • yarn
winget install OpenJS.NodeJS
winget install Yarn.Yarn
yarn install
yarn run build
yarn run test

To run as example

yarn run build && node dist/examples/sql

Is VSCode, just run task "npm: install", then F5 to run.

1.2.2

5 months ago

1.2.1

3 years ago

1.2.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

5 years ago

1.0.0-alpha.4

5 years ago

1.0.0-alpha.3

7 years ago

1.0.0-alpha.2

7 years ago

1.0.0-alpha.1

7 years ago