Scala 2.6.1-final

API Specification

This document is the API specification for Scala Library Documentation

Class Summary
trait BindingParsers extends Parsers with Binders

This component augments the generic parsers with support for variable binding.

Use bind to decorate a parser that parses a binder (e.g., the name of a local variable or an argument name in a list of formal arguments): besides the parser, it requires a fresh Binder object, which serves as a container for one or more binders with the same scope. The result of the parser is added to the binder's elements. Note that semantic equality (equals) is used to link a binder to its bound occurrences (along with its scope, of course).

For example, here's how you'd write a parser (p) for a let construct (assuming b: Binder[Name]):

   "val" ~! bind(name, b) ~ ":" ~ typeP ~ "=" ~ term ~ "in" ~ in(term, b),

This can be read as ``The parser that matches val (and then does not back-track anymore), a name -- which represents a binder we'll call b -- a colon, a type, an equals sign, a term, the keyword in and finally a term where `b' is in scope.''

The result of this parser is a nested tuple of depth 3, containing a Type, a Term and an UnderBinder[Name, Term]. Note that the binder itself is discarded (the UnderBinder keeps track of it).

newScope makes an empty scope so that you can use into to pass it to a function that makes a parser whose bound variables end up in this scope: In our example, it would be used like this (with b free in p):

    newScope[Name] into { b => p }

Finally, bound(p) constructs a parser that checks that the result of p is bound by some binder b (i.e., b has an element which equals the result of p) in the current scope (as delineated by in(scopeP, b), where p is called during `scopeP'). If scoping is indeed respected, bound(p) wraps the result of p in a BoundElement.

trait StdTokenParsers extends TokenParsers
This component provides primitive parsers for the standard tokens defined in `StdTokens'.
trait TokenParsers extends Parsers

This is the core component for token-based parsers.

@requires lexical a component providing the tokens consumed by the parsers in this component.