Packages

  • package root

    Scallion is a library for easily writing LL(1) parsers in Scala, with support for pretty printing.

    Overview

    Scallion is a library for easily writing LL(1) parsers in Scala, with support for pretty printing. See the package scallion for more information.

    Definition Classes
    root
  • package scallion

    This package is used to describe syntax for LL(1) languages.

    This package is used to describe syntax for LL(1) languages.

    To use the package, mix-in the scallion.Parsers trait.

    object MyParser extends Parsers {
    
      // Type of tokens.
      type Token = MyToken
    
      // Type of token kinds.
      type Kind = MyKind
    
      // Define the token kind of tokens.
      override def getKind(token: Token): Kind = ...
    
      // Then define your syntax using combinators.
      lazy val mySyntax = ...
    }
    Definition Classes
    root
  • package util
  • package visualization
  • Debug
  • Enumeration
  • Operators
  • PairDecorator
  • Parsers
  • Parsing
  • PrettyPrinting
  • Syntaxes
  • ~
p

scallion

package scallion

This package is used to describe syntax for LL(1) languages.

To use the package, mix-in the scallion.Parsers trait.

object MyParser extends Parsers {

  // Type of tokens.
  type Token = MyToken

  // Type of token kinds.
  type Kind = MyKind

  // Define the token kind of tokens.
  override def getKind(token: Token): Kind = ...

  // Then define your syntax using combinators.
  lazy val mySyntax = ...
}
Source
package.scala
Linear Supertypes
AnyRef, Any

Type Members

  1. trait Debug extends AnyRef

    Contains methods to produce reports to help debug LL(1) conflicts in syntaxes.

  2. trait Enumeration extends AnyRef

    Provides enumeration capabilites to syntaxes.

  3. trait Operators extends AnyRef

    Contains utilities to write syntaxes with infix, prefix and postfix operators.

    Contains utilities to write syntaxes with infix, prefix and postfix operators. Expected to be mixed-in to Syntaxes.

    Example

    The following example shows how to build a syntax for a language with unary operators and infix operators of different priority levels.

    // Syntax for basic expressions, which are our operands.
    lazy val basic: Syntax[Expr] = number | open.skip ~ value ~ close.skip
    
    // Syntax for postfix application of an operator.
    lazy val postfixed: Syntax[Expr] = postfixes(basic, fac)({
      // Indicates how to apply the operator.
      case (e, op) => UnaryExpr(op, e)
    }, {
      // Optionally, indicates how to unapply an operator.
      // This is only used for pretty printing.
      case UnaryExpr(op, e) => (e, op)
    })
    
    // Syntax for infix application of various operators.
    lazy val value: Syntax[Expr] = recursive {
    
      // In this case, our operands are postfixed basic expressions.
      operators(postfixed)(
        // Indicates the various operators and their associativity.
        // First level in multiplication and division, which are
        // left associative and bind the strongest.
        times | div is LeftAssociative,
    
        // On the next priority level are addition and subtraction,
        // which are also left associative.
        plus | minus is LeftAssociative
      )({
        // Indicates how to apply a binary operator.
        case (l, op, r) => BinaryExpr(op, l, r)
      }, {
        // Optionally, indicates how to unapply a binary operator.
        // This is only used for pretty printing.
        case BinaryExpr(op, l, r) => (l, op, r)
      })
    }
  4. implicit class PairDecorator[A] extends AnyRef

    Adds an ~ methods to build pairs.

  5. trait Parsers extends Syntaxes with Parsing with Enumeration with PrettyPrinting with Operators with Debug

    Main trait for defining parsers.

  6. trait Parsing extends AnyRef

    This trait implements LL(1) parsing with derivatives.

  7. trait PrettyPrinting extends AnyRef

    Provides pretty printing capabilites to syntaxes.

  8. trait Syntaxes extends AnyRef

    Contains the definition of syntaxes.

  9. case class ~[+A, +B](_1: A, _2: B) extends Product with Serializable

    Simply a pair.

    Simply a pair.

    Can be used in infix position in pattern matching.

    _1

    First element.

    _2

    Second element.

Inherited from AnyRef

Inherited from Any

Parsing

Syntax

Debugging

Enumeration

Pretty Printing

Pairs

Ungrouped