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
  • ε
c

org.benknoble.ebnf

Nonterminal

case class Nonterminal(name: Symbol) extends Word with Product with Serializable

A nonterminal symbol of the grammar

Nonterminals look like <Name>:

scala> import org.benknoble.ebnf._
import org.benknoble.ebnf._

scala> val n = Nonterminal('A).format
n: String = <A>
name

the name of the Nonterminal

Linear Supertypes
Serializable, Serializable, Product, Equals, Word, Expr, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Nonterminal
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. Word
  7. Expr
  8. AnyRef
  9. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Nonterminal(name: Symbol)

    create a new Nonterminal with a name

    create a new Nonterminal with a name

    name

    the name of the Nonterminal

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def *(): Expr

    Returns a org.benknoble.ebnf.Repetition of this

    Definition Classes
    Expr
  4. def ::=(rule: Expr): Production

    Syntactic sugar to create org.benknoble.ebnf.Productions:

    Syntactic sugar to create org.benknoble.ebnf.Productions:

    scala> import org.benknoble.ebnf._
    import org.benknoble.ebnf._
    
    scala> val p = Nonterminal('A) ::= Terminal("a")
    p: org.benknoble.ebnf.Production = Production(Nonterminal('A), Terminal(a))
    rule

    the right hand side of a production

    returns

    an org.benknoble.ebnf.Production of this ::= rule

  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. def ?(): Expr

    Returns a org.benknoble.ebnf.Option of this

    Returns a org.benknoble.ebnf.Option of this

    Definition Classes
    Expr
  7. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  8. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  9. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  10. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. 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

    Definition Classes
    NonterminalExpr
  12. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. val name: Symbol
  15. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  18. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  19. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  22. def ||(right: Expr): Expr

    Returns an org.benknoble.ebnf.Alternation

    right

    the right side of the branch

    Definition Classes
    Expr
  23. def ~(right: Expr): Expr

    Returns a org.benknoble.ebnf.Sequence

    right

    the next item in the sequence

    Definition Classes
    Expr

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from Word

Inherited from Expr

Inherited from AnyRef

Inherited from Any

Ungrouped