Parser

amyc.parsing.Parser$
object Parser extends Pipeline[Iterator[Token], Program], Parsers

Attributes

Graph
Supertypes
trait Parsers
trait Debug
trait Operators
trait PrettyPrinting
trait Enumeration
trait Parsing
trait Syntaxes
class Pipeline[Iterator[Token], Program]
class Object
trait Matchable
class Any
Show all
Self type
Parser.type

Members list

Type members

Inherited classlikes

sealed trait Associativity

Associativity of an operator.

Associativity of an operator.

Attributes

Inherited from:
Operators
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object LeftAssociative.type
object RightAssociative.type
object Conflict

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

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

Attributes

Inherited from:
Parsing
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
sealed trait Conflict

Describes a LL(1) conflict.

Describes a LL(1) conflict.

Attributes

Inherited from:
Parsing
Supertypes
class Object
trait Matchable
class Any
case class ConflictException(conflicts: Set[Conflict]) extends Exception

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

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

Attributes

Inherited from:
Parsing
Supertypes
trait Product
trait Equals
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
object Enumerator

Factory of iterators over sequences accepted by a syntax.

Factory of iterators over sequences accepted by a syntax.

Attributes

Inherited from:
Enumeration
Supertypes
class Object
trait Matchable
class Any
object Implicits extends UnsafeImplicits

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

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

Attributes

Inherited from:
Syntaxes
Supertypes
class Object
trait Matchable
class Any
case object LeftAssociative extends Associativity

Left-associativity.

Left-associativity.

Attributes

Inherited from:
Operators
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class Level[Op](operator: Syntax[Op], associativity: Associativity)

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.

Attributes

Inherited from:
Operators
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
class LevelDecorator[Op](operator: Syntax[Op])

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

Attributes

Inherited from:
Operators
Supertypes
class Object
trait Matchable
class Any
sealed trait ParseResult[A]

Result of parsing.

Result of parsing.

Attributes

Inherited from:
Parsing
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Parsed[A]
class UnexpectedEnd[A]
class UnexpectedToken[A]
case class Parsed[A](value: A, rest: Parser[A]) extends ParseResult[A]

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 parameters

rest

Parser for more input.

value

The value produced.

Attributes

Inherited from:
Parsing
Supertypes
trait Serializable
trait Product
trait Equals
trait ParseResult[A]
class Object
trait Matchable
class Any
Show all
object Parser

Factory of LL(1) parsers.

Factory of LL(1) parsers.

Attributes

Inherited from:
Parsing
Supertypes
class Object
trait Matchable
class Any
sealed trait Parser[A]

LL(1) parser.

LL(1) parser.

Attributes

Inherited from:
Parsing
Supertypes
class Object
trait Matchable
class Any
object PrettyPrinter

Factory of pretty printers.

Factory of pretty printers.

Attributes

Inherited from:
PrettyPrinting
Supertypes
class Object
trait Matchable
class Any
trait PrettyPrinter[A]

Pretty printer of values.

Pretty printer of values.

Attributes

Inherited from:
PrettyPrinting
Supertypes
class Object
trait Matchable
class Any
case class Properties[A](nullable: Option[A], first: Set[Kind], shouldNotFollow: Set[Kind], conflicts: Set[Conflict])

Contains properties of syntaxes.

Contains properties of syntaxes.

Value parameters

conflicts

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

first

The set of token kinds that can start valid sequences.

nullable

A value associated to the empty string, if any.

shouldNotFollow

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

Attributes

Inherited from:
Parsing
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case object RightAssociative extends Associativity

Right-associativity.

Right-associativity.

Attributes

Inherited from:
Operators
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object SafeImplicits

Contains the instance for Uninteresting of Unit.

Contains the instance for Uninteresting of Unit.

Attributes

Inherited from:
Syntaxes
Supertypes
class Object
trait Matchable
class Any
case class Skip(syntax: Syntax[Unit])

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 ~.

Value parameters

syntax

The wrapped syntax.

Attributes

Inherited from:
Syntaxes
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Syntax

Contains primitive basic syntaxes and syntax combinators.

Contains primitive basic syntaxes and syntax combinators.

Attributes

Inherited from:
Syntaxes
Supertypes
class Object
trait Matchable
class Any
sealed trait Syntax[A]

Represents a syntax.

Represents a syntax.

Acts as both a parser and a pretty printer.

Type parameters

A

the type of values that can be produced or printed.

Attributes

Inherited from:
Syntaxes
Supertypes
class Object
trait Matchable
class Any
case class UnexpectedEnd[A](rest: Parser[A]) extends ParseResult[A]

Indicates that end of input was unexpectedly encountered.

Indicates that end of input was unexpectedly encountered.

The syntax for subsequent input is provided.

Value parameters

syntax

Syntax at the end of input.

Attributes

Inherited from:
Parsing
Supertypes
trait Serializable
trait Product
trait Equals
trait ParseResult[A]
class Object
trait Matchable
class Any
Show all
case class UnexpectedToken[A](token: Token, rest: Parser[A]) extends ParseResult[A]

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.

Value parameters

rest

Parser at the point of error.

token

The token at fault.

Attributes

Inherited from:
Parsing
Supertypes
trait Serializable
trait Product
trait Equals
trait ParseResult[A]
class Object
trait Matchable
class Any
Show all
trait Uninteresting[A]

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.

Attributes

Inherited from:
Syntaxes
Supertypes
class Object
trait Matchable
class Any

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

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

Attributes

Inherited from:
Syntaxes
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Implicits.type

Types

type Kind = TokenKind

Type of kinds.

Type of kinds.

Attributes

type Token = Token

Type of tokens.

Type of tokens.

Attributes

Inherited types

type Mark = String

Type of markings.

Type of markings.

Attributes

Inherited from:
Syntaxes
type RecId = Int

Unique identifier for Recursive syntaxes.

Unique identifier for Recursive syntaxes.

Attributes

Inherited from:
Syntaxes

Value members

Concrete methods

override def getKind(token: Token): TokenKind

Returns the kind associated with token.

Returns the kind associated with token.

Attributes

Definition Classes
Syntaxes
inline def inBrace[A](inline syntax: Syntax[A]): Syntax[A]
inline def inParenthesis[A](inline syntax: Syntax[A]): Syntax[A]
override def run(tokens: Iterator[Token])(using Context): Program

Attributes

Definition Classes

Inherited methods

def accept[A](kind: Kind)(function: PartialFunction[Token, A], inverse: A => Seq[Token]): 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.

Attributes

Inherited from:
Syntaxes
def andThen[G](thenn: Pipeline[Program, G]): Pipeline[F, G]

Attributes

Inherited from:
Pipeline
def debug[A](syntax: Syntax[A], showTrails: Boolean, ansi: Boolean): Unit

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

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

Attributes

Inherited from:
Debug
def debugString[A](syntax: Syntax[A], showTrails: Boolean, ansi: Boolean): String

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

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

Attributes

Inherited from:
Debug
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.

Attributes

Inherited from:
Syntaxes
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.

Attributes

Inherited from:
Syntaxes
def failure[A]: Syntax[A]

Empty syntax.

Empty syntax.

Attributes

Inherited from:
Syntaxes
def infixLeft[Op, A](elem: Syntax[A], op: Syntax[Op])(function: (A, Op, A) => A, inverse: PartialFunction[A, (A, Op, A)]): Syntax[A]

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

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

Value parameters

elem

Syntax for the operands.

function

Function to apply an operation.

inverse

Function to reverse an operation.

op

Syntax for the operators.

Attributes

Inherited from:
Operators
def infixRight[Op, A](elem: Syntax[A], op: Syntax[Op])(function: (A, Op, A) => A, inverse: PartialFunction[A, (A, Op, A)]): Syntax[A]

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

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

Value parameters

elem

Syntax for the operands.

function

Function to apply an operation.

inverse

Function to reverse an operation. *

op

Syntax for the operators.

Attributes

Inherited from:
Operators
def many[A](rep: Syntax[A], mark: Option[Mark]): 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.

Attributes

Inherited from:
Syntaxes
def many1[A](rep: Syntax[A], mark: Option[Mark]): 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.

Attributes

Inherited from:
Syntaxes
def oneOf[A](syntaxes: Syntax[A]*): Syntax[A]

Syntax that represents the disjunction of several syntaxes.

Syntax that represents the disjunction of several syntaxes.

Attributes

Inherited from:
Syntaxes
def operators[Op, A](elem: Syntax[A])(levels: Level[Op]*)(function: (A, Op, A) => A, inverse: PartialFunction[A, (A, Op, A)]): 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)
})

Value parameters

elem

Syntax for the operands.

function

Function to apply an operation.

inverse

Function to reverse an operation.

levels

Operators (with associativity), in decreasing priority.

Attributes

Inherited from:
Operators
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.

Attributes

Inherited from:
Syntaxes
def postfixes[Op, A](elem: Syntax[A], op: Syntax[Op])(function: (A, Op) => A, inverse: PartialFunction[A, (A, Op)]): 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)
})

Value parameters

elem

Syntax for the operands.

function

Function to apply an operation.

inverse

Function to reverse an operation.

op

Syntax for the operators.

Attributes

Inherited from:
Operators
def prefixes[Op, A](op: Syntax[Op], elem: Syntax[A])(function: (Op, A) => A, inverse: PartialFunction[A, (Op, A)]): 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)
})

Value parameters

elem

Syntax for the operands.

function

Function to apply an operation.

inverse

Function to reverse an operation.

op

Syntax for the operators.

Attributes

Inherited from:
Operators
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.

Attributes

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

Attributes

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

Attributes

Inherited from:
Syntaxes

Concrete fields

Attributes

lazy val args: Syntax[Seq[Expr]]

Attributes

Attributes

lazy val eof: Syntax[Token]
lazy val expr: Syntax[Expr]
lazy val factor: Syntax[Expr]
lazy val funDef: Syntax[FunDef]

Attributes

val identifier: Syntax[String]
lazy val ifExpression: Syntax[Expr]
lazy val ifOrBinary: Syntax[Expr]
lazy val l0_op: Syntax[String]
lazy val l1_op: Syntax[String]
lazy val l2_op: Syntax[String]
lazy val l3_op: Syntax[String]
lazy val l4_op: Syntax[String]
lazy val l5_op: Syntax[String]
lazy val l6_op: Syntax[String]
lazy val l7_op: Syntax[String]
lazy val l8_op: Syntax[String]
lazy val l9_op: Syntax[String]
lazy val literal: Syntax[Literal[Boolean | Int | String]]
lazy val minus: Syntax[String]
lazy val modifier: Syntax[String]
override val name: String
lazy val not: Syntax[String]
lazy val parameters: Syntax[List[ParamDef]]
lazy val pattern: Syntax[Pattern]
lazy val patterns: Syntax[Seq[Pattern]]
lazy val plus: Syntax[String]
lazy val program: Syntax[Program]

Attributes

lazy val typeTree: Syntax[TypeTree]

Implicits

Implicits

implicit inline def delimiter(inline string: String): Syntax[Token]
implicit inline def kw(inline k: Keyword): Syntax[Token]

Inherited implicits

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.

Attributes

Inherited from:
Parsing