com.ph.pr.parser.vbs2java
Class VBSVisitor
java.lang.Object
com.ph.pr.parser.ReflectiveVisitor
com.ph.pr.parser.vbs2java.VBSVisitor
- All Implemented Interfaces:
- Visitor
public class VBSVisitor
- extends ReflectiveVisitor
Translates a VBScript script into a Java class.
Notice that this was
generated with the first draft of ASTBuilder
,
which had a little issue due to the silliness of the author. As a result,
getters and setters for non-terminals in each implementation of
ASTNode
are still used (whereas the fix is to
use ASTNode.getNodes()
). The ambiguous cases here have been fixed
manually (such as visit(expr_7_AST)
and similar ones). A given
VBScript script is translated into a Java class. Sample usage is:
ASTNode start = ASTBuilder.singleton().parse(null, "com.sun.foo", "XXX.vbs");
VBSVisitor visitor = new VBSVisitor();
start.accept(visitor);
String code = visitor.getCode();
After which the code variable will contain the body of the
class, without the class signature, package statements or
imports. It currently the job of the caller (in our case,
com.ph.pr.parser.vb2java.achapps.VBS2Java
) to fill that out.
However, the resulting class must import everything in this package, and
extend com.ph.pr.parser.vb2java.VBS2JavaBase
(or a subclass
thereof). Also, since we're only concerned with cases that appear in our
VBScript files, some functionality of VBScript is not handled; the
corresponding branches of its visit() methods throw
UnsupportedOperationException
.
- Author:
ASTBuilder
-- auto-generation, Greg Golberg -- post-processing
- See Also:
ASTBuilder
,
ASTNode
Constructor Summary |
VBSVisitor(java.util.Map ast2Comments,
java.util.Collection allAsts)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
methods
private java.util.Map methods
pass
private int pass
INDENT
public static final java.lang.String INDENT
- See Also:
- Constant Field Values
ast2Comments
private java.util.Map ast2Comments
indentLevel
private int indentLevel
- Current indent level.
code
private java.lang.String code
caseFirst
private boolean caseFirst
downUse
private java.util.Stack downUse
funcName
private java.lang.String funcName
EOL
private static final java.lang.String EOL
- See Also:
- Constant Field Values
VBSVisitor
public VBSVisitor(java.util.Map ast2Comments,
java.util.Collection allAsts)
endStatement
private java.lang.String endStatement()
- Ends a statement.
- Returns:
- effectively, a ;, followed by
EOL
, followed
by a result of indent()
.
openBrace
private java.lang.String openBrace()
- Opens a brace (such as one after an if, etc.).
- Returns:
- effectively, increments
indentLevel
, and returns
{, followed by EOL
, followed by result of a
call to indent()
, then decrements indentLevel.
defaultVisit
public void defaultVisit(java.lang.Object o)
- Description copied from class:
ReflectiveVisitor
- If all else fails...
- Specified by:
defaultVisit
in class ReflectiveVisitor
- Parameters:
o
- say, can you see?
indent
private final java.lang.String indent()
- Indent.
- Returns:
indentLevel
number of INDENT
s.
getCode
public java.lang.String getCode()
visit
public void visit(expr_16_AST node)
visit
public void visit(formal_list_opt2_AST node)
visit
public void visit(start_AST node)
visit
public void visit(dim_decl_list_AST node)
visit
public void visit(ext_statement_AST node)
visit
public void visit(expr_17_AST node)
visit
public void visit(sub_list2_AST node)
visit
public void visit(redim_decl_AST node)
visit
public void visit(const_decl_list_AST node)
visit
public void visit(statement_AST node)
visit
public void visit(formal_list_opt_AST node)
visit
public void visit(expr_9_AST node)
visit
public void visit(by_opt_AST node)
visit
public void visit(exit_kind_AST node)
visit
public void visit(on_error_AST node)
visit
public void visit(on_target_AST node)
visit
public void visit(case_list_AST node)
visit
public void visit(formal_declarator_AST node)
visit
public void visit(for_AST node)
visit
public void visit(as_type_AST node)
visit
public void visit(expr_list_2_AST node)
visit
public void visit(expr_opt_AST node)
visit
public void visit(expr_6_AST node)
visit
public void visit(formal_list_AST node)
visit
public void visit(case_item_AST node)
visit
public void visit(no_paren_call_AST node)
visit
public void visit(expr_5_AST node)
visit
public void visit(const_AST node)
visit
public void visit(postfix_expr_AST node)
visit
public void visit(select_AST node)
visit
public void visit(tkNameList_AST node)
visit
public void visit(expr_AST node)
visit
public void visit(ext_statement_list_AST node)
visit
public void visit(ASTNode node)
visit
public void visit(expr_14_AST node)
visit
public void visit(set_expr_AST node)
visit
public void visit(if_then_AST node)
visit
public void visit(simple_statement_list_AST node)
visit
public void visit(formal_list_2_AST node)
visit
public void visit(dim_decl_list_2_AST node)
visit
public void visit(dim_AST node)
visit
public void visit(sub_AST node)
visit
public void visit(dim_decl_AST node)
undoNewline
private void undoNewline()
- Modifies
code
by truncating everything after the last
EOL
.
finishBlock
private void finishBlock()
- Calls
undoNewline()
, and then appends a EOL
, a result
of indent()
, a }, another two EOLs, and
another result of indent()
to code
visit
public void visit(func_AST node)
visit
public void visit(expr_2_AST node)
visit
public void visit(redim_decl_list_2_AST node)
visit
public void visit(statement_list_AST node)
visit
public void visit(expr_10_AST node)
visit
public void visit(const_decl_AST node)
visit
public void visit(assign_opt_AST node)
visit
public void visit(option_explicit_AST node)
visit
public void visit(name_opt_AST node)
visit
public void visit(redim_AST node)
visit
public void visit(parens_opt_AST node)
visit
public void visit(redim_decl_list_AST node)
visit
public void visit(expr_15_AST node)
visit
public void visit(condition_opt_AST node)
visit
public void visit(comment_list_AST node)
visit
public void visit(expr_3_AST node)
visit
public void visit(if_then_else_AST node)
visit
public void visit(expr_list_AST node)
visit
public void visit(simple_statement_AST node)
visit
public void visit(elseif_list_AST node)
visit
public void visit(assignment_AST node)
visit
public void visit(expr_12_AST node)
visit
public void visit(while_AST node)
visit
public void visit(as_opt_AST node)
visit
public void visit(else_opt_AST node)
visit
public void visit(expr_8_AST node)
visit
public void visit(expr_13_AST node)
visit
public void visit(const_decl_list_2_AST node)
visit
public void visit(expr_7_AST node)
visit
public void visit(set_AST node)
visit
public void visit(expr_4_AST node)
visit
public void visit(sub_list2_2_AST node)
visit
public void visit(primary_expr_AST node)
visit
public void visit(caseelse_opt_AST node)
visit
public void visit(step_opt_AST node)
visit
public void visit(preserve_opt_AST node)
visit
public void visit(type_decl_list_AST node)
visit
public void visit(elseif_item_AST node)
visit
public void visit(func_call_AST node)
visit
public void visit(expr_11_AST node)