Skip to content

A javascript library for parsing rsql expressions into predicates.

License

Notifications You must be signed in to change notification settings

vodori/rsql-parser

Repository files navigation

Build Status MIT Licence

rsql-parser

A javascript parser and visitor for the predicate expression language RSQL. Useful for turning simple string expressions into a function that resolves to either true or false when provided a chunk of data.

Usage

const parser = new Parser.PredicateParser();
const predicate = parser.parse("firstName==Paul;age==25");
const matches = predicate({firstName: "Paul", age: 23});
assertFalse(matches);

How it works

We've written an RSQL grammar for Antlr4. We compile this grammar into a lexer, parser, and base visitor. We then extend the base visitor with hand-written code that builds the parsed AST into a function of one argument that returns a boolean indicating if the data matches the expression. The grammar still needs battle testing and may be missing support for certain edge cases. Please see the tests for examples of what is / isn't supported and expected behavior.

Motivation

RSQL is used internally as a predicate expression language within Vodori's Pepper Cloud product suite. We're creating a browser compatible version so that we can extend dynamic configurable behavior to the browser but without asking the people writing configuration to learn a new expression language.

License

This project is licensed under MIT license.

About

A javascript library for parsing rsql expressions into predicates.

Resources

License

Stars

Watchers

Forks

Packages

No packages published