com.judoscript.parser.helper
Class ParserHelper

java.lang.Object
  extended by com.judoscript.JudoUtil
      extended by com.judoscript.parser.helper.ParserHelper
All Implemented Interfaces:
Consts
Direct Known Subclasses:
JudoParser

public abstract class ParserHelper
extends JudoUtil
implements Consts

TODO: clean up the label mess -- labels are now part of a loop statment and need no special treatment.


Nested Class Summary
static class ParserHelper.SgmlEvent
           
 
Field Summary
 int curFileIndex
           
protected  java.lang.String currentNS
           
protected  java.util.HashSet definedClasses
           
static Expr[] emptyExprs
           
protected  java.lang.String encoding
           
static java.lang.String eol
           
protected  Expr first
           
protected  boolean inClassDef
           
protected  boolean inFxnThrd
           
protected  boolean inJavaCtor
           
protected  boolean inJavax
           
protected  java.util.HashSet javaxCalls
           
protected  java.util.HashMap labels
           
protected  MixtureParser mixtureParser
           
protected  int[] ops
           
protected  ParsingContext pc
           
protected  Expr[] rest
           
 Script script
           
protected static int SGML_AFTER
           
protected static int SGML_BEFORE
           
protected static int SGML_DEFAULT_TAG
           
protected static int SGML_SPECIAL
           
protected static int SGML_TAG
           
protected static int SGML_TEXT
           
protected  java.util.Stack stack
          This stack is used for ()*, or rather, ()+ constructs.
protected  Stmt[] stmts
           
protected  java.util.HashSet superCalls
           
 
Fields inherited from class com.judoscript.JudoUtil
searchCP
 
Fields inherited from interface com.judoscript.Consts
ADAPTER_PREFIX, ANNOTATION_NAME, ANY_TAG_SYMBOL, ANY_TEXT_SYMBOL, ARGS_NAME, BSF_NAME, CONTEXT_NAME, DEFAULT_CONNECTION_NAME, DEFAULT_HIBERNATE_NAME, DEFAULT_NS_SYMBOL, DYNAMIC_EVAL, DYNAMIC_EVALEXTERNAL, DYNAMIC_EVALFILE, FOREVER, FS_ADD_TO_CLASSPATH, FS_COPY, FS_DO, FS_LIST, FS_LIST_BY_DATE, FS_LIST_BY_EXT, FS_LIST_BY_NAME, FS_LIST_BY_NONE, FS_LIST_BY_SIZE, FS_LIST_COMPRESSED_SIZE, FS_LIST_COUNT, FS_LIST_COUNTLINES, FS_LIST_COUNTWORDS, FS_LIST_PER_FILE, FS_LIST_PER_NONE, FS_LIST_SIZE, FS_MAKEDIR, FS_MOVE, FS_NONE, FS_REMOVE, FS_REMOVEDIR, FS_RESULT_NAME, FS_SETFILETIME, FS_SETREADONLY, FS_SETREADWRITE, HTTP_GET, HTTP_HEAD, HTTP_POST, IO_GZIPPED_INPUTFILE, IO_GZIPPED_OUTPUTFILE, IO_GZIPPED_TEXTINPUTFILE, IO_GZIPPED_TEXTOUTPUTFILE, IO_INPUTSTREAM, IO_OUTPUTSTREAM, IO_RANDOMACCESS, IO_TEXTINPUTFILE, IO_TEXTOUTPUTFILE, ISSUE_LEVEL_DEBUG, ISSUE_LEVEL_ERROR, ISSUE_LEVEL_IGNORE, ISSUE_LEVEL_INFO, ISSUE_LEVEL_WARN, JAVA_ANY, JAVA_ANY_I, JAVA_BOOLEAN, JAVA_BOOLEAN_I, JAVA_BOOLEAN_O, JAVA_BYTE, JAVA_BYTE_I, JAVA_BYTE_O, JAVA_CHAR, JAVA_CHAR_I, JAVA_CHAR_O, JAVA_CURRENCY, JAVA_CURRENCY_I, JAVA_DATE_O, JAVA_DOUBLE, JAVA_DOUBLE_I, JAVA_DOUBLE_O, JAVA_FLOAT, JAVA_FLOAT_I, JAVA_FLOAT_O, JAVA_INT, JAVA_INT_I, JAVA_INT_O, JAVA_LONG, JAVA_LONG_I, JAVA_LONG_O, JAVA_SHORT, JAVA_SHORT_I, JAVA_SHORT_O, JAVA_SQL_DATE_O, JAVA_SQL_TIME_O, JAVA_SQL_TIMESTAMP_O, JAVA_STRING, JAVA_STRING_I, LABEL_SCHEDULE, LAMBDA_PREFIX, LOCAL_NAME, LOCALTEXT_NAME, MAX_READ_FILE_LENGTH, NODE_PREFIX, OP_AND, OP_AND_ASSIGN, OP_ASSIGN, OP_COMPLEMENT, OP_CONCAT, OP_CONCAT_ASSIGN, OP_COPY, OP_DIV, OP_DIV_ASSIGN, OP_EQ, OP_GE, OP_GT, OP_LE, OP_LOGIC_AND_ASSIGN, OP_LOGIC_OR_ASSIGN, OP_LSHIFT, OP_LSHIFT_ASSIGN, OP_LT, OP_MINUS, OP_MINUS_ASSIGN, OP_MOD, OP_MOD_ASSIGN, OP_MUL, OP_MUL_ASSIGN, OP_NE, OP_NOT, OP_OR, OP_OR_ASSIGN, OP_PLUS, OP_PLUS_ASSIGN, OP_RSHIFT, OP_RSHIFT_ASSIGN, OP_RUSHIFT, OP_RUSHIFT_ASSIGN, OP_XOR, OP_XOR_ASSIGN, OPTION_JDBC_PASSWORD, OPTION_JDBC_URL, OPTION_JDBC_USERNAME, ORACLE_BFILE, ORACLE_CURSOR, ORACLE_FIXED_CHAR, ORACLE_NUMBER, ORACLE_PLSQL_INDEX_TABLE, ORACLE_RAW, ORACLE_ROWID, PARENT_NAME, PARSER_NAME, PRAGMA_ASSERTION, PRAGMA_CRYPTOCLASS, PRAGMA_GUILISTENER, PRAGMA_INCLUDEPATH, PRAGMA_JAVACOMPILER, PRAGMA_JDBCDRIVER, pragma_names, PRAGMA_UNKNOWN, PREPARED_STMT_CALL, PRINT_ERR, PRINT_LOG, PRINT_OUT, PRINT_PIPE, PRINT_USER, RTERR_ASSERTION_FAILURE, RTERR_BAD_PRINT_TARGET, RTERR_CONSTANT_NOT_DEFINED, RTERR_CONSTANT_REDEFINITION, RTERR_EMBEDDED_JAVA_COMPILE_FAILED, RTERR_ENVIRONMENT_ERROR, RTERR_EVALUATION_FAILED, RTERR_FS_COPY_MOVE_FAILED, RTERR_FS_CREATE_DIR_FAILED, RTERR_FS_REMOVE_DIR_FAILED, RTERR_FUNCTION_ALREADY_DEFINED, RTERR_ILLEGAL_ACCESS, RTERR_ILLEGAL_ARGUMENTS, RTERR_ILLEGAL_INDEXED_ACCESS, RTERR_ILLEGAL_JUMP, RTERR_ILLEGAL_STATEMENT, RTERR_ILLEGAL_VALUE_SETTING, RTERR_INTERNAL_ERROR, RTERR_INVALID_ARRAY_ACCESS, RTERR_INVALID_JAVA_VERSION, RTERR_INVALID_MEMBER_ACCESS, RTERR_INVALID_NUMBER_FORMAT, RTERR_INVALID_VARIABLE_NAME, RTERR_IO_FAILURE, RTERR_IO_FILE_OPEN_FAILURE, RTERR_JAVA_COMPILE_FAILED, RTERR_JAVA_EXCEPTION, RTERR_JAVA_METHOD_CALL, RTERR_JAVA_OBJECT_CREATION, RTERR_JDBC_DRIVER_NOT_FOUND, RTERR_JDBC_FAILURE, RTERR_JDBC_INVALID_COLUMN, RTERR_JDBC_WARNING, RTERR_MAIL_MISSING_FIELD, RTERR_MAILSERVER_NOT_CONNECTED, RTERR_METHOD_NOT_FOUND, rterr_names, RTERR_NO_SUCH_VALUE, RTERR_OBJECT_INIT, RTERR_TIMER_ALREADY_EXISTS, RTERR_UNDEFINED_GUI_EVENT, RTERR_UNDEFINED_OBJECT_TYPE, RTERR_USER_EXCEPTION, RTERR_XML_PARSING_ERROR, RULEENGINE_MAX_ITERATIONS, SYS_NAME, TEMPVAR_PREFIX, TEXT_PREFIX, THIS_NAME, THREAD_PREFIX, TIMER_NAME, TYPE_ARRAY, TYPE_CALLABLE, TYPE_COM, TYPE_COMPLEX, TYPE_CONTEXT, TYPE_DATE, TYPE_DOUBLE, TYPE_FUNCTION, TYPE_INT, TYPE_INTERNAL, TYPE_JAVA, TYPE_NAN, TYPE_NIL, TYPE_OBJECT, TYPE_QUEUE, TYPE_SET, TYPE_STACK, TYPE_STRING, TYPE_STRUCT, TYPE_UNDEFINED, TYPE_UNKNOWN, TYPE_WS, TYPE1_SYMBOL, TYPE2_SYMBOL, TYPE3_SYMBOL, XML_EVENT_PREFIX
 
Constructor Summary
protected ParserHelper()
           
 
Method Summary
 void addClassToScript(UserDefined.UserType ot)
           
 void addFunction(Script script, Function fxn)
           
 void addFunction(UserDefined.UserType ot, Function fxn)
           
 void addSgmlHandler(ParserHelper.SgmlEvent evt, StmtHtml hndlr)
          stmts is expected to be processed, which can be null
 boolean checkAntTask(java.lang.String name)
           
static boolean CheckSupportedAntTask(java.lang.String name)
           
protected  void cleanup()
           
 void close()
           
protected  int countOnStack(int lastMark)
           
 void defineJavaPackages(java.lang.String pkgName, java.lang.String javaPkg)
           
 boolean evalConstToBool(Expr expr, boolean def)
           
 java.lang.String getScriptBasePath()
           
 int getTargetID(java.lang.String targetName)
           
protected  java.lang.Object[] handleAny(int lastMark)
           
protected  BlockSimple handleBlock(int lastMark, java.lang.String exceptionName, int begin)
           
protected  Expr[] handleExprs(int lastMark)
          rest is set and returned.
protected  Expr handleForIn(int lineNum, AccessVar avar, Expr arr, Expr from, Expr to, Expr step, boolean backward, Expr[] forInit, Expr[] forNext, Stmt[] preStmts)
           
 void handleJavaPackages(int lineNo, java.lang.String pkgId, java.lang.String var)
           
protected  Expr handleMixture(int beginLine, int endLine, java.lang.Object[] oa)
           
protected  Expr handleMixture(java.lang.Object[] oa)
           
protected  boolean handleMultiBase(int lastMark)
          If true is returned, then ops, first and rest are set.
protected  boolean handleMultiBase1(int lastMark)
          If true is returned, then first and rest are set.
protected  AssociateList handleNamedExprs(int lastMark)
           
 void handlePragma(int lineNo, java.lang.String pragma, Variable val)
           
 Variable handleRegexLiteral(java.lang.String literal)
           
protected  Expr handleSingleExpr()
           
protected  Expr handleSingleExpr(int lastMark)
           
protected  boolean handleStmts(int lastMark)
          If true is returned, then stmts and labels are set.
protected  java.lang.String[] handleStrings(int lastMark)
           
static boolean isOctalChar(char ch)
           
protected  int markStack()
           
 ExprBindVar newBindVar(int idx, java.lang.String name, int type, java.lang.String typeName, Expr expr)
           
static ExprCall newCall(Expr var, java.lang.String fxn, Expr[] params, int[] types)
           
static ExprCall newCall(java.lang.String var, java.lang.String fxn, Expr[] params, int[] types)
           
static ExprCall newCall(java.lang.String var, java.lang.String fxn, Expr[] params, int[] types, boolean expand)
           
static NewJava newJava(Expr className, int line)
           
static NewJava newJava(Expr className, java.lang.Object args, int line)
           
 ExprOutBoundVar newOutBoundVar(int idx, java.lang.String name, int type, Expr host, boolean inOut)
           
 Expr nonAssignExpr(java.lang.Object o)
           
static Script parse(java.lang.String name, java.io.File f, java.lang.String enc, long lastMod, boolean dbg)
           
static Script parse(java.lang.String name, java.lang.String path, java.io.InputStream is, java.lang.String enc, long lastMod, boolean dbg)
           
static Script parse(java.lang.String name, java.lang.String path, java.io.Reader r, java.lang.String enc, long lastMod, boolean dbg)
           
static int parseInt(java.lang.String x)
           
static java.util.HashMap parseUsage(java.lang.String fileName)
           
static Expr[] reduce(Expr[] ea)
           
static Expr reduce(java.lang.Object o)
           
 Stmt reduceBlock(BlockSimple blk)
           
 Expr reduceIt()
           
 void throwParseException(java.lang.Exception ex)
           
 void throwParseException(java.lang.String msg)
           
abstract  void throwParseException(java.lang.String msg, java.lang.String hint)
           
static java.lang.String unicodify(java.lang.String s)
           
static java.lang.String unquote(java.lang.String s)
           
static java.lang.String unquote(java.lang.String s, int delimLen)
           
 
Methods inherited from class com.judoscript.JudoUtil
arrayToJudoArray, checkJCE, comWrap, copy, createSimpleArith, createSimpleRelation, findFile, findFile, findFileInClasspath, findFileInJudoPath, findInClasspath, fixFilePath, fixFilePaths, fixIncludeFilePath, genTempVarName, genTempVarName, getJavaException, getJavaPrimitiveTypeName, getLocale, getPathName, getRegexEngine, getSSH, getTempDir, getTime, isDate, isGetter, isNil, loadProperties, parseParams, parseString, parseStringAsObject, processMarkup, registerToBSF, scp, toArray, toChar, toLinePrintWriter, toLinePrintWriter, toParameterNameString, toVariable, toVariable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

eol

public static final java.lang.String eol

emptyExprs

public static final Expr[] emptyExprs

script

public Script script

curFileIndex

public int curFileIndex

mixtureParser

protected MixtureParser mixtureParser

pc

protected ParsingContext pc

first

protected Expr first

rest

protected Expr[] rest

ops

protected int[] ops

stmts

protected Stmt[] stmts

labels

protected java.util.HashMap labels

inClassDef

protected boolean inClassDef

inJavaCtor

protected boolean inJavaCtor

inJavax

protected boolean inJavax

inFxnThrd

protected boolean inFxnThrd

currentNS

protected java.lang.String currentNS

definedClasses

protected java.util.HashSet definedClasses

superCalls

protected java.util.HashSet superCalls

javaxCalls

protected java.util.HashSet javaxCalls

encoding

protected java.lang.String encoding

stack

protected java.util.Stack stack
This stack is used for ()*, or rather, ()+ constructs. I believe jjtree uses the same mechanism, except that we can optimally utilize it for our grammar rules and nodes. The contents are typically String's, Expr's and Stmt's. For rules that use this stack, it should have a pointer (an int index) indicating its initial position, and at the end of the rule pop objects in the stack beyond the original position and construct whatever its return type.


SGML_BEFORE

protected static final int SGML_BEFORE
See Also:
Constant Field Values

SGML_AFTER

protected static final int SGML_AFTER
See Also:
Constant Field Values

SGML_TAG

protected static final int SGML_TAG
See Also:
Constant Field Values

SGML_DEFAULT_TAG

protected static final int SGML_DEFAULT_TAG
See Also:
Constant Field Values

SGML_TEXT

protected static final int SGML_TEXT
See Also:
Constant Field Values

SGML_SPECIAL

protected static final int SGML_SPECIAL
See Also:
Constant Field Values
Constructor Detail

ParserHelper

protected ParserHelper()
Method Detail

checkAntTask

public boolean checkAntTask(java.lang.String name)

CheckSupportedAntTask

public static final boolean CheckSupportedAntTask(java.lang.String name)

close

public void close()

addFunction

public void addFunction(Script script,
                        Function fxn)
                 throws ParseException
Throws:
ParseException

addFunction

public void addFunction(UserDefined.UserType ot,
                        Function fxn)
                 throws ParseException
Throws:
ParseException

addClassToScript

public void addClassToScript(UserDefined.UserType ot)
                      throws ParseException
Throws:
ParseException

getScriptBasePath

public java.lang.String getScriptBasePath()

markStack

protected final int markStack()

countOnStack

protected final int countOnStack(int lastMark)

newCall

public static ExprCall newCall(Expr var,
                               java.lang.String fxn,
                               Expr[] params,
                               int[] types)

newCall

public static ExprCall newCall(java.lang.String var,
                               java.lang.String fxn,
                               Expr[] params,
                               int[] types)

newCall

public static ExprCall newCall(java.lang.String var,
                               java.lang.String fxn,
                               Expr[] params,
                               int[] types,
                               boolean expand)

newJava

public static NewJava newJava(Expr className,
                              java.lang.Object args,
                              int line)

newJava

public static NewJava newJava(Expr className,
                              int line)

handleSingleExpr

protected final Expr handleSingleExpr(int lastMark)

handleSingleExpr

protected final Expr handleSingleExpr()

handleBlock

protected BlockSimple handleBlock(int lastMark,
                                  java.lang.String exceptionName,
                                  int begin)
Returns:
BlockSimple or Block.

handleAny

protected final java.lang.Object[] handleAny(int lastMark)

