Package gov.nih.mipav.model.scripting
Class ParserEngine
java.lang.Object
gov.nih.mipav.model.scripting.ParserEngine
Performs the heavy-lifting of parsing out individual lines from a script.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intThe number of the current (or last if not currently parsing) line being parsed (1-based).private static final PatternThis regular expression pattern breaks apart an action parameter string into three parts: param label, param data type, and param data.private static final StringThe delimiter used to split up a String containing all of the parameters which should be parsed and passed to an action.private StringThe path to the script file to be parsed ('-' if the script is already in memory and has no related file).private static final PatternThis 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 BufferedReaderThe reader used to read in each line of the script. -
Constructor Summary
ConstructorsConstructorDescriptionParserEngine(String script, boolean scriptIsFileToParse) Creates a new ParserEngine object. -
Method Summary
Modifier and TypeMethodDescriptionvoidfinalize()Clean up memory used by the parser engine and make sure the reader we used is closed.intReturns the line number of the last line parsed by the parser engine.booleanReturns whether there are more lines in the script to be parsed.private static booleanisCommentLine(String scriptLine) Checks to see if a line is a comment.private BufferedReaderopenScriptFile(String scriptFileToParse) Open a script file and prepare a reader for it.private BufferedReaderopenScriptString(String scriptDataToParse) Prepare a reader for a given string of script data.private ParsedActionLineParses a line from a script.Parse and return the next line in the script.private ParameterparseParameterInfo(String paramInfo) Parse out the individual parameter information from a string.private ParameterTableparseParameters(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.voidResets the parser to the beginning of the script.
-
Field Details
-
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
This regular expression pattern breaks apart an action parameter string into three parts: param label, param data type, and param data. -
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:
-
currentScriptLineNumber
private int currentScriptLineNumberThe number of the current (or last if not currently parsing) line being parsed (1-based). -
scriptFile
The path to the script file to be parsed ('-' if the script is already in memory and has no related file). -
scriptReader
The reader used to read in each line of the script.
-
-
Constructor Details
-
ParserEngine
Creates 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 Details
-
finalize
public void finalize()Clean up memory used by the parser engine and make sure the reader we used is closed. -
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
Returns 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
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
Resets the parser to the beginning of the script.- Throws:
ParserException- If a problem is encountered while resetting the script parser.
-
isCommentLine
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
Open 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
Prepare 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
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
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
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.
-