1.0.9-rc20 • Published 7 months ago

gramr-ts v1.0.9-rc20

Weekly downloads
-
License
MIT
Repository
github
Last release
7 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

7 months ago

1.0.9-rc19

7 months ago

1.0.9-rc18

7 months ago

1.0.9-rc17

8 months ago

1.0.9-rc16

8 months ago

1.0.9-rc15

8 months ago

1.0.9-rc14

8 months ago

1.0.9-rc13

8 months ago

1.0.9-rc12

8 months ago

1.0.9-rc11

8 months ago

1.0.9-rc10

8 months ago

1.0.9-rc9

8 months ago

1.0.9-rc8

8 months ago

1.0.9-rc7

8 months ago

1.0.9-rc6

8 months ago

1.0.9-rc5

8 months ago

1.0.9-rc4

8 months ago

1.0.9-rc3

8 months ago

1.0.9-rc2

8 months ago

1.0.9-rc1

8 months ago

1.0.9-rc0

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago