public class AstToPrintTreeVisitor extends Object implements net.sourceforge.czt.base.visitor.TermVisitor<net.sourceforge.czt.base.ast.Term>, AndPredVisitor<net.sourceforge.czt.base.ast.Term>, ApplExprVisitor<net.sourceforge.czt.base.ast.Term>, AxParaVisitor<net.sourceforge.czt.base.ast.Term>, MemPredVisitor<net.sourceforge.czt.base.ast.Term>, RefExprVisitor<net.sourceforge.czt.base.ast.Term>, ZSectVisitor<net.sourceforge.czt.base.ast.Term>
This visitor transforms an AST into a print tree, that is an AST prepared for printing.
In order to print, precedences and associativity of operators needs to be known. This information is provided by an SectInfo object.
Note that fixed precedences and associativities are defined in the Z standard in Table 31; user defined precedences and associativities are obtained from an operator table. This implies that this visitor cannot be used for an arbitrary term, like an expression, without providing the operator table as well.
The recommended way to use this visitor is via the #run(ZSect) or #run(Spec) methods. In this case, the operator table is obtained from the SectInfo object (provided in the constructor of this class) as soon as the name of the current section to be visited becomes available (which happens when visiting a ZSect).
It is also possible to provide an operator table explicitly via
the #run(Term, OpTable) method. This method enables the handling
of arbitrary terms where the name of the section is not apparent.
Note that this explicity provided operator table is discarded when
a ZSect is visited. As soon as a ZSect is visited, the SectInfo
object is consulted to provide an operator table for the given
section and this operator table is used instead of the explicitly
provided one (even if the new one is null
).
It is not recommended to call the accept method of a term to use this visitor since it is not guaranteed that the correct operator table is used.
Modifier and Type | Class and Description |
---|---|
static class |
AstToPrintTreeVisitor.CannotPrintAstException |
Modifier and Type | Field and Description |
---|---|
protected WarningManager |
warningManager_ |
protected boolean |
withinAxPara_ |
Constructor and Description |
---|
AstToPrintTreeVisitor(SectionInfo sectInfo) |
AstToPrintTreeVisitor(SectionInfo sectInfo,
WarningManager wm)
Creates a new ast to print tree visitor.
|
Modifier and Type | Method and Description |
---|---|
protected Precedence |
getPrec(net.sourceforge.czt.base.ast.Term term) |
protected SectionInfo |
getSectionInfo() |
protected WarningManager |
getWarningManager() |
protected ZFactory |
getZFactory() |
protected PrintFactory |
getZPrintFactory() |
protected PrintParagraph |
handleOldZ(List<Object> anns,
PrintParagraph pp) |
protected boolean |
isInfix(OperatorName opName) |
protected void |
preprocessSchema(AxPara term,
List<Object> list)
Called for schema boxes right after the schema tagging.
|
protected void |
preprocessTerm(net.sourceforge.czt.base.ast.Term term,
List<Object> list)
Called right after the main Z token found.
|
net.sourceforge.czt.base.ast.Term |
run(String sectionName) |
net.sourceforge.czt.base.ast.Term |
run(net.sourceforge.czt.base.ast.Term term,
OpTable opTable)
Visits a term and transforms it into a printable tree.
|
net.sourceforge.czt.base.ast.Term |
run(net.sourceforge.czt.base.ast.Term term,
String sectionName)
Visits a term and transforms it into a printable tree.
|
void |
setOldZ(boolean value) |
protected net.sourceforge.czt.base.ast.Term |
visit(net.sourceforge.czt.base.ast.Term term) |
net.sourceforge.czt.base.ast.Term |
visitAndPred(AndPred andPred) |
net.sourceforge.czt.base.ast.Term |
visitApplExpr(ApplExpr applExpr)
Transforms each function application (an application expression
with Mixfix set to
true ) into an
OperatorApplication, and each application (an application
expression with Mixfix set to false ) into an
Application. |
net.sourceforge.czt.base.ast.Term |
visitAxPara(AxPara axPara) |
net.sourceforge.czt.base.ast.Term |
visitMemPred(MemPred memPred) |
net.sourceforge.czt.base.ast.Term |
visitRefExpr(RefExpr refExpr)
Transforms each generic operator application, that is each
reference expression with Mixfix set to
true into an
OperatorApplication. |
net.sourceforge.czt.base.ast.Term |
visitTerm(net.sourceforge.czt.base.ast.Term term)
Visits all children of a term.
|
net.sourceforge.czt.base.ast.Term |
visitZSect(ZSect zSect)
Sets up the operator table for this Z section.
|
protected final WarningManager warningManager_
protected boolean withinAxPara_
public AstToPrintTreeVisitor(SectionInfo sectInfo)
public AstToPrintTreeVisitor(SectionInfo sectInfo, WarningManager wm)
net.sourceforge.czt.parser.util.OpTable.class
.sectInfo
- wm
- protected ZFactory getZFactory()
protected PrintFactory getZPrintFactory()
protected SectionInfo getSectionInfo()
protected WarningManager getWarningManager()
public net.sourceforge.czt.base.ast.Term run(String sectionName) throws CommandException
CommandException
public net.sourceforge.czt.base.ast.Term run(net.sourceforge.czt.base.ast.Term term, OpTable opTable)
Visits a term and transforms it into a printable tree. The given operator table is used to lookup precedence and associativity of user defined operators, but only if the name of the section is not apparent from the term.
For instance, the given operator table is used if the given term is an expression, predicate, or paragraph, but not if the given term is a Z section or specification.
term
- opTable
- public net.sourceforge.czt.base.ast.Term run(net.sourceforge.czt.base.ast.Term term, String sectionName) throws CommandException
Visits a term and transforms it into a printable tree. The given section name is used to lookup precedence and associativity of user defined operators, but only if the name of the section is not apparent from the term itself.
For instance, the given section name is used if the given term is an expression, predicate, or paragraph, but not if the given term is a Z section or specification.
term
- sectionName
- CommandException
public void setOldZ(boolean value)
public net.sourceforge.czt.base.ast.Term visitTerm(net.sourceforge.czt.base.ast.Term term)
visitTerm
in interface net.sourceforge.czt.base.visitor.TermVisitor<net.sourceforge.czt.base.ast.Term>
term
- public net.sourceforge.czt.base.ast.Term visitAndPred(AndPred andPred)
visitAndPred
in interface AndPredVisitor<net.sourceforge.czt.base.ast.Term>
public net.sourceforge.czt.base.ast.Term visitApplExpr(ApplExpr applExpr)
true
) into an
OperatorApplication, and each application (an application
expression with Mixfix set to false
) into an
Application.visitApplExpr
in interface ApplExprVisitor<net.sourceforge.czt.base.ast.Term>
protected PrintParagraph handleOldZ(List<Object> anns, PrintParagraph pp)
protected void preprocessSchema(AxPara term, List<Object> list) throws PrintException
term
- list
- PrintException
protected void preprocessTerm(net.sourceforge.czt.base.ast.Term term, List<Object> list) throws PrintException
term
- list
- PrintException
public net.sourceforge.czt.base.ast.Term visitAxPara(AxPara axPara)
visitAxPara
in interface AxParaVisitor<net.sourceforge.czt.base.ast.Term>
public net.sourceforge.czt.base.ast.Term visitMemPred(MemPred memPred)
visitMemPred
in interface MemPredVisitor<net.sourceforge.czt.base.ast.Term>
public net.sourceforge.czt.base.ast.Term visitRefExpr(RefExpr refExpr)
true
into an
OperatorApplication.visitRefExpr
in interface RefExprVisitor<net.sourceforge.czt.base.ast.Term>
public net.sourceforge.czt.base.ast.Term visitZSect(ZSect zSect)
visitZSect
in interface ZSectVisitor<net.sourceforge.czt.base.ast.Term>
protected boolean isInfix(OperatorName opName)
protected net.sourceforge.czt.base.ast.Term visit(net.sourceforge.czt.base.ast.Term term)
protected Precedence getPrec(net.sourceforge.czt.base.ast.Term term)
Copyright © 2003–2016 Community Z Tools Project. All rights reserved.