6

Is there a JavaScript framework that allows to define a parsing grammar using JavaScript syntax, similar to the way Irony does it for C#?

3 Answers 3

6

I have built a JavaScript Parsing DSL called Chevrotain.

Source: https://github.com/SAP/chevrotain

Online Playground: http://sap.github.io/chevrotain/playground/

It is not a Parser combinator like Irony, but it is very similar as it allows you to "define a parsing grammar using JavaScript syntax" without any code generation phase.

Using it is similar to "hand building" a recursive decent parser, only without most of the headache such as:

  • Lookahead function creation (deciding which alternative to take)
  • Automatic Error Recovery.
  • Left recursion detection
  • Ambiguity Detection.
  • Position information.
  • ...

as Chevrotain handles that automatically.

Sign up to request clarification or add additional context in comments.

Comments

3

I don't know much about how Irony works, but Chris Double has a library that lets you define grammars in JavaScript here: http://www.bluishcoder.co.nz/2007/10/javascript-parser-combinators.html. The code is available on GitHub.

It's a "parser combinator" library which means you combine parsers for each production in your grammar into a larger parser that parses the whole thing. Each "sub-grammar" is a just a function that you create by calling the library functions.

1 Comment

Thanks, that seems to be the thing I was looking for, I'll take a closer look.
0

PEG.js could be one solution.

PEG.js is a simple parser generator for JavaScript that produces fast parsers with excellent error reporting. You can use it to process complex data or computer languages and build transformers, interpreters, compilers and other tools easily.

Features

Simple and expressive grammar syntax Integrates both lexical and syntactical analysis Parsers have excellent error reporting out of the box Based on parsing expression grammar formalism — more powerful than traditional LL(k) and LR(k) parsers Usable from your browser, from the command line, or via JavaScript API

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.