kiama.parsing

trait Parsers

[source: kiama/parsing/Parsers.scala]

trait Parsers
extends AnyRef
Parser combinator library modelled on the Scala parser combinator library, and through it on various versions of parser combinator libraries for Haskell.
Direct Known Subclasses:
PackratParsers, CharParsers

Type Summary
abstract type Elem
The abstract type of input element that these parsers process.
type Input
The input for these parsers comes from a reader of the element type. We use the same readers as the standard parser combinator library.
Value Summary
val any : Parser[Elem]
Parse any element.
Method Summary
def Parser [T](f : (scala.util.parsing.input.Reader) => ParseResult[T]) : Parser[T]
Construct a parser that produces whatever result f produces when applied to the input.
implicit def accept (e : Elem) : Parser[Elem]
(Implicitly) construct a parser that succeeds with e if the next input element is e, and otherwise fails.
implicit def acceptIf (pred : (Elem) => Boolean) : Parser[Elem]
(Implicitly) construct a parser that succeeds if the given predicate answers true when applied to the next input element, and otherwise fails.
def and [T](p : => Parser[T]) : Parser[T]
Construct a parser that returns the result of parsing with p, except that it unconditionally backtracks to the input position when p was invoked. I.e., the resulting parser is only useful for its success or failure result, not its effect on the input.
def failure (message : java.lang.String) : Parser[Nothing]
Construct a parser that always fails with the given message without consuming any input.
def not [T](p : => Parser[T]) : Parser[Unit]
Construct a parser that succeeds if p fails and fails if p succeeds. In the case of success (i.e., p has failed), the constructed parser returns (). In neither case is the input affected.
def opt [T](p : => Parser[T]) : Parser[scala.Option[T]]
Construct a parser that parsers either what p parses or nothing.
def phrase [T](p : => Parser[T]) : Parser[T]
Construct a parser that parses with p and then makes sure that the entire input has been consumed (i.e., the input was a phrase that was recognised by p).
def rep [T](p : => Parser[T]) : Parser[scala.List[T]]
Construct a parser that parses zero or more occurrences of what p parses. Collect the result values in a list. Defined in terms of rep1.
def rep1 [T](p : => Parser[T]) : Parser[scala.List[T]]
Construct a parser that parses one or more occurrences of what p parses. Collect the result values in a list. This parser is right recursive to avoid infinite recursion.
def rep1sep [T, U](p : => Parser[T], sep : => Parser[U]) : Parser[scala.List[T]]
Construct a parser that parses one or more occurrences of what p parses, where each pair of occurrences is separated by something that sep parses. At the moment, there is no way to get at the results of sep.
def repN [T](n : Int, p : => Parser[T]) : Parser[scala.List[T]]
Construct a parser that parses exactly n repetitions of what p parses. Collect the result values in a list.
def repsep [T, U](p : => Parser[T], sep : => Parser[U]) : Parser[scala.List[T]]
Construct a parser that parses zero or more occurrences of what p parses, where each pair of occurrences is separated by something that sep parses. At the moment, there is no way to get at the results of sep.
def success [T](result : T) : Parser[T]
Construct a parser that always succeeds with the given result without consuming any input.
Methods inherited from AnyRef
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Class Summary
case class Failure (val msg : java.lang.String, val in : scala.util.parsing.input.Reader) extends ParseResult[Nothing] with scala.Product
A parse result representing failure of a parse.
sealed abstract class ParseResult [+T] extends AnyRef
Representations of the results of parsing.
abstract class Parser [+T] extends (scala.util.parsing.input.Reader) => ParseResult[T]
A parser from inputs to parse results.
case class Success [T](val result : T, val in : scala.util.parsing.input.Reader) extends ParseResult[T] with scala.Product
A successful parse result.
case class ~ [+U, +V](val l : U, val r : V) extends scala.Product
A tuple for compound parser result values. Designed to match the ~ combinator used for sequencing.
Type Details
abstract type Elem
The abstract type of input element that these parsers process.

type Input
The input for these parsers comes from a reader of the element type. We use the same readers as the standard parser combinator library.

Value Details
val any : Parser[Elem]
Parse any element.

Method Details
def Parser[T](f : (scala.util.parsing.input.Reader) => ParseResult[T]) : Parser[T]
Construct a parser that produces whatever result f produces when applied to the input.

def success[T](result : T) : Parser[T]
Construct a parser that always succeeds with the given result without consuming any input.

def failure(message : java.lang.String) : Parser[Nothing]
Construct a parser that always fails with the given message without consuming any input.

implicit def accept(e : Elem) : Parser[Elem]
(Implicitly) construct a parser that succeeds with e if the next input element is e, and otherwise fails.

implicit def acceptIf(pred : (Elem) => Boolean) : Parser[Elem]
(Implicitly) construct a parser that succeeds if the given predicate answers true when applied to the next input element, and otherwise fails.

def opt[T](p : => Parser[T]) : Parser[scala.Option[T]]
Construct a parser that parsers either what p parses or nothing.

def rep[T](p : => Parser[T]) : Parser[scala.List[T]]
Construct a parser that parses zero or more occurrences of what p parses. Collect the result values in a list. Defined in terms of rep1.

def rep1[T](p : => Parser[T]) : Parser[scala.List[T]]
Construct a parser that parses one or more occurrences of what p parses. Collect the result values in a list. This parser is right recursive to avoid infinite recursion.

def repN[T](n : Int, p : => Parser[T]) : Parser[scala.List[T]]
Construct a parser that parses exactly n repetitions of what p parses. Collect the result values in a list.

def repsep[T, U](p : => Parser[T], sep : => Parser[U]) : Parser[scala.List[T]]
Construct a parser that parses zero or more occurrences of what p parses, where each pair of occurrences is separated by something that sep parses. At the moment, there is no way to get at the results of sep.

def rep1sep[T, U](p : => Parser[T], sep : => Parser[U]) : Parser[scala.List[T]]
Construct a parser that parses one or more occurrences of what p parses, where each pair of occurrences is separated by something that sep parses. At the moment, there is no way to get at the results of sep.

def phrase[T](p : => Parser[T]) : Parser[T]
Construct a parser that parses with p and then makes sure that the entire input has been consumed (i.e., the input was a phrase that was recognised by p).

def and[T](p : => Parser[T]) : Parser[T]
Construct a parser that returns the result of parsing with p, except that it unconditionally backtracks to the input position when p was invoked. I.e., the resulting parser is only useful for its success or failure result, not its effect on the input.

def not[T](p : => Parser[T]) : Parser[Unit]
Construct a parser that succeeds if p fails and fails if p succeeds. In the case of success (i.e., p has failed), the constructed parser returns (). In neither case is the input affected.