0.17.0 • Published 4 months ago

retsac v0.17.0

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

Retsac

npm coverage build license

!WARNING This project is still in early development stage, the API may change frequently.

Text lexer and parser. Compiler frontend framework.

This can be used to fast prototype your own programming language compiler/translator frontend, or parse your domain specific language.

Try it online in the playground.

Installation

yarn add retsac

Features

  • The Lexer, yield token from the text input string.
    • Regex support. See examples below.
    • Built-in util functions.
      • JavaScript's string literal, numeric literal, integer literal, identifier, etc.
      • JSON's string literal, numeric literal.
    • Support custom functions.
  • The Parser, co-work with the lexer and produce an AST (Abstract Syntax Tree).
    • ELR (Expectational LR) parser.
      • Meta characters like +*? when defining a grammar rule.
      • Conflict detection, try to auto resolve conflicts.
      • Query children nodes by using $('name') instead of children[index].
      • Top-down traverse the AST.
      • Bottom-up reduce data.
      • Expect lexer to yield specific token type and/or content.
      • Try to re-lex the input if parsing failed.
      • DFA serialization & hydration to accelerate future building.
    • Serializable AST object to co-work with other tools (e.g. compiler backend libs like LLVM).
  • Strict type checking with TypeScript.
    • This is amazing, you'd better try this out by yourself.

Resources

Examples

JSON Parser

In this example, we use AdvancedBuilder to define grammar rules with +*?, define top-down traversers using traverser, and query nodes in grammar rules using $ and $$.

All conflicts are auto resolved.

Calculator

In this example, we use reducer to define bottom-up data reducers, so we can get the result when the AST is built.

There are conflicts introduced by those grammar rules, we use the high-level resolver API priority to resolve them.

Contribute

All issues and pull requests are highly welcomed.

CHANGELOG

0.17.0

4 months ago

0.16.0

4 months ago

0.16.1

4 months ago

0.15.0

4 months ago

0.12.0

7 months ago

0.13.0

6 months ago

0.14.0

6 months ago

0.13.1

6 months ago

0.10.0

9 months ago

0.11.0

9 months ago

0.9.0

1 year ago

0.8.0

1 year ago

0.4.0-beta.2

1 year ago

0.4.0-beta.3

1 year ago

0.4.0-beta.4

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.1

1 year ago

0.4.0-beta.1

1 year ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago