Giter VIP home page Giter VIP logo

kanonic's Introduction

Kanonic

Kanonic is a fast LR(1) parser generator operating on the JVM.

While Java is understood to be the language of the software industry, there hasn't been an adequate parser generator operating on the JVM that accomplishes one of the main pre-requisites for companies: speed. This project aims to tackle this problem by leveraging the speed and expressiveness of LR(1) grammars.

About

Check out Kanonic's Documentation for information regarding the Kanonic syntax, example usage, code generation, and more!

Status

This project is a work-in-progress and should be considered experimental.

Building

./gradlew clean assemble

Using the Tool

First, you'll need to install the kanonic command:

./gradlew :kanonic-tool:install

Then, run the command on a Kanonic file:

./kanonic-tool/build/install/kanonic-tool/bin/kanonic ./examples/calculator.knc

Or, see more options:

./kanonic-tool/build/install/kanonic-tool/bin/kanonic --help

Please see the documentation for more information!

kanonic's People

Contributors

aeram0 avatar johnedquinn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

aeram0

kanonic's Issues

Add Grammar to ParserMetadata

When parsing, we currently need to pass the grammar itself AND the ParserMetadata to the KanonicParser. Ideally, we only pass the ParserMetadata (generated). So, we need to either:

  • Serialize the Grammar and generate the file
  • Or, a much easier approach, generate the Grammar DSL to create the grammar.

Make KanonicLexer better

So, right now, it's a dumb lever, and it needs to be smarter. It does most things well enough, but for some edge cases, it doesn't work. Formalize the Lexer and make it better.

Add build step to generate syntax parser

Right now, we install the partial-syntax command, and we run it manually. Ideally, this would be a build step after building runtime and gen but before tool.

Modify regex for tokens/rules

Change the regexes for the following:

  • Token: "[A-Z][A-Z_]*"
  • Rule: "[a-z][a-z_]*"

Then, make the code generation pretty by splitting on the _.

Top-level groups cause generated node issue

In below, since the root is expr, and since one of expr's variants, symbol, is a group, it cause the root to be a generated node. Causing issues, since we can't visit a generated node. Needs research. Likely in the AstConverter.

kanonic: {
  name: ion;
  root: expr;
  package: "io.johnedquinn.ion.generated";
};

COLON: ":";
PAREN_LEFT: "\(";
PAREN_RIGHT: "\)";
SYMBOL_QUOTED: "'((\')|[^'])*'";
SYMBOL: "[a-zA-Z]+";
NUMBER: "[0-9]+";
LITERAL_STRING: "\"((\")|[^\"])*\"";

expr
	: annotation? expr --> annotated_expr
	| NUMBER --> number
	| PAREN_LEFT expr+ PAREN_RIGHT --> sexp
	| ( SYMBOL | SYMBOL_QUOTED ) --> symbol
	| LITERAL_STRING --> string
	;

Modify child functions to return a single node or multiple depending on count

For rule:

some_rule
    : other_rule PLUS other_rule --> rule_name
    ;

The generate rule looks like:

data class RuleName(...) : SomeRule(...) {
    public fun otherRule(): List<OtherRule> = {...}
    public fun PLUS(): List<TerminalNode> = {...}
}

But, we KNOW that only a single PLUS can be present, so, the function should be:

    public fun PLUS(): TerminalNode = {...}

We need to account for generated/hidden nodes while counting too.

Add alias/name to variant items

ANTLR allows:

topRule:
    : key=IDENT EQUALS value=IDENT # IdentEqualsIdent
    | key=IDENT EQUALS ref=someOtherRule # IdentEqualsRef
    ;

Handle groups and repeating groups

We need to handle groups and repeating groups:

expr
    : expr (PLUS | MINUS | ASTERISK) atomic --> arithmeticExpr
    | expr ( PERIOD expr )+ --> indexingExpr
    ;

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.