All Projects → thautwarm → RBNF

thautwarm / RBNF

Licence: MIT license
This project's lifetime has ended. The successor is https://github.com/thautwarm/frontend-for-free which is WIP. You can check lark-parser project which is a good alt.

Programming Languages

python
139335 projects - #7 most used programming language
Jupyter Notebook
11667 projects

Projects that are alternatives of or similar to RBNF

nimly
Lexer Generator and Parser Generator as a Library in Nim.
Stars: ✭ 113 (+189.74%)
Mutual labels:  parser-generator, ebnf
YaccConstructor
Platform for parser generators and other grammarware research and development. GLL, RNGLR, graph parsing algorithms, and many others are included.
Stars: ✭ 36 (-7.69%)
Mutual labels:  parser-generator, ebnf
human-parser-generator
A straightforward recursive descent Parser Generator with a focus on "human" code generation and ease of use.
Stars: ✭ 27 (-30.77%)
Mutual labels:  parser-generator, ebnf
Covfefe
A parser for nondeterministic context free languages
Stars: ✭ 49 (+25.64%)
Mutual labels:  parser-generator, ebnf
ebnf
EBNF parser and generic parser generator for Ruby.
Stars: ✭ 101 (+158.97%)
Mutual labels:  parser-generator, ebnf
dropincc.java
A small and easy to use parser generator. Specify your grammar in pure java and compile dynamically. Especially suitable for DSL creation in java.
Stars: ✭ 90 (+130.77%)
Mutual labels:  parser-generator, ebnf
Reduce.jl
Symbolic parser generator for Julia language expressions using REDUCE algebra term rewriter
Stars: ✭ 172 (+341.03%)
Mutual labels:  parser-generator
lilt
LILT: noun, A characteristic rising and falling of the voice when speaking; a pleasant gentle accent.
Stars: ✭ 18 (-53.85%)
Mutual labels:  parser-generator
Npeg
PEGs for Nim, another take
Stars: ✭ 163 (+317.95%)
Mutual labels:  parser-generator
Lalrpop
LR(1) parser generator for Rust
Stars: ✭ 1,929 (+4846.15%)
Mutual labels:  parser-generator
parsesig
A Telegram bot that forwards messages from one private/public channel to another after formatting
Stars: ✭ 40 (+2.56%)
Mutual labels:  parser-generator
DirectFire Converter
DirectFire Firewall Converter - Network Security, Next-Generation Firewall Configuration Conversion, Firewall Syntax Translation and Firewall Migration Tool - supports Cisco ASA, Fortinet FortiGate (FortiOS), Juniper SRX (JunOS), SSG / Netscreen (ScreenOS) and WatchGuard (support for further devices in development). Similar to FortiConverter, Sm…
Stars: ✭ 34 (-12.82%)
Mutual labels:  parser-generator
ebnf2railroad
Create beautiful documentation for EBNF
Stars: ✭ 36 (-7.69%)
Mutual labels:  ebnf
Tatsu
竜 TatSu generates Python parsers from grammars in a variation of EBNF
Stars: ✭ 198 (+407.69%)
Mutual labels:  parser-generator
language-grammars
Syntax highlighting for ABNF/BNF/EBNF, Yacc, and other language-related languages.
Stars: ✭ 14 (-64.1%)
Mutual labels:  ebnf
Pegparser
💡 Build your own programming language! A C++17 PEG parser generator supporting parser combination, memoization, left-recursion and context-dependent grammars.
Stars: ✭ 164 (+320.51%)
Mutual labels:  parser-generator
lalr
Modern LALR(1) parser for C++
Stars: ✭ 56 (+43.59%)
Mutual labels:  parser-generator
Ecsharp
Home of LoycCore, the LES language of Loyc trees, the Enhanced C# parser, the LeMP macro preprocessor, and the LLLPG parser generator.
Stars: ✭ 141 (+261.54%)
Mutual labels:  parser-generator
nearley-playground
⛹ Write Grammars for the Nearley Parser!
Stars: ✭ 76 (+94.87%)
Mutual labels:  parser-generator
kison
A LALR(1)/LL(1)/LL(K) parser generator for javascript/typescript
Stars: ✭ 40 (+2.56%)
Mutual labels:  parser-generator

RBNF: Parser Generator for Context Sensitive Grammars

Build Status PyPI version MIT License

Tutorials

See Jupyter Notebook.

Preview

  • rbnf.zero: solution to processing complex texts. Similar to re.

    See source file Poly.rbnf.

    # parse polynomials from text.
    import rbnf.zero as ze
    ze_exp = ze.compile("import poly.[*]", use='Poly')
    print(ze_exp.match("2x^2 + 3 + 4 - 7 x^5 + 4 x + 5 x ^2 - x + 7 x ^ 11").result)

    Then we got output [(0, 7), (1, 3), (2, 7), (5, -7), (11, 7)].

  • CLI tool chains:

    λ rbnf.exe --help
    Available commands:
     cc
         rbnf source code compiler.
    
     - filename(positional or keyword arg)        : input source file
     - output(positional or keyword arg) = None   : output file name. default to be ...
     - name(positional or keyword arg) = 'unname' : name of language
    
     run
         You can apply immediate tests on your parser.
         P.S: use `--opt` option takes longer starting time.
    
     - filename(positional or keyword arg)    : python file generated by `rbnf` command, or rbnf sour file
     - opt(positional or keyword arg) = False : optimize switch
    
    
    
    λ printf "ignore [space]\nspace := R'\s+'\nterm := R'[^\s\(\)]+'\nsexpr ::= '(' sexpr* ')' | term" > lisp.rbnf
    λ rbnf run lisp
    
    type `:i` to switch between python mode and parsing mode.
    The last result of parsing is stored as symbol `res`.
    
    runbnf> (add 1 (add 2))
    
    sexpr[
          Tokenizer(name='auto_const', value='(', lineno=0, colno=0)
          sexpr[
                Tokenizer(name='term', value='add', lineno=0, colno=1)
          ]
          sexpr[
                Tokenizer(name='term', value='1', lineno=0, colno=5)
          ]
          sexpr[
                 Tokenizer(name='auto_const', value='(', lineno=0, colno=7)
                 sexpr[
                       Tokenizer(name='term', value='add', lineno=0, colno=8)
                 ]
                 sexpr[
                       Tokenizer(name='term', value='2', lineno=0, colno=12)
                 ]
                 Tokenizer(name='auto_const', value=')', lineno=0, colno=13)
          ]
          Tokenizer(name='auto_const', value=')', lineno=0, colno=14)
    ]
    
    runbnf> exit
    
    λ rbnf cc lisp.bnf -output lisp.py
    ...

Related

RBNF is leveraged to handle parsing tasks in some projects. Feel free to check them to get a better knowledge:

  • Yet Another Python Python:

    A Python bytecode compiler to provide custom extended syntaxes and optimization passes.
    This provides a parser for extended Python(compatible to Python 3.6.x-3.8.0).

    {"a" : a, "b": {"c": c}} = {"a": 1, "b": {"c": 2, **other2}, **others1}
    assert a == 1 and c == 2
  • Reley

    A haskell-like language implemented in Python. This provides a parser for a part of haskell.

      import operator (add, eq)
      import functools (reduce)
      import toolz (curry)
      import reley.prelude ((+))
    
      infix 5 (==)
      infix 0 ($)
      (==) = curry eq
      ($) a b = a b
      (+) = curry add
    
    
      m_sum lst = if lst == [] then 0
              else destruct lst
              where
                  destruct (a, b) = a + m_sum(b)
  • ReFining:

    A type checker.

    python cli.py
    
    reF> let x: 'a = 1 in
          fn x: 'a -> x ;;
    =>  (int`2 => int`2)
    
  • RMalt:

    A concise demo of intepreter implementation.

    python test.py
    
    malt> let (%+) = (l, r) -> (l + r) % r;;
    malt> let f = (a, b) -> a  + b;;
    malt> f 1 2;;
    =>  3
    malt> f 1
          ;;
    =>  Fn(b)<id=3061211909288>
    malt> infix %+ 5;;
    =>  5
    malt> let (%+) = (l, r) -> (l % r) + r;;
    malt> 5 %+ 6;;
    =>  11
    
    

EDSL in Python

To be continue.

RBNF's compiler(rbnf -> python or others) relies on bootstrap.

Actually, in current version, bootstrap of RBNF is implemented in EDSL.

See rbnf bootstrap in Python.

A snippet could be previewed here.

rbnf = Language("RBNF")

...

@rbnf
class Primitive(Parser):

    @classmethod
    def bnf(cls):
        # @formatter:off
        return optimize(
                 C('(') + Or @ "or_" + C(')')
               | C('[') + Or @ "optional" + C(']')
               | Name @ "name"
               | Str  @ "str")
        # @formatter:on

     @classmethod
    def rewrite(cls, state: State):
        get = state.ctx.get
        or_: Parser = get('or_')
        optional: Parser = get('optional')
        ...

...

Other backend

To be continue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].