Giter Site home page Giter Site logo

oele-grammar's Introduction

oele-grammar

This is the grammar for oele.

Goal

The goal of this project is to parse statements written in the Okta Expression Language for correctness. Since this is a WIP, it will just be an Okay expression language evaluator for now.

Defined in this source code is a Moo tokenizer/lexer and a grammar using Nearley syntax. Nearley is then used to parse the expression.

Supported Expressions

  • AND, OR
  • !=, ==, >, <, >=, <=

with more on the way!

How to use

The code below follows the Nearly docs on how to use a parser

import nearley from 'nearley';
import grammar from './dist/grammar.cjs';

const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));

// Streaming parser, can feed multiple lines
parser.feed('user.name == "John" AND user.age > 18');

// To query the results of the parser and print out the whole structure
console.dir(parser.results, { depth: null });

Note: parser.results is an array, but it will always be length 1 if this grammar is correctly unambigious

The structure of the output is still in flux as the grammar develops. I'd like to produce an abstract syntax tree and maybe have an interface that does not require interacting directly with Nearly - just one import, send in expression, get AST back.

Developing

Once you've cloned the project, install dependencies with npm install (or pnpm install or yarn). This project uses Nearley to compile and test the grammar. To compile the grammar into JavaScript:

npm run compile

Once you've compile the grammar, you can run the index.js file in the project to see an example parsed with the grammar.

node index.js

Nearley comes with a test command, but it leaves a lot to be desired when it comes to supporting the running of test cases and comparisons against expected values. I've linked it up to npm scripts, but it won't help much at the moment. Watch this space.

npm run test

oele-grammar's People

Contributors

mgarbacz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.