scala.util.parsing.combinator

trait PackratParsers

[source: scala/util/parsing/combinator/PackratParsers.scala]

trait PackratParsers
extends Parsers

PackratParsers is a component that extends the parser combinators provided by Parsers with a memoization facility (``Packrat Parsing'').

Packrat Parsing is a technique for implementing backtracking, recursive-descent parsers, with the advantage that it guarantees unlimited lookahead and a linear parse time. Using this technique, left recursive grammars can also be accepted.

Using PackratParsers is very similar to using Parsers:

Cached parse results are attached to the input, not the grammar. Therefore, PackratsParsers require a PackratReader as input, which adds memoization to an underlying Reader. Programmers can create PackratReader objects either manually, as in production(new PackratReader(new lexical.Scanner("input"))), but the common way should be to rely on the combinator phrase to wrap a given input with a PackratReader if the input is not one itself.

See Also
Bryan Ford: "Packrat Parsing: Simple, Powerful, Lazy, Linear Time." ICFP'02
Alessandro Warth, James R. Douglass, Todd Millstein: "Packrat Parsers Can Support Left Recursion." PEPM'08
Since
2.8
Author
Manohar Jonnalagedda, Tiark Rompf
Values and Variables inherited from Parsers
lastNoSuccess
Method Summary
def memo [T](p : Parser[T]) : PackratParser[T]
Explicitly convert a given parser to a memoizing packrat parser. In most cases, client code should avoid calling memo directly and rely on implicit conversion instead.
implicit def parser2packrat [T](p : => Parser[T]) : PackratParser[T]
Implicitly convert a parser to a packrat parser. The conversion is triggered by giving the appropriate target type: val myParser: PackratParser[MyResult] = aParser
override def phrase [T](p : Parser[T]) : PackratParser[T]
Methods inherited from Parsers
Parser, OnceParser, commit, elem, elem, accept, accept, accept, acceptIf, acceptMatch, acceptSeq, failure, err, success, log, rep, repsep, rep1, rep1, repN, rep1sep, chainl1, chainl1, chainr1, opt, not, guard, positioned, mkList
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
abstract class PackratParser [+T] extends Parser[T]
The root class of packrat parsers.
class PackratReader [+T](underlying : Reader[T]) extends Reader[T]
A specialized Reader class that wraps an underlying Reader and provides memoization of parse results.
Method Details
override def phrase[T](p : Parser[T]) : PackratParser[T]

A parser generator delimiting whole phrases (i.e. programs).

Overridden to make sure any input passed to the argument parser is wrapped in a PackratReader.

Overrides
Parsers.phrase

implicit def parser2packrat[T](p : => Parser[T]) : PackratParser[T]
Implicitly convert a parser to a packrat parser. The conversion is triggered by giving the appropriate target type: val myParser: PackratParser[MyResult] = aParser

def memo[T](p : Parser[T]) : PackratParser[T]
Explicitly convert a given parser to a memoizing packrat parser. In most cases, client code should avoid calling memo directly and rely on implicit conversion instead.