Class ParserEngine

java.lang.Object
gov.nih.mipav.model.scripting.ParserEngine

public class ParserEngine extends Object
Performs the heavy-lifting of parsing out individual lines from a script.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    The number of the current (or last if not currently parsing) line being parsed (1-based).
    private static final Pattern
    This regular expression pattern breaks apart an action parameter string into three parts: param label, param data type, and param data.
    private static final String
    The delimiter used to split up a String containing all of the parameters which should be parsed and passed to an action.
    private String
    The path to the script file to be parsed ('-' if the script is already in memory and has no related file).
    private static final Pattern
    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.
    The reader used to read in each line of the script.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ParserEngine(String script, boolean scriptIsFileToParse)
    Creates a new ParserEngine object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clean up memory used by the parser engine and make sure the reader we used is closed.
    int
    Returns the line number of the last line parsed by the parser engine.
    boolean
    Returns whether there are more lines in the script to be parsed.
    private static boolean
    isCommentLine(String scriptLine)
    Checks to see if a line is a comment.
    openScriptFile(String scriptFileToParse)
    Open a script file and prepare a reader for it.
    openScriptString(String scriptDataToParse)
    Prepare a reader for a given string of script data.
    parseLine(String scriptLine)
    Parses a line from a script.
    Parse and return the next line in the script.
    private Parameter
    Parse out the individual parameter information from a string.
    parseParameters(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.
    void
    Resets the parser to the beginning of the script.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • scriptLineRegex

      private static final 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 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 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:
    • currentScriptLineNumber

      private int currentScriptLineNumber
      The number of the current (or last if not currently parsing) line being parsed (1-based).
    • scriptFile

      private 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 BufferedReader scriptReader
      The reader used to read in each line of the script.
  • Constructor Details

    • ParserEngine

      public ParserEngine(String script, boolean scriptIsFileToParse) throws ParserException
      Creates a new ParserEngine object.
      Parameters:
      script - Either the path to the script on disk, or the text of the script.
      scriptIsFileToParse - If true, then script is 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.
      Overrides:
      finalize in class 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 ParserException
      Returns whether there are more lines in the script to be parsed.
      Returns:
      True if 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 ParserException
      Resets 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(String scriptLine)
      Checks to see if a line is a comment.
      Parameters:
      scriptLine - A line from a script.
      Returns:
      True if the line is a comment, false otherwise.
    • openScriptFile

      private BufferedReader openScriptFile(String scriptFileToParse) throws ParserException
      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

      private BufferedReader openScriptString(String scriptDataToParse) throws ParserException
      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

      private ParsedActionLine parseLine(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(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(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.