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 = ...
}

Attributes

Members list

Packages

package scallion.util

Grouped members

Parsing

Main trait for defining parsers.

Main trait for defining parsers.

Attributes

Supertypes
trait Debug
trait Operators
trait Enumeration
trait Parsing
trait Syntaxes
class Object
trait Matchable
class Any
Show all

Syntax

trait Operators

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

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)
 })
}

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Parsers
Self type

Debugging

trait Debug

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

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

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Parsers
Self type

Enumeration

trait Enumeration

Provides enumeration capabilites to syntaxes.

Provides enumeration capabilites to syntaxes.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Parsers
Self type

Pretty Printing

Provides pretty printing capabilites to syntaxes.

Provides pretty printing capabilites to syntaxes.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Parsers
Self type

Pairs

implicit class PairDecorator[A](first: A)

Adds an ~ methods to build pairs.

Adds an ~ methods to build pairs.

Attributes

Supertypes
class Object
trait Matchable
class Any
final implicit def PairDecorator[A](first: A): PairDecorator[A]

Adds an ~ methods to build pairs.

Adds an ~ methods to build pairs.

Attributes

case class ~[+A, +B](_1: A, _2: B)

Simply a pair.

Simply a pair.

Can be used in infix position in pattern matching.

Value parameters

_1

First element.

_2

Second element.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Type members

Classlikes

trait Parsing

This trait implements LL(1) parsing with derivatives.

This trait implements LL(1) parsing with derivatives.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Parsers
Self type
trait Syntaxes

Contains the definition of syntaxes.

Contains the definition of syntaxes.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Parsers