1.0.9-rc20 • Published 10 months ago

gramr-ts v1.0.9-rc20

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Gramr

Gramr is a lightweight library for building combinator-based parsers. Whether you're parsing a string into tokens or transforming token streams into ASTs, Gramr makes it straightforward, efficient, and fun.

🌟 Features

  • Composable Parsers: Build complex parsers by combining simple, reusable ones.
  • Tokenization Made Easy: Define your grammar for tokenizing strings with intuitive combinators.
  • Flexible AST Generation: Seamlessly convert token streams into Abstract Syntax Trees.
  • Lightweight: Minimal overhead, zero dependency.
  • Typesafe: Every rule is strictly type-annotated.

🚀 Installation

Install Gramr using your favorite package manager:

# npm
npm install gramr-ts

# yarn
yarn add gramr-ts

✨ Basic Usage

Here’s how you can get started:

1. Tokenize a String

import { Lexer } from 'gramr-ts/lexer';
import { Rule } from 'gramr-ts/rule';

const tokenize = Lexer.create(
  [
    Lexer.anyOf('0123456789')
    .let(Rule.collect({ min: 1 }))
    .let(Lexer.slice)
    .let(
      Rule.map((value) => ({ type: 'number', value })),
    ),
    Lexer.exact('+').let(Rule.as({ type: 'plus' })),
  ],
  Lexer.whitespace.let(Rule.loop()),
);

const tokens = tokenize('3 + 5');
// Output: [{ type: 'number', value: '3' }, { type: 'plus' }, { type: 'number', value: '5' }]
console.log(tokens);

Docs

1.0.9-rc20

10 months ago

1.0.9-rc19

10 months ago

1.0.9-rc18

10 months ago

1.0.9-rc17

11 months ago

1.0.9-rc16

11 months ago

1.0.9-rc15

11 months ago

1.0.9-rc14

11 months ago

1.0.9-rc13

11 months ago

1.0.9-rc12

11 months ago

1.0.9-rc11

11 months ago

1.0.9-rc10

11 months ago

1.0.9-rc9

11 months ago

1.0.9-rc8

11 months ago

1.0.9-rc7

11 months ago

1.0.9-rc6

11 months ago

1.0.9-rc5

11 months ago

1.0.9-rc4

11 months ago

1.0.9-rc3

11 months ago

1.0.9-rc2

11 months ago

1.0.9-rc1

11 months ago

1.0.9-rc0

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago