xtc.parser
Class Copier

java.lang.Object
  extended by xtc.tree.Visitor
      extended by xtc.parser.Copier

public class Copier
extends Visitor

Visitor to copy grammar nodes. This visitor makes deep copies of grammars, modules, productions, and elements. Note that when copying elements, this visitor must be invoked through the copy(Element) method. Further note that, if the element to be copied contains a generic node value or a generic recursion value, the element must also contain all bindings referenced by that value element. Otherwise, an IllegalArgumentException is signalled.

Version:
$Revision: 1.51 $
Author:
Robert Grimm

Field Summary
protected  java.util.List<Binding> source
          The list of source bindings.
protected  java.util.List<Binding> target
          The list of target bindings.
 
Constructor Summary
Copier()
          Create a new copier.
 
Method Summary
<T extends Element>
T
copy(T e)
          Copy the specified element.
protected  Binding match(Binding b)
          Match the specified binding with its copy.
protected  void patch(java.util.List<Binding> bindings)
          Patch the specified bindings.
 Action visit(Action a)
          Copy the specified action.
 ActionBaseValue visit(ActionBaseValue v)
          Copy the specified action base value.
 AlternativeAddition visit(AlternativeAddition p)
          Copy the specified alternative addition.
 AlternativeRemoval visit(AlternativeRemoval p)
          Copy the specified alternative removal.
 Binding visit(Binding b)
          Copy the specified binding.
 BindingValue visit(BindingValue v)
          Copy the specified binding value.
 CharCase visit(CharCase c)
          Copy the specified character case.
 CharClass visit(CharClass c)
          Copy the specified character class.
 CharSwitch visit(CharSwitch s)
          Copy the specified character switch.
 Comment visit(Comment c)
          Copy the specified comment.
 Element visit(Element e)
          Visit the specified element.
 FollowedBy visit(FollowedBy p)
          Copy the specified followed-by predicate.
 FullProduction visit(FullProduction p)
          Copy the specified full production.
 GenericActionValue visit(GenericActionValue v)
          Copy the specified generic action value.
 GenericNodeValue visit(GenericNodeValue v)
          Copy the specified generic node value.
 GenericRecursionValue visit(GenericRecursionValue v)
          Copy the specified generic recursion value.
 Grammar visit(Grammar g)
          Copy the specified grammar.
 Module visit(Module m)
          Copy the specified module.
 ModuleImport visit(ModuleImport i)
          Copy the specified module import declaration.
 ModuleInstantiation visit(ModuleInstantiation i)
          Copy the specified module instantiation declaration.
 ModuleList visit(ModuleList l)
          Copy the specified module list.
 ModuleModification visit(ModuleModification m)
          Copy the specified module modification.
 NotFollowedBy visit(NotFollowedBy p)
          Copy the specified not-followed-by predicate.
 Option visit(Option o)
          Copy the specified option.
 OrderedChoice visit(OrderedChoice c)
          Copy the specified ordered choice.
 ParserAction visit(ParserAction pa)
          Copy the specified parser action.
 ParseTreeNode visit(ParseTreeNode n)
          Copy the specified parse tree node.
 ProductionOverride visit(ProductionOverride p)
          Copy the specified production override.
 ProperListValue visit(ProperListValue v)
          Copy the specified proper list value.
 Repetition visit(Repetition r)
          Copy the specified repetition.
 SemanticPredicate visit(SemanticPredicate p)
          Copy the specified semantic predicate.
 Sequence visit(Sequence s)
          Copy the specified sequence.
 StringMatch visit(StringMatch m)
          Copy the specified string match.
 VoidedElement visit(VoidedElement v)
          Copy the specified voided element.
 
Methods inherited from class xtc.tree.Visitor
dispatch, equals, hashCode, iterate, map, mapInPlace, unableToVisit, visit
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

source

protected java.util.List<Binding> source
The list of source bindings.


target

