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

object Grammar

Factory for org.benknoble.ebnf.Grammar instances.

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

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def apply(productions: Production*): Grammar

    Creates a Grammar with the given productions

    Creates a Grammar with the given productions

    productions

    the productions

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  17. def toString(): String
    Definition Classes
    AnyRef → Any
  18. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped