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
    Definition Classes
    scallion
  • package visualization
    Definition Classes
    scallion
  • Debug
  • Enumeration
  • Operators
  • PairDecorator
  • Parsers
  • Parsing
  • PrettyPrinting
  • Syntaxes
  • ~
t

scallion

Parsers

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

Main trait for defining parsers.

Source
package.scala
Linear Supertypes
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. Parsers
  2. Debug
  3. Operators
  4. PrettyPrinting
  5. Enumeration
  6. Parsing
  7. Syntaxes
  8. AnyRef
  9. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. sealed trait Associativity extends AnyRef

    Associativity of an operator.

    Associativity of an operator.

    Definition Classes
    Operators
  2. case class Level[Op](operator: (Operators.this)#Syntax[Op], associativity: (Operators.this)#Associativity) extends Product with Serializable

    Represents a precedence level with a syntax for the various operators of that level and an associativity.

    Represents a precedence level with a syntax for the various operators of that level and an associativity.

    Definition Classes
    Operators
  3. implicit class LevelDecorator[Op] extends AnyRef

    Implicitly decorates an operator syntax to add an is method that indicates the associativity of the operator.

    Implicitly decorates an operator syntax to add an is method that indicates the associativity of the operator.

    Example

    val level = div | times is LeftAssociative
    Definition Classes
    Operators
  4. abstract type Kind

    Type of kinds.

    Type of kinds.

    Definition Classes
    Syntaxes
  5. type Mark = String

    Type of markings.

    Type of markings.

    Definition Classes
    Syntaxes
  6. type RecId = Int

    Unique identifier for Recursive syntaxes.

    Unique identifier for Recursive syntaxes.

    Definition Classes
    Syntaxes
  7. abstract type Token

    Type of tokens.

    Type of tokens.

    Definition Classes
    Syntaxes
  8. sealed trait Conflict extends AnyRef

    Describes a LL(1) conflict.

    Describes a LL(1) conflict.

    Definition Classes
    Parsing
  9. case class ConflictException(conflicts: Set[(Parsing.this)#Conflict]) extends Exception with Product with Serializable

    Indicates that a syntax is not LL(1) due to various conflicts.

    Indicates that a syntax is not LL(1) due to various conflicts.

    Definition Classes
    Parsing
  10. sealed trait ParseResult[A] extends AnyRef

    Result of parsing.

    Result of parsing.

    Definition Classes
    Parsing
  11. case class Parsed[A](value: A, rest: (Parsing.this)#Parser[A]) extends (Parsing.this)#ParseResult[A] with Product with Serializable

    Indicates that the input has been fully parsed, resulting in a value.

    Indicates that the input has been fully parsed, resulting in a value.

    A parser for subsequent input is also provided.

    value

    The value produced.

    rest

    Parser for more input.

    Definition Classes
    Parsing
  12. sealed trait Parser[A] extends AnyRef

    LL(1) parser.

    LL(1) parser.

    Definition Classes
    Parsing
  13. case class Properties[A](nullable: Option[A], first: Set[(Parsing.this)#Kind], shouldNotFollow: Set[(Parsing.this)#Kind], conflicts: Set[(Parsing.this)#Conflict]) extends Product with Serializable

    Contains properties of syntaxes.

    Contains properties of syntaxes.

    nullable

    A value associated to the empty string, if any.

    first

    The set of token kinds that can start valid sequences.

    shouldNotFollow

    The set of token kinds that should not follow in sequence.

    conflicts

    The set of LL(1) conflicts of the syntax.

    Definition Classes
    Parsing
  14. case class UnexpectedEnd[A](rest: (Parsing.this)#Parser[A]) extends (Parsing.this)#ParseResult[A] with Product with Serializable

    Indicates that end of input was unexpectedly encountered.

    Indicates that end of input was unexpectedly encountered.

    The syntax for subsequent input is provided.

    Definition Classes
    Parsing
  15. case class UnexpectedToken[A](token: (Parsing.this)#Token, rest: (Parsing.this)#Parser[A]) extends (Parsing.this)#ParseResult[A] with Product with Serializable

    Indicates that the provided token was not expected at that point.

    Indicates that the provided token was not expected at that point.

    The parser at the point of error is returned.

    token

    The token at fault.

    rest

    Parser at the point of error.

    Definition Classes
    Parsing
  16. trait PrettyPrinter[A] extends AnyRef

    Pretty printer of values.

    Pretty printer of values.

    Definition Classes
    PrettyPrinting
  17. case class Skip(syntax: Syntax[Unit]) extends Product with Serializable

    Wrapper around a Syntax indicating that values from the inner syntax should be ignored when building up sequences using ~.

    Wrapper around a Syntax indicating that values from the inner syntax should be ignored when building up sequences using ~.

    syntax

    The wrapped syntax.

    Definition Classes
    Syntaxes
  18. sealed trait Syntax[A] extends AnyRef

    Represents a syntax.

    Represents a syntax.

    Acts as both a parser and a pretty printer.

    A

    the type of values that can be produced or printed.

    Definition Classes
    Syntaxes
  19. trait Uninteresting[A] extends AnyRef

    Typeclass to denote that values of a given type are uninteresting and can be safely ignored while describing a syntax.

    Typeclass to denote that values of a given type are uninteresting and can be safely ignored while describing a syntax.

    Definition Classes
    Syntaxes
    Annotations
    @implicitNotFound( ... )
  20. trait UnsafeImplicits extends AnyRef

    Low priority implicits.

    Low priority implicits. Contains an instance for Uninteresting for every type.

    Definition Classes
    Syntaxes

Abstract Value Members

  1. abstract def getKind(token: Token): Kind

    Returns the kind associated with token.

    Returns the kind associated with token.

    Definition Classes
    Syntaxes

Concrete Value Members

  1. object Enumerator

    Factory of iterators over sequences accepted by a syntax.

    Factory of iterators over sequences accepted by a syntax.

    Definition Classes
    Enumeration
  2. object LeftAssociative extends (Operators.this)#Associativity with Product with Serializable

    Left-associativity.

    Left-associativity.

    Definition Classes
    Operators
  3. object RightAssociative extends (Operators.this)#Associativity with Product with Serializable

    Right-associativity.

    Right-associativity.

    Definition Classes
    Operators
  4. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  5. final def ##(): Int
    Definition Classes
    AnyRef → Any
  6. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  7. def accept[A](kind: Kind)(function: PartialFunction[Token, A], inverse: (A) ⇒ Seq[Token] = (x: A) => Seq()): Syntax[A]

    Syntax that describes a single token of the provided kind, and that directly applies a function on the successfully parsed token.

    Syntax that describes a single token of the provided kind, and that directly applies a function on the successfully parsed token.

    Definition Classes
    Syntaxes
  8. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  9. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  10. def debug[A](syntax: Syntax[A], showTrails: Boolean = true, ansi: Boolean = true): Unit

    Prints a report of LL(1) conflicts in the syntax.

    Prints a report of LL(1) conflicts in the syntax.

    Definition Classes
    Debug
  11. def debugString[A](syntax: Syntax[A], showTrails: Boolean = true, ansi: Boolean = true): String

    Returns a report of LL(1) conflicts in the syntax.

    Returns a report of LL(1) conflicts in the syntax.

    Definition Classes
    Debug
  12. def elem(kind: Kind): Syntax[Token]

    Syntax that describes a single token of the provided kind.

    Syntax that describes a single token of the provided kind.

    Definition Classes
    Syntaxes
  13. def epsilon[A](value: A): Syntax[A]

    Syntax that produces the given value to the empty sequence of tokens.

    Syntax that produces the given value to the empty sequence of tokens.

    Definition Classes
    Syntaxes
  14. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  16. def failure[A]: Syntax[A]

    Empty syntax.

    Empty syntax.

    Definition Classes
    Syntaxes
  17. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  18. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  19. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  20. def infixLeft[Op, A](elem: Syntax[A], op: Syntax[Op])(function: (A, Op, A) ⇒ A, inverse: PartialFunction[A, (A, Op, A)] = PartialFunction.empty): Syntax[A]

    Syntax that represents repetitions of elem separated by left-associative op.

    Syntax that represents repetitions of elem separated by left-associative op. The value returned is reduced left-to-right.

    Example

    val binaryOp: Syntax[Operator] = ...
    val operand: Syntax[Expr] = ...
    
    val operationExpr = infixLeft(operand, binaryOp) {
      // Describes how to turn two values and an operator into a value.
      case (lhs, op, rhs) => BinaryExpr(op, lhs, rhs)
    }

    With inverse function, for pretty printing support:

    val binaryOp: Syntax[Operator] = ...
    val operand: Syntax[Expr] = ...
    
    val operationExpr = infixLeft(operand, binaryOp)({
      // Describes how to turn two values and an operator into a value.
      case (lhs, op, rhs) => BinaryExpr(op, lhs, rhs)
    }, {
      // Describes how to turn a `BinaryExpr` back to its components.
      case BinaryExpr(op, lhs, rhs) => (lhs, op, rhs)
    })
    elem

    Syntax for the operands.

    op

    Syntax for the operators.

    function

    Function to apply an operation.

    inverse

    Function to reverse an operation.

    Definition Classes
    Operators
  21. def infixRight[Op, A](elem: Syntax[A], op: Syntax[Op])(function: (A, Op, A) ⇒ A, inverse: PartialFunction[A, (A, Op, A)] = PartialFunction.empty): Syntax[A]

    Syntax that represents repetitions of elem separated by right-associative op.

    Syntax that represents repetitions of elem separated by right-associative op. The value returned is reduced right-to-left.

    Example

    val binaryOp: Syntax[Operator] = ...
    val operand: Syntax[Expr] = ...
    
    val operationExpr = infixRight(operand, binaryOp) {
      // Describes how to turn two values and an operator into a value.
      case (lhs, op, rhs) => BinaryExpr(op, lhs, rhs)
    }

    With inverse function, for pretty printing support:

    val binaryOp: Syntax[Operator] = ...
    val operand: Syntax[Expr] = ...
    
    val operationExpr = infixRight(operand, binaryOp)({
      // Describes how to turn two values and an operator into a value.
      case (lhs, op, rhs) => BinaryExpr(op, lhs, rhs)
    }, {
      // Describes how to turn a `BinaryExpr` back to its components.
      case BinaryExpr(op, lhs, rhs) => (lhs, op, rhs)
    })
    elem

    Syntax for the operands.

    op

    Syntax for the operators.

    function

    Function to apply an operation.

    inverse

    Function to reverse an operation. *

    Definition Classes
    Operators
  22. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  23. def many[A](rep: Syntax[A], mark: Option[Mark] = None): Syntax[Seq[A]]

    Syntax that represents 0 or more repetitions of the rep syntax.

    Syntax that represents 0 or more repetitions of the rep syntax.

    Definition Classes
    Syntaxes
  24. def many1[A](rep: Syntax[A], mark: Option[Mark] = None): Syntax[Seq[A]]

    Syntax that represents 1 or more repetitions of the rep syntax.

    Syntax that represents 1 or more repetitions of the rep syntax.

    Definition Classes
    Syntaxes
  25. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  26. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  27. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  28. def oneOf[A](syntaxes: Syntax[A]*): Syntax[A]

    Syntax that represents the disjunction of several syntaxes.

    Syntax that represents the disjunction of several syntaxes.

    Definition Classes
    Syntaxes
  29. def operators[Op, A](elem: Syntax[A])(levels: Level[Op]*)(function: (A, Op, A) ⇒ A, inverse: PartialFunction[A, (A, Op, A)] = PartialFunction.empty): Syntax[A]

    Syntax that represents repetitions of elem separated by infix operators.

    Syntax that represents repetitions of elem separated by infix operators.

    The operators in earlier levels are considered to bind tighter than those in later levels.

    Example

    val andOp: Syntax[Operator]
    val orOp: Syntax[Operator]
    val implyOr: Syntax[Operator]
    
    val operand: Syntax[Expr]
    
    val operationExpr = operators(operand)(
      // The "and" operation binds the strongest.
      andOp is LeftAssociative,
    
      // Then, the "or" operation.
      orOp is LeftAssociative,
    
      // Finally, the "imply" operation, which is right associative.
      implyOr is RightAssociative
    )({
      // Defines how to turn two values and an operator into a value.
      case (lhs, op, rhs) => BinaryExpr(op, lhs, rhs)
    }, {
      // Optionally, defines how to turn a value back into its components.
      // This part is only needed if you want to support pretty printing.
      case BinaryExpr(op, lhs, rhs) => (lhs, op, rhs)
    })

    If multiple operators share the same priority level, you can simply combine them using | before specifying the associativity:

    val operationExpr = operators(operand)(
      // First, multiplication and division, at the same priority level.
      timesOp | divOp is LeftAssociative,
    
      // Then, addition and substraction, at the next priority level.
      plusOp | minusOp is LeftAssociative
    )({
      case (lhs, op, rhs) => BinaryExpr(op, lhs, rhs)
    }, {
      case BinaryExpr(op, lhs, rhs) => (lhs, op, rhs)
    })
    elem

    Syntax for the operands.

    levels

    Operators (with associativity), in decreasing priority.

    function

    Function to apply an operation.

    inverse

    Function to reverse an operation.

    Definition Classes
    Operators
  30. def opt[A](syntax: Syntax[A]): Syntax[Option[A]]

    Syntax that represents 0 or 1 instances of the syntax.

    Syntax that represents 0 or 1 instances of the syntax.

    Definition Classes
    Syntaxes
  31. def postfixes[Op, A](elem: Syntax[A], op: Syntax[Op])(function: (A, Op) ⇒ A, inverse: PartialFunction[A, (A, Op)] = PartialFunction.empty): Syntax[A]

    Syntax that represents elem postfixed by any number of op.

    Syntax that represents elem postfixed by any number of op.

    Operators are applied left-to-right.

    Example

    val simpleExpr: Syntax[Expr] = ...
    val unaryOps: Syntax[Operator] = ...
    
    val postfixedExpr = postfixes(simpleExpr, unaryOps) {
      // Defines how to convert an `expr` and an `op` into a `Unary` expression.
      case (expr, op) => Unary(op, expr)
    }

    With inverse function, for pretty printing support:

    val simpleExpr: Syntax[Expr] = ...
    val unaryOps: Syntax[Operator] = ...
    
    val postfixedExpr = postfixes(simpleExpr, unaryOps)({
      // Defines how to convert an `expr` and an `op` into a `Unary` expression.
      case (expr, op) => Unary(op, expr)
    }, {
      // Defines how to convert a `Unary` expression into its components.
      case Unary(op, expr) => (expr, op)
    })
    elem

    Syntax for the operands.

    op

    Syntax for the operators.

    function

    Function to apply an operation.

    inverse

    Function to reverse an operation.

    Definition Classes
    Operators
  32. def prefixes[Op, A](op: Syntax[Op], elem: Syntax[A])(function: (Op, A) ⇒ A, inverse: PartialFunction[A, (Op, A)] = PartialFunction.empty): Syntax[A]

    Syntax that represents elem prefixed by any number of op.

    Syntax that represents elem prefixed by any number of op.

    Operators are applied right-to-left.

    Example

    val simpleExpr: Syntax[Expr] = ...
    val unaryOps: Syntax[Operator] = ...
    
    val prefixedExpr = prefixes(unaryOps, simpleExpr) {
      // Defines how to convert an `op` and an `expr` into an `expr`.
      case (op, expr) => Unary(op, expr)
    }

    With inverse function, for pretty printing support:

    val simpleExpr: Syntax[Expr] = ...
    val unaryOps: Syntax[Operator] = ...
    
    val prefixedExpr = prefixes(unaryOps, simpleExpr)({
      // Defines how to convert an `op` and an `expr` into a `Unary` expression.
      case (op, expr) => Unary(op, expr)
    }, {
      // Defines how to convert a `Unary` expression into its components.
      case Unary(op, expr) => (op, expr)
    })
    op

    Syntax for the operators.

    elem

    Syntax for the operands.

    function

    Function to apply an operation.

    inverse

    Function to reverse an operation.

    Definition Classes
    Operators
  33. def recursive[A](syntax: ⇒ Syntax[A]): Syntax[A]

    Indicates that the syntax can refer to itself within its body.

    Indicates that the syntax can refer to itself within its body.

    Definition Classes
    Syntaxes
  34. def rep1sep[A, B](rep: Syntax[A], sep: Syntax[B]): Syntax[Seq[A]]

    [use case] Syntax that represents 1 or more repetitions of the rep syntax, separated by sep.

    [use case]

    Syntax that represents 1 or more repetitions of the rep syntax, separated by sep.

    Definition Classes
    Syntaxes
    Full Signature

    def rep1sep[A, B](rep: Syntax[A], sep: Syntax[B], mark: Option[Mark] = None)(implicit ev: Uninteresting[B]): Syntax[Seq[A]]

  35. def repsep[A, B](rep: Syntax[A], sep: Syntax[B]): Syntax[Seq[A]]

    [use case] Syntax that represents 0 or more repetitions of the rep syntax, separated by sep.

    [use case]

    Syntax that represents 0 or more repetitions of the rep syntax, separated by sep.

    Definition Classes
    Syntaxes
    Full Signature

    def repsep[A, B](rep: Syntax[A], sep: Syntax[B], mark: Option[Mark] = None)(implicit ev: Uninteresting[B]): Syntax[Seq[A]]

  36. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  37. implicit def syntaxToLL1Properties[A](syntax: Syntax[A]): Properties[A]

    Decorates syntaxes with methods for LL(1) properties.

    Decorates syntaxes with methods for LL(1) properties.

    Definition Classes
    Parsing
  38. def toString(): String
    Definition Classes
    AnyRef → Any
  39. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  40. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  41. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  42. object Conflict

    Contains the description of the various LL(1) conflicts.

    Contains the description of the various LL(1) conflicts.

    Definition Classes
    Parsing
  43. object Parser

    Factory of LL(1) parsers.

    Factory of LL(1) parsers.

    Definition Classes
    Parsing
  44. object PrettyPrinter

    Factory of pretty printers.

    Factory of pretty printers.

    Definition Classes
    PrettyPrinting
  45. object Implicits extends UnsafeImplicits

    Contains an instance for Uninteresting for every type.

    Contains an instance for Uninteresting for every type. The Uninteresting instance for Unit is distinct.

    Definition Classes
    Syntaxes
  46. object SafeImplicits

    Contains the instance for Uninteresting of Unit.

    Contains the instance for Uninteresting of Unit.

    Definition Classes
    Syntaxes
  47. object Syntax

    Contains primitive basic syntaxes and syntax combinators.

    Contains primitive basic syntaxes and syntax combinators.

    Definition Classes
    Syntaxes

Inherited from Debug

Inherited from Operators

Inherited from PrettyPrinting

Inherited from Enumeration

Inherited from Parsing

Inherited from Syntaxes

Inherited from AnyRef

Inherited from Any

Abstract Members

Parsing

Syntax

Parse Results

Basic Syntaxes

Combinators

Priority Levels

Priority levels for the operators combinator.

Associativity

Associativity for priority levels.

Properties

LL(1) Conflicts

Debugging

Enumeration

Pretty Printing

Implicits

Others

Ungrouped