handleStrings

protected final java.lang.String[] handleStrings(int lastMark)

handleExprs

protected final Expr[] handleExprs(int lastMark)
rest is set and returned. On the stack is: (Expr)+


handleMultiBase1

protected final boolean handleMultiBase1(int lastMark)
If true is returned, then first and rest are set. On the stack is: Expr, (Expr)+


handleMultiBase

protected final boolean handleMultiBase(int lastMark)
If true is returned, then ops, first and rest are set. On the stack is: Expr, (Interger, Expr)*


handleStmts

protected boolean handleStmts(int lastMark)
If true is returned, then stmts and labels are set. On the stack are: (String|Stmt)*


handleNamedExprs

protected final AssociateList handleNamedExprs(int lastMark)

handleMixture

protected final Expr handleMixture(java.lang.Object[] oa)

handleMixture

protected final Expr handleMixture(int beginLine,
                                   int endLine,
                                   java.lang.Object[] oa)

handlePragma

public void handlePragma(int lineNo,
                         java.lang.String pragma,
                         Variable val)

reduceBlock

public Stmt reduceBlock(BlockSimple blk)

newBindVar

public final ExprBindVar newBindVar(int idx,
                                    java.lang.String name,
                                    int type,
                                    java.lang.String typeName,
                                    Expr expr)

newOutBoundVar

public final ExprOutBoundVar newOutBoundVar(int idx,
                                            java.lang.String name,
                                            int type,
                                            Expr host,
                                            boolean inOut)
                                     throws ParseException
Throws:
ParseException

getTargetID

public int getTargetID(java.lang.String targetName)
                throws ParseException
Throws:
ParseException

nonAssignExpr

public Expr nonAssignExpr(java.lang.Object o)
                   throws ParseException
Throws:
ParseException

reduceIt

public final Expr reduceIt()

reduce

public static Expr reduce(java.lang.Object o)

reduce

public static Expr[] reduce(Expr[] ea)

handleForIn

protected Expr handleForIn(int lineNum,
                           AccessVar avar,
                           Expr arr,
                           Expr from,
                           Expr to,
                           Expr step,
                           boolean backward,
                           Expr[] forInit,
                           Expr[] forNext,
                           Stmt[] preStmts)

defineJavaPackages

public final void defineJavaPackages(java.lang.String pkgName,
                                     java.lang.String javaPkg)

handleJavaPackages

public final void handleJavaPackages(int lineNo,
                                     java.lang.String pkgId,
                                     java.lang.String var)
                              throws ParseException
Throws:
ParseException

evalConstToBool

public boolean evalConstToBool(Expr expr,
                               boolean def)

isOctalChar

public static final boolean isOctalChar(char ch)

unquote

public static java.lang.String unquote(java.lang.String s)

unquote

public static java.lang.String unquote(java.lang.String s,
                                       int delimLen)

unicodify

public static java.lang.String unicodify(java.lang.String s)

parseInt

public static int parseInt(java.lang.String x)

handleRegexLiteral

public Variable handleRegexLiteral(java.lang.String literal)
                            throws ParseException
Throws:
ParseException

cleanup

protected void cleanup()

throwParseException

public abstract void throwParseException(java.lang.String msg,
                                         java.lang.String hint)
                                  throws ParseException
Throws:
ParseException

throwParseException

public final void throwParseException(java.lang.String msg)
                               throws ParseException
Throws:
ParseException

throwParseException

public final void throwParseException(java.lang.Exception ex)
                               throws ParseException
Throws:
ParseException

addSgmlHandler

public void addSgmlHandler(ParserHelper.SgmlEvent evt,
                           StmtHtml hndlr)
stmts is expected to be processed, which can be null


parse

public static Script parse(java.lang.String name,
                           java.lang.String path,
                           java.io.InputStream is,
                           java.lang.String enc,
                           long lastMod,
                           boolean dbg)
                    throws ParseException,
                           java.io.IOException
Throws:
ParseException
java.io.IOException

parse

public static Script parse(java.lang.String name,
                           java.io.File f,
                           java.lang.String enc,
                           long lastMod,
                           boolean dbg)
                    throws ParseException,
                           java.io.IOException
Throws:
ParseException
java.io.IOException

parse

public static Script parse(java.lang.String name,
                           java.lang.String path,
                           java.io.Reader r,
                           java.lang.String enc,
                           long lastMod,
                           boolean dbg)
                    throws ParseException,
                           java.io.IOException
Throws:
ParseException
java.io.IOException

parseUsage

public static java.util.HashMap parseUsage(java.lang.String fileName)