Reputation: 23506
The SyntaxDefinition documentation page of Rascal has two sections, where one speaks about "labels" (starting with "Each alternative of a syntax definition is defined by a list of Symbols."), the other about "names" (starting with "Alternatives can be named or not."). For both items a list of effects are given that largely overlap, e.g. both enable the is
operator, are necessary for imploding ParseTrees or for writing Action functions. The Syntax section at the top of the page only lists a Name
component, and Tags
but no labels.
Is "label" an alternative term for "name"? And if so why do the lists of the effects using them differ?
Upvotes: 1
Views: 153
Reputation: 6696
That documentation page could use some love indeed.
The "labels" that are talked about function as optionally declared "names" for two different kinds of things:
syntax E = add: E "+" E | sub: E "-" E;
syntax E = E lhs "+" E rhs | E lhs "-" E rhs;
Having a label on a rule enables different functionality from having a label on a symbol position.
For rules we get:
myExp is myLabel
; checks to see if the top parse tree node has a syntax rule labeled with that labelParseTree::implode
uses the rule labels to map concrete parse tree nodes to abstract data tree nodesExp add(Exp lhs, Exp rhs) { ... }
will be called when constructing syntax Exp = add: Exp "+" Exp;
For symbol positions we get:
myExp has myLabel
; checks to see whether the current parse tree node has a syntax rule where one of the symbol positions is labeled with myLabel
myExp.myLabel
; projects out the tree at the labeled position from given parse treemyExp.myLabel = newExp
; replaces the tree at the labeled position in the given parse treeUpvotes: 1