Packages

  • package root
    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package benknoble
    Definition Classes
    org
  • package ebnf

    Provides classes for dealing with context-free grammars in EBNF form.

    Provides classes for dealing with context-free grammars in EBNF form.

    Provides a org.benknoble.ebnf.Grammar model, complete with scala DSL for creating complex grammars in code, and an org.benknoble.ebnf.EbnfParser to generate Grammars from a String.

    Overview

    The main class is org.benknoble.ebnf.Grammar:

    scala> val grammar = Grammar(
         |   new Production(
         |     Nonterminal('A),
         |     Alternation(Nonterminal('A),
         |     Sequence(Repetition(Terminal("abc")), Option(Terminal("def"))))))
    grammar: org.benknoble.ebnf.Grammar = Grammar(List(Production(Nonterminal('A), Alternation(Nonterminal('A),Sequence(Repetition(Terminal(abc)),Option(Terminal(def)))))))
    
    scala> val s = grammar.format
    s: String = <A> ::= <A>|{'abc'}['def'] ;

    If you include org.benknoble.ebnf.ExprImplicits and take advantage of org.benknoble.ebnf.Expr syntax, it looks a lot cleaner:

    scala> val grammar = Grammar('A ::= 'A || Terminal("abc").* ~ "def".?)
    grammar: org.benknoble.ebnf.Grammar = Grammar(List(Production(Nonterminal('A), Alternation(Nonterminal('A),Sequence(Repetition(Terminal(abc)),Option(Terminal(def)))))))
    
    scala> val s = grammar.format
    s: String = <A> ::= <A>|{'abc'}['def'] ;

    Finally, you can take advantage of org.benknoble.ebnf.EbnfParser:

    scala> val grammar = EbnfParser("<A> ::= <A>|{'abc'}['def'] ;")
    grammar: Either[String,org.benknoble.ebnf.Grammar] = Right(Grammar(List(Production(Nonterminal('A), Alternation(Nonterminal('A),Sequence(Repetition(Terminal(abc)),Option(Terminal(def))))))))
    
    scala> val msg = grammar.fold(s => s, g => g.format)
    msg: String = <A> ::= <A>|{'abc'}['def'] ;
    Definition Classes
    benknoble
  • Alternation
  • EbnfParser
  • Expr
  • ExprImplicits
  • Grammar
  • Main
  • Nonterminal
  • Option
  • Production
  • Repetition
  • Sequence
  • Terminal
  • Word
  • ε

abstract class Expr extends AnyRef

Base class for expressions

An expression is the right hand side of an EBNF rule, made of sequences, branches, repetitions, and options of terminal and nonterminal symbols. Each of these is represented by a concrete case class.

Provides methods common to all expressions.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Expr
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Expr()

Abstract Value Members

  1. abstract def format: String

    Returns a formatted version of this

    Returns a formatted version of this

    Sub-classes implement this to determine formatting.

    returns

    a print-able version in EBNF format

Concrete Value Members

  1. def *(): Expr

    Returns a org.benknoble.ebnf.Repetition of this

  2. def ?(): Expr

    Returns a org.benknoble.ebnf.Option of this

  3. def ||(right: Expr): Expr

    Returns an org.benknoble.ebnf.Alternation

    right

    the right side of the branch

  4. def ~(right: Expr): Expr

    Returns a org.benknoble.ebnf.Sequence

    right

    the next item in the sequence