protected java.util.List<Binding> target
The list of target bindings.

Constructor Detail

Copier

public Copier()
Create a new copier.

Method Detail

match

protected Binding match(Binding b)
Match the specified binding with its copy.

Parameters:
b - The binding.
Returns:
The corresponding copy.
Throws:
java.lang.IllegalArgumentException - Signals that the specified binding has no copy.

patch

protected void patch(java.util.List<Binding> bindings)
Patch the specified bindings. This method replaces the source bindings in the specified list of bindings with the corresponding copies, thus ensuring that the list contains previously copied bindings.

Parameters:
bindings - The bindings to patch.

copy

public <T extends Element> T copy(T e)
Copy the specified element.

Parameters:
e - The element.
Returns:
A deep copy.
Throws:
java.lang.IllegalArgumentException - Signals that the specified element is incomplete.

visit

public Grammar visit(Grammar g)
Copy the specified grammar.


visit

public Module visit(Module m)
Copy the specified module.


visit

public Comment visit(Comment c)
Copy the specified comment.


visit

public ModuleImport visit(ModuleImport i)
Copy the specified module import declaration.


visit

public ModuleInstantiation visit(ModuleInstantiation i)
Copy the specified module instantiation declaration.


visit

public ModuleModification visit(ModuleModification m)
Copy the specified module modification.


visit

public ModuleList visit(ModuleList l)
Copy the specified module list.


visit

public FullProduction visit(FullProduction p)
Copy the specified full production.


visit

public AlternativeAddition visit(AlternativeAddition p)
Copy the specified alternative addition.


visit

public AlternativeRemoval visit(AlternativeRemoval p)
Copy the specified alternative removal.


visit

public ProductionOverride visit(ProductionOverride p)
Copy the specified production override.


visit

public OrderedChoice visit(OrderedChoice c)
Copy the specified ordered choice.


visit

public Repetition visit(Repetition r)
Copy the specified repetition.


visit

public Option visit(Option o)
Copy the specified option.


visit

public Sequence visit(Sequence s)
Copy the specified sequence.


visit

public FollowedBy visit(FollowedBy p)
Copy the specified followed-by predicate.


visit

public NotFollowedBy visit(NotFollowedBy p)
Copy the specified not-followed-by predicate.


visit

public SemanticPredicate visit(SemanticPredicate p)
Copy the specified semantic predicate.


visit

public VoidedElement visit(VoidedElement v)
Copy the specified voided element.


visit

public Binding visit(Binding b)
Copy the specified binding.


visit

public StringMatch visit(StringMatch m)
Copy the specified string match.


visit

public CharClass visit(CharClass c)
Copy the specified character class.


visit

public CharCase visit(CharCase c)
Copy the specified character case.


visit

public CharSwitch visit(CharSwitch s)
Copy the specified character switch.


visit

public Action visit(Action a)
Copy the specified action.


visit

public ParserAction visit(ParserAction pa)
Copy the specified parser action.


visit

public ParseTreeNode visit(ParseTreeNode n)
Copy the specified parse tree node.


visit

public BindingValue visit(BindingValue v)
Copy the specified binding value.


visit

public ProperListValue visit(ProperListValue v)
Copy the specified proper list value.


visit

public ActionBaseValue visit(ActionBaseValue v)
Copy the specified action base value.


visit

public GenericNodeValue visit(GenericNodeValue v)
Copy the specified generic node value.


visit

public GenericActionValue visit(GenericActionValue v)
Copy the specified generic action value.


visit

public GenericRecursionValue visit(GenericRecursionValue v)
Copy the specified generic recursion value.


visit

public Element visit(Element e)
Visit the specified element. This method provides the default implementation for nonterminals, terminals (besides character classes and switches), node markers, null literals, and value elements (besides properlists, generic node, generic action, and generic recursion values), which are immutable and not containers for other elements.



Copyright © 2012. All Rights Reserved.