org.jmol.script
Class ScriptCompiler

java.lang.Object
  extended by org.jmol.script.ScriptCompilationTokenParser
      extended by org.jmol.script.ScriptCompiler

public class ScriptCompiler
extends ScriptCompilationTokenParser


Field Summary
private  Token[][] aatokenCompiled
           
private  int braceCount
           
private  int bracketCount
           
private  int cchScript
           
private  int cchToken
           
(package private)  char chFirst
           
private  String comment
           
private  Hashtable contextVariables
           
private static int CONTINUE
           
private  boolean endOfLine
           
private static int EOL
           
private static int ERROR
           
private  String filename
           
private  ScriptFlowContext flowContext
           
private  int forPoint3
           
private  boolean haveComments
           
private  int iBrace
           
private  int ichBrace
           
private  boolean iHaveQuotedString
           
private  boolean isCheckOnly
           
private  boolean isEndOfCommand
           
private  boolean isShowCommand
           
private  boolean isShowScriptOutput
           
private  boolean isSilent
           
private  boolean isUserToken
           
private  int[][] lineIndices
           
private  short[] lineNumbers
           
private  List lltoken
           
private  int lnLength
           
private  List ltoken
           
private  boolean needRightParen
           
private  int nSemiSkip
           
private static int OK
           
private static int OK2
           
private  int parenCount
           
private  boolean preDefining
           
private  int ptSemi
           
(package private)  int pushCount
           
(package private)  String scriptExtensions
           
private  int setBraceCount
           
private  int setEqualPt
           
private  ScriptFunction thisFunction
           
private  int tokInitialPlusPlus
           
private  int tokLastMath
           
private  List vBraces
           
private  List vFunctionStack
           
(package private)  List vPush
           
 
Fields inherited from class org.jmol.script.ScriptCompilationTokenParser
atokenInfix, ERROR_badArgumentCount, ERROR_badContext, ERROR_commandExpected, ERROR_endOfCommandUnexpected, ERROR_invalidExpressionToken, ERROR_missingEnd, ERROR_tokenExpected, ERROR_tokenUnexpected, ERROR_unrecognizedParameter, ERROR_unrecognizedToken, errorLine, errorMessage, errorMessageUntranslated, errorType, haveString, htUserFunctions, ichComment, ichCurrentCommand, ichEnd, ichToken, iCommand, isCommaAsOrAllowed, isEmbeddedExpression, isMathExpressionCommand, isNewSet, isSetBrace, isSetOrDefine, isStateScript, itokenInfix, lastFlowCommand, lastToken, lineCurrent, logMessages, nTokens, ptNewSetModifier, script, theTok, theToken, tokCommand, tokenAndEquals, tokenCommand, viewer
 
Constructor Summary
ScriptCompiler(ScriptCompiler compiler)
           
ScriptCompiler(Viewer viewer)
           
 
Method Summary
(package private) static void addContextVariable(Hashtable contextVariables, String ident)
           
private  void addContextVariable(String ident)
           
private  void addTokenToPrefix(Token token)
           
private  boolean charToken()
           
private  boolean checkFlowCommand(String ident)
           
private  boolean checkFlowEnd(int tok, String ident, int pt1)
           
private  int checkFlowEndBrace()
           
private  boolean checkFlowStartBrace(boolean atEnd)
           
private  boolean checkNewSetCommand()
           
private  int checkSpecialParameterSyntax()
           
private  void checkUnquotedFileName()
           
private  String cleanScriptComments(String script)
          allows for three kinds of comments.
(package private)  ScriptContext compile(String filename, String script, boolean isPredefining, boolean isSilent, boolean debugScript, boolean isCheckOnly)
           
private  boolean compile0(boolean isFull)
           
private  boolean compileCommand()
           
private  boolean eol(char ch)
           
(package private) static boolean eol(char ch, int nSkip)
           
private  int ERROR(int error)
           
private  int ERROR(int error, String value)
           
private  int forceFlowEnd(Token token)
           
private  boolean getData(String key)
           
static String getEmbeddedScript(String script)
           
private  String getPrefixToken()
           
(package private)  String getUnescapedStringLiteral()
           
private  boolean handleError()
           
static int ichMathTerminator(String script, int ichT, int len)
          For @{....}
private  int incrementLineCount(String str)
           
(package private) static boolean isBreakableContext(int tok)
           
private  boolean isContextVariable(String ident)
           
private  boolean isLineContinuation(int ichT, boolean checkMathop)
           
private static boolean isSpaceOrTab(char ch)
           
(package private)  BitSet lookingAtBitset()
           
private  boolean lookingAtBraceSyntax()
           
private  int lookingAtComment()
           
private  boolean lookingAtDecimal()
           
private  boolean lookingAtEndOfLine()
           
private  boolean lookingAtEndOfStatement()
           
private  float lookingAtExponential()
           
private  boolean lookingAtImpliedString(boolean allowSpace)
          An "implied string" is a parameter that is not quoted but because of its position in a command is implied to be a string.
private  int lookingAtInteger()
           
private  boolean lookingAtLeadingWhitespace()
           
private  boolean lookingAtLoadFormat()
           
private  boolean lookingAtLookupToken(int ichT)
           
private  boolean lookingAtMathContinuation(int ichT)
           
private  Object lookingAtMatrix()
           
private  boolean lookingAtObjectID(boolean allowWildID)
           
private  boolean lookingAtSeqcode()
           
private  boolean lookingAtString(boolean allowPrime)
           
private  int nCharNewLine(int ichT)
           
private  char nextChar()
           
private  int parseCommandParameter(String ident)
           
private  int parseKnownToken(String ident)
           
private  ScriptContext parseScript(boolean doFull)
           
(package private)  ScriptContext parseScriptForTokens(String script)
          return a structure that is only the first part of the process - identifying lines and commands for the scriptEditor
private  int processTokenList(short iLine, boolean doCompile)
           
private  void replaceCommand(Token token)
           
private  void setAaTokenCompiled()
           
private  Token setCommand(Token token)
           
private  Token setNewSetCommand(boolean isSetBrace, String ident)
           
static String[] splitCommandLine(String cmd)
          used by app to separate a command line into three sections: prefix....;cmd ........
protected  int tokAt(int i)
           
private  Token tokenAt(int i)
           
private  void tokenizePlusPlus(int tok, boolean isPlusPlusX)
           
 
Methods inherited from class org.jmol.script.ScriptCompilationTokenParser
commandExpected, compileExpression, compileExpressions, error, error, error, error, errorString, isUserFunction, tokenAttr
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filename

private String filename

isSilent

private boolean isSilent

contextVariables

private Hashtable contextVariables

aatokenCompiled

private Token[][] aatokenCompiled

lineNumbers

private short[] lineNumbers

lineIndices

private int[][] lineIndices

lnLength

private int lnLength

preDefining

private boolean preDefining

isShowScriptOutput

private boolean isShowScriptOutput

isCheckOnly

private boolean isCheckOnly

haveComments

private boolean haveComments

scriptExtensions

String scriptExtensions

thisFunction

private ScriptFunction thisFunction

flowContext

private ScriptFlowContext flowContext

ltoken

private List ltoken

lltoken

private List lltoken

vBraces

private List vBraces

ichBrace

private int ichBrace

cchToken

private int cchToken

cchScript

private int cchScript

nSemiSkip

private int nSemiSkip

parenCount

private int parenCount

braceCount

private int braceCount

setBraceCount

private int setBraceCount

bracketCount

private int bracketCount

ptSemi

private int ptSemi

forPoint3

private int forPoint3

setEqualPt

private int setEqualPt

iBrace

private int iBrace

iHaveQuotedString

private boolean iHaveQuotedString

isEndOfCommand

private boolean isEndOfCommand

needRightParen

private boolean needRightParen

endOfLine

private boolean endOfLine

comment

private String comment

OK

private static final int OK
See Also:
Constant Field Values

OK2

private static final int OK2
See Also:
Constant Field Values

CONTINUE

private static final int CONTINUE
See Also:
Constant Field Values

EOL

private static final int EOL
See Also:
Constant Field Values

ERROR

private static final int ERROR
See Also:
Constant Field Values

tokLastMath

private int tokLastMath

vFunctionStack

private List vFunctionStack

isShowCommand

private boolean isShowCommand

isUserToken

private boolean isUserToken

tokInitialPlusPlus

private int tokInitialPlusPlus

vPush

List vPush

pushCount

int pushCount

chFirst

char chFirst
Constructor Detail

ScriptCompiler

public ScriptCompiler(Viewer viewer)

ScriptCompiler

public ScriptCompiler(ScriptCompiler compiler)
Method Detail

parseScriptForTokens

ScriptContext parseScriptForTokens(String script)
return a structure that is only the first part of the process - identifying lines and commands for the scriptEditor

Parameters:
script -
Returns:
ScriptContext

parseScript

private ScriptContext parseScript(boolean doFull)

compile

ScriptContext compile(String filename,
                      String script,
                      boolean isPredefining,
                      boolean isSilent,
                      boolean debugScript,
                      boolean isCheckOnly)

addContextVariable

private void addContextVariable(String ident)

addContextVariable

static void addContextVariable(Hashtable contextVariables,
                               String ident)

isContextVariable

private boolean isContextVariable(String ident)

cleanScriptComments

private String cleanScriptComments(String script)
allows for three kinds of comments. NOTE: closing involves asterisks and slash together, but that can't be shown here. 1) /** .... ** / super-comment 2) /* ..... * / may be INSIDE /**....** /). 3) \n//.....\n single-line comments -- like #, but removed entirely The reason is that /* ... * / will appear as standard in MOVETO command but we still might want to escape it, so around that you can have /** .... ** / The terminator is not necessary -- so you can quickly escape anything in a file after /** or /* In addition, we can have [/*|/**] .... **** Jmol Embedded Script **** [script commands] [** /|* /] Then ONLY that script is taken. This is a powerful and simple way then to include Jmol scripting in any file -- including, for example, HTML as an HTML comment. Just send the whole file to Jmol, and it will find its script!

Parameters:
script -
Returns:
cleaned script

getEmbeddedScript

public static String getEmbeddedScript(String script)

addTokenToPrefix

private void addTokenToPrefix(Token token)

compile0

private boolean compile0(boolean isFull)

setAaTokenCompiled

private void setAaTokenCompiled()

lookingAtLeadingWhitespace

private boolean lookingAtLeadingWhitespace()

isLineContinuation

private boolean isLineContinuation(int ichT,
                                   boolean checkMathop)

lookingAtMathContinuation

private boolean lookingAtMathContinuation(int ichT)

lookingAtEndOfLine

private boolean lookingAtEndOfLine()

nCharNewLine

private int nCharNewLine(int ichT)

lookingAtEndOfStatement

private boolean lookingAtEndOfStatement()

lookingAtComment

private int lookingAtComment()

processTokenList

private int processTokenList(short iLine,
                             boolean doCompile)

compileCommand

private boolean compileCommand()

tokenAt

private Token tokenAt(int i)

tokAt

protected int tokAt(int i)
Overrides:
tokAt in class ScriptCompilationTokenParser

setCommand

private Token setCommand(Token token)

replaceCommand

private void replaceCommand(Token token)

getPrefixToken

private String getPrefixToken()

checkSpecialParameterSyntax

private int checkSpecialParameterSyntax()

lookingAtMatrix

private Object lookingAtMatrix()

parseKnownToken

private int parseKnownToken(String ident)

tokenizePlusPlus

private void tokenizePlusPlus(int tok,
                              boolean isPlusPlusX)

checkNewSetCommand

private boolean checkNewSetCommand()

parseCommandParameter

private int parseCommandParameter(String ident)

setNewSetCommand

private Token setNewSetCommand(boolean isSetBrace,
                               String ident)

nextChar

private char nextChar()

checkUnquotedFileName

private void checkUnquotedFileName()

checkFlowStartBrace

private boolean checkFlowStartBrace(boolean atEnd)

checkFlowEndBrace

private int checkFlowEndBrace()

forceFlowEnd

private int forceFlowEnd(Token token)

isBreakableContext

static boolean isBreakableContext(int tok)

checkFlowCommand

private boolean checkFlowCommand(String ident)

checkFlowEnd

private boolean checkFlowEnd(int tok,
                             String ident,
                             int pt1)

getData

private boolean getData(String key)

incrementLineCount

private int incrementLineCount(String str)

isSpaceOrTab

private static boolean isSpaceOrTab(char ch)

eol

private boolean eol(char ch)

eol

static boolean eol(char ch,
                   int nSkip)

lookingAtBraceSyntax

private boolean lookingAtBraceSyntax()

lookingAtString

private boolean lookingAtString(boolean allowPrime)

getUnescapedStringLiteral

String getUnescapedStringLiteral()

lookingAtLoadFormat

private boolean lookingAtLoadFormat()

lookingAtImpliedString

private boolean lookingAtImpliedString(boolean allowSpace)
An "implied string" is a parameter that is not quoted but because of its position in a command is implied to be a string. First we must exclude @xxxx. Then we consume the entire math syntax @{......} or any set of characters not involving white space. echo, hover, label, message, pause are odd-valued; no initial parsing of variables for them.

Parameters:
allowSpace -
Returns:
true or false

ichMathTerminator

public static int ichMathTerminator(String script,
                                    int ichT,
                                    int len)
For @{....}

Parameters:
script -
ichT -
len -
Returns:
position of "}"

lookingAtExponential

private float lookingAtExponential()

lookingAtDecimal

private boolean lookingAtDecimal()

lookingAtSeqcode

private boolean lookingAtSeqcode()

lookingAtInteger

private int lookingAtInteger()

lookingAtBitset

BitSet lookingAtBitset()

lookingAtObjectID

private boolean lookingAtObjectID(boolean allowWildID)

lookingAtLookupToken

private boolean lookingAtLookupToken(int ichT)

charToken

private boolean charToken()

ERROR

private int ERROR(int error)

ERROR

private int ERROR(int error,
                  String value)

handleError

private boolean handleError()

splitCommandLine

public static String[] splitCommandLine(String cmd)
used by app to separate a command line into three sections: prefix....;cmd ........ token where token can be a just-finished single or double quote or a string of characters

Parameters:
cmd -
Returns:
String[] {prefix, cmd..... token}