Package gov.nih.mipav.model.scripting
Class ParserEngine
- java.lang.Object
-
- gov.nih.mipav.model.scripting.ParserEngine
-
public class ParserEngine extends java.lang.ObjectPerforms the heavy-lifting of parsing out individual lines from a script.
-
-
Field Summary
Fields Modifier and Type Field Description private intcurrentScriptLineNumberThe number of the current (or last if not currently parsing) line being parsed (1-based).private static java.util.regex.PatternparamInfoRegexThis regular expression pattern breaks apart an action parameter string into three parts: param label, param data type, and param data.private static java.lang.StringparamListDelimiterThe delimiter used to split up a String containing all of the parameters which should be parsed and passed to an action.private java.lang.StringscriptFileThe path to the script file to be parsed ('-' if the script is already in memory and has no related file).private static java.util.regex.PatternscriptLineRegexThis regular expression pattern breaks apart a line in a script into two groups: the script action and the string containing all the action's parameters.private java.io.BufferedReaderscriptReaderThe reader used to read in each line of the script.
-
Constructor Summary
Constructors Constructor Description ParserEngine(java.lang.String script, boolean scriptIsFileToParse)Creates a new ParserEngine object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfinalize()Clean up memory used by the parser engine and make sure the reader we used is closed.intgetCurrentLineNumber()Returns the line number of the last line parsed by the parser engine.booleanhasMoreLinesToParse()Returns whether there are more lines in the script to be parsed.private static booleanisCommentLine(java.lang.String scriptLine)Checks to see if a line is a comment.private java.io.BufferedReaderopenScriptFile(java.lang.String scriptFileToParse)Open a script file and prepare a reader for it.private java.io.BufferedReaderopenScriptString(java.lang.String scriptDataToParse)Prepare a reader for a given string of script data.private ParsedActionLineparseLine(java.lang.String scriptLine)Parses a line from a script.ParsedActionLineparseNextLine()Parse and return the next line in the script.private ParameterparseParameterInfo(java.lang.String paramInfo)Parse out the individual parameter information from a string.private ParameterTableparseParameters(java.lang.String paramString)Splits a list of parameters into individual parameter information strings, parses the individual parameter strings, and puts the parameters into a look up table.voidresetParser()Resets the parser to the beginning of the script.
-
-
-
Field Detail
-
scriptLineRegex
private static final java.util.regex.Pattern scriptLineRegex
This regular expression pattern breaks apart a line in a script into two groups: the script action and the string containing all the action's parameters.
-
paramInfoRegex
private static final java.util.regex.Pattern paramInfoRegex
This regular expression pattern breaks apart an action parameter string into three parts: param label, param data type, and param data.
-
paramListDelimiter
private static final java.lang.String paramListDelimiter
The delimiter used to split up a String containing all of the parameters which should be parsed and passed to an action.- See Also:
- Constant Field Values
-
currentScriptLineNumber
private int currentScriptLineNumber
The number of the current (or last if not currently parsing) line being parsed (1-based).
-
scriptFile
private java.lang.String scriptFile
The path to the script file to be parsed ('-' if the script is already in memory and has no related file).
-
scriptReader
private java.io.BufferedReader scriptReader
The reader used to read in each line of the script.
-
-
Constructor Detail
-
ParserEngine
public ParserEngine(java.lang.String script, boolean scriptIsFileToParse) throws ParserExceptionCreates a new ParserEngine object.- Parameters:
script- Either the path to the script on disk, or the text of the script.scriptIsFileToParse- Iftrue, thenscriptis the path to a file on disk. Otherwise, it is the text of a script and no file should be read in from disk.- Throws:
ParserException- If a problem is encountered while parsing the script.
-
-
Method Detail
-
finalize
public void finalize()
Clean up memory used by the parser engine and make sure the reader we used is closed.- Overrides:
finalizein classjava.lang.Object
-
getCurrentLineNumber
public int getCurrentLineNumber()
Returns the line number of the last line parsed by the parser engine.- Returns:
- The line number of the last line parsed by the parser engine.
-
hasMoreLinesToParse
public boolean hasMoreLinesToParse() throws ParserExceptionReturns whether there are more lines in the script to be parsed.- Returns:
Trueif the parser engine has not reached the end of the script.- Throws:
ParserException- If a problem is encountered while parsing the script.
-
parseNextLine
public ParsedActionLine parseNextLine() throws ParserException
Parse and return the next line in the script.- Returns:
- The next line in the script, parsed into action and parameter table.
- Throws:
ParserException- If a problem is encountered while parsing the script.
-
resetParser
public void resetParser() throws ParserExceptionResets the parser to the beginning of the script.- Throws:
ParserException- If a problem is encountered while resetting the script parser.
-
isCommentLine
private static boolean isCommentLine(java.lang.String scriptLine)
Checks to see if a line is a comment.- Parameters:
scriptLine- A line from a script.- Returns:
Trueif the line is a comment,falseotherwise.
-
openScriptFile
private java.io.BufferedReader openScriptFile(java.lang.String scriptFileToParse) throws ParserExceptionOpen a script file and prepare a reader for it.- Parameters:
scriptFileToParse- Path on disk to a script file to open.- Returns:
- A reader for the script file.
- Throws:
ParserException- If a problem is encountered while parsing the script.
-
openScriptString
private java.io.BufferedReader openScriptString(java.lang.String scriptDataToParse) throws ParserExceptionPrepare a reader for a given string of script data.- Parameters:
scriptDataToParse- The contents of a script.- Returns:
- A reader for the script contents.
- Throws:
ParserException- If a problem is encountered while parsing the script.
-
parseLine
private ParsedActionLine parseLine(java.lang.String scriptLine) throws ParserException
Parses a line from a script.- Parameters:
scriptLine- A line of text from a script.- Returns:
- The parsed-out information from the script line.
- Throws:
ParserException- If a problem is encountered while parsing the script.
-
parseParameterInfo
private Parameter parseParameterInfo(java.lang.String paramInfo) throws ParserException
Parse out the individual parameter information from a string.- Parameters:
paramInfo- Parameter information string.- Returns:
- The new parameter.
- Throws:
ParserException- If a problem is encountered while parsing the script.
-
parseParameters
private ParameterTable parseParameters(java.lang.String paramString) throws ParserException
Splits a list of parameters into individual parameter information strings, parses the individual parameter strings, and puts the parameters into a look up table.- Parameters:
paramString- A list of parameters.- Returns:
- A table containing all the parameters extracted from the string.
- Throws:
ParserException- If a problem is encountered while parsing the script.
-
-