Giter Club home page Giter Club logo

fling's Introduction

Fling is the first general and practical solution of the fluent API problem. The implementation includes an algorithm that takes a deterministic context free language (equivalently, LR(k), k≥0 language) and encodes it in an unbounded parametric polymorphism type system employing only a polynomial number of types. The theoretical result is employed in an actual tool Fling—a fluent API compiler-compiler in the venue of YACC, tailored for embedding DSLs in polymorphic, object-oriented languages.

Fling

Fling (fluent interfaces generator) is a parser generator. Instead of generating the code of a real-time parser, Fling generates Java fluent interfaces, which implement a compile-time parser of the given language. Fling accepts either LL(1) grammar or DPDA specifications; If a grammar is given, Fling also generates the AST class definitions used to compile a fluent API INVOCATION into an abstract parse tree at run-time.

Download jar

Full release (includes examples)

Documentation

Example

Let us define the Datalog grammar, in Java, using Fling's interface:

// Datalog grammar defined in BNF
BNF bnf = bnf().
      start(Program).
      derive(Program).to(oneOrMore(Statement)).
      specialize(Statement).into(Fact, Rule, Query).
      derive(Fact).to(fact.with(S), of.many(S)).
      derive(Query).to(query.with(S), of.many(Term)).
      specialize(Rule).into(Bodyless, WithBody).
      derive(Bodyless).to(always.with(S), of.many(Term)).
      derive(WithBody).to(RuleHead, RuleBody).
      derive(RuleHead).to(infer.with(S), of.many(Term)).
      derive(RuleBody).to(FirstClause, noneOrMore(AdditionalClause)).
      derive(FirstClause).to(when.with(S), of.many(Term)).
      derive(AdditionalClause).to(and.with(S), of.many(Term)).
      derive(Term).to(l.with(S)).or(v.with(S)).
      build();

After Fling has created the fluent interfaces supporting Datalog, a simple Datalog program...

parent(john, bob)
parent(bob, donald)
ancestor(A, B) := parent(A, B)
ancestor(A, B) := parent(A, C), ancestor(C, B)
ancestor(john, X)?

...can be written in Java by method-chaining, as follows:

Program program =
  fact("parent").of("john", "bob").
  fact("parent").of("bob", "donald").
  always("ancestor").of(l("adam"), v("X")).
  infer("ancestor").of(v("A"), v("B")).
    when("parent").of(v("A"), v("B")).
  infer("ancestor").of(v("A"), v("B")).
    when("parent").of(v("A"), v("C")).
    and("ancestor").of(v("C"), v("B")).
  query("ancestor").of(l("john"), v("X")).$();

The produced program is represented in Java as an abstract syntax tree (AST) that can be traversed and analyzed by the client library.

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.