scala.util.parsing.ast

trait Binders

[source: scala/util/parsing/ast/Binders.scala]

trait Binders
extends AbstractSyntax with Mappable

This component provides functionality for enforcing variable binding during parse-time.

When parsing simple languages, like Featherweight Scala, these parser combinators will fully enforce the binding discipline. When names are allowed to be left unqualified, these mechanisms would have to be complemented by an extra phase that resolves names that couldn't be resolved using the naive binding rules. (Maybe some machinery to model `implicit' binders (e.g., `this' and imported qualifiers) and selection on a binder will suffice?)

Author
Adriaan Moors
Direct Known Subclasses:
BindingParsers

Method Summary
implicit def NameElementIsMappable (self : NameElement) : Mappable[NameElement]
implicit def ScopeIsMappable [bt <: NameElement](scope : Scope[bt])(implicit view$10 : (bt) => Mappable[bt]) : Mappable[Scope[bt]]
implicit def UnderBinderIsMappable [bt <: NameElement, st](ub : UnderBinder[bt, st])(implicit view$8 : (bt) => Mappable[bt], implicit view$9 : (st) => Mappable[st]) : Mappable[UnderBinder[bt, st]]
abstract def UserNameElementIsMappable [t <: NameElement](self : t) : Mappable[t]
def return_ [T](result : T) : ReturnAndDo[T]
def sequence [bt <: NameElement, st](orig : List[UnderBinder[bt, st]])(implicit view$13 : (st) => Mappable[st]) : UnderBinder[bt, List[st]]
If a list of `UnderBinder's all have the same scope, they can be turned in to an UnderBinder containing a list of the elements in the original `UnderBinder'. The name `sequence' comes from the fact that this method's type is equal to the type of monadic sequence.
def unsequence [bt <: NameElement, st](orig : UnderBinder[bt, List[st]])(implicit view$14 : (st) => Mappable[st]) : List[UnderBinder[bt, st]]
Methods inherited from Mappable
StringIsMappable, ListIsMappable, OptionIsMappable
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 BinderEnv extends AnyRef
An environment that maps a `NameElement' to the scope in which it is bound. This can be used to model scoping during parsing. (This class is similar to Burak's ECOOP paper on pattern matching, except that we use `==' instead of `eq', thus types can't be unified in general) TODO: more documentation
trait BindingSensitive extends AnyRef
case class BoundElement [boundElement <: NameElement](val el : boundElement, val scope : Scope[boundElement]) extends NameElement with Proxy with BindingSensitive with Product
A `BoundElement' is bound in a certain scope `scope', which keeps track of the actual element that `el' stands for. A `BoundElement' is represented textually by its bound element, followed by its scope's `id'. For example: `x@1' represents the variable `x' that is bound in the scope with `id' `1'. @invar scope.binds(el)
trait ReturnAndDo [T] extends AnyRef
Returns a given result, but executes the supplied closure before returning. (The effect of this closure does not influence the returned value.) TODO: move this to some utility object higher in the scala hierarchy?
class Scope [binderType <: NameElement] extends Iterable[binderType]
A `Scope' keeps track of one or more syntactic elements that represent bound names. The elements it contains share the same scope and must all be distinct (wrt. ==) A `NameElement' `n' in the AST that is conceptually bound by a `Scope' `s', is replaced by a `BoundElement(n, s)'. (For example, in `val x:Int=x+1', the first `x' is modelled by a Scope `s' that contains `x' and the second `x' is represented by a `BoundElement(`x', s)') The term (`x+1') in scope of the Scope becomes an `UnderBinder(s, `x+1'). A `NameElement' `n' is bound by a `Scope' `s' if it is wrapped as a `BoundElement(`n', s)', and `s' has a binder element that is semantically equal (`equals' or `==') to `n'. A `Scope' is represented textually by its list of binder elements, followed by the scope's `id'. For example: `[x, y]!1' represents the scope with `id' `1' and binder elements `x' and `y'. (`id' is solely used for this textual representation.)
class UnboundElement [N <: NameElement](private el : N) extends NameElement
A variable that escaped its scope (i.e., a free variable) -- we don't deal very well with these yet
class UnderBinder [binderType <: NameElement, elementT](val scope : Scope[binderType], val element : elementT, implicit view$5 : (elementT) => Mappable[elementT]) extends Element with BindingSensitive
Represents an element with variables that are bound in a certain scope.
Object Summary
object EmptyBinderEnv extends BinderEnv
object UnderBinder extends AnyRef
Method Details
implicit def UnderBinderIsMappable[bt <: NameElement, st](ub : UnderBinder[bt, st])(implicit view$8 : (bt) => Mappable[bt], implicit view$9 : (st) => Mappable[st]) : Mappable[UnderBinder[bt, st]]

implicit def ScopeIsMappable[bt <: NameElement](scope : Scope[bt])(implicit view$10 : (bt) => Mappable[bt]) : Mappable[Scope[bt]]

implicit def NameElementIsMappable(self : NameElement) : Mappable[NameElement]

abstract def UserNameElementIsMappable[t <: NameElement](self : t) : Mappable[t]

def sequence[bt <: NameElement, st](orig : List[UnderBinder[bt, st]])(implicit view$13 : (st) => Mappable[st]) : UnderBinder[bt, List[st]]
If a list of `UnderBinder's all have the same scope, they can be turned in to an UnderBinder containing a list of the elements in the original `UnderBinder'. The name `sequence' comes from the fact that this method's type is equal to the type of monadic sequence.
Precondition
!orig.isEmpty implies orig.forall(ub => ub.scope eq orig(0).scope)

def unsequence[bt <: NameElement, st](orig : UnderBinder[bt, List[st]])(implicit view$14 : (st) => Mappable[st]) : List[UnderBinder[bt, st]]

def return_[T](result : T) : ReturnAndDo[T]