1.0.9-rc20 • Published 9 months ago

gramr-ts v1.0.9-rc20

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

9 months ago

1.0.9-rc19

9 months ago

1.0.9-rc18

9 months ago

1.0.9-rc17

9 months ago

1.0.9-rc16

9 months ago

1.0.9-rc15

9 months ago

1.0.9-rc14

9 months ago

1.0.9-rc13

9 months ago

1.0.9-rc12

9 months ago

1.0.9-rc11

9 months ago

1.0.9-rc10

10 months ago

1.0.9-rc9

10 months ago

1.0.9-rc8

10 months ago

1.0.9-rc7

10 months ago

1.0.9-rc6

10 months ago

1.0.9-rc5

10 months ago

1.0.9-rc4

10 months ago

1.0.9-rc3

10 months ago

1.0.9-rc2

10 months ago

1.0.9-rc1

10 months ago

1.0.9-rc0

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago