Class RuleBasedParser

java.lang.Object
cruise.umple.parser.analysis.RuleBasedParser

public class RuleBasedParser
extends java.lang.Object
The rule based parser takes in umple grammar files and parses them into Rule objects(ChoiceRule, ChainRule, etc.). Really what happens is that the rulebasedparser contstructs an initial rootToken that contains all the grammar rules, and then the grammaranalyzer turns those into rules. Regardless, then we have a graph of rules which each has a parse function. The parse function is called on the root, and the parsing begins. After that there is the cleanup, that is recovery if there was a failure or getting the rootToken and storing it if not.
  • Field Details

  • Constructor Details

  • Method Details

    • setRootToken

      public boolean setRootToken​(Token aRootToken)
    • setParseResult

      public boolean setParseResult​(ParseResult aParseResult)
    • addGrammarFile

      public boolean addGrammarFile​(java.lang.String aGrammarFile)
    • removeGrammarFile

      public boolean removeGrammarFile​(java.lang.String aGrammarFile)
    • getRootToken

      public Token getRootToken()
      the Root Token that will be contain the result of the parse of the umple file
    • getParseResult

      public ParseResult getParseResult()
      The parse's result, it will either have the value of success or failure, and should not be null after a parse
    • getGrammarFile

      public java.lang.String getGrammarFile​(int index)
    • getGrammarFiles

      public java.lang.String[] getGrammarFiles()
    • numberOfGrammarFiles

      public int numberOfGrammarFiles()
    • hasGrammarFiles

      public boolean hasGrammarFiles()
    • indexOfGrammarFile

      public int indexOfGrammarFile​(java.lang.String aGrammarFile)
    • getFailedPosition

      public Position getFailedPosition()
    • hasFailedPosition

      public boolean hasFailedPosition()
    • setFailedPosition

      public boolean setFailedPosition​(Position aNewFailedPosition)
    • delete

      public void delete()
    • getAnalyzer

      public static GrammarAnalyzer getAnalyzer()
    • getGRootToken

      public Token getGRootToken()
    • parse

      public void parse​(ChoiceRule root, Token token, java.lang.String filename, ParserDataPackage data)
      Takes a root rule and uses it to start parsing. The result will be put into the root token passed. The parsing will be performed on the file. data is a DataPackage which needs to be initialized(using the init(Position)) before passing to this function. The data package will contain miscellaneous data that will be computed throughout the parsing, such as FailPosition(if parsing fails) and the location of couples(brackets and quotes).
    • addParserAction

      public void addParserAction​(java.lang.String name, ParserAction action)
      Adds a parser action to operate on an action token of the specified name
      Parameters:
      name - the name of the token to perform the action
      action - the ParserAction to perform
    • parse

      public void parse​(ChoiceRule root, Token token, java.lang.String filename, int line, ParserDataPackage data)
    • setupRules

      public void setupRules()
    • setupRules

      public void setupRules​(boolean forceParse)
      After being passed all the grammar files by the UmpleInternalParser, this function is called to compute all the rules that are associated to the umple language. For some reason this is computationally expensive, future implementations will hopefully be able to speed this up.
    • parse

      public ParseResult parse​(java.io.File file, java.io.File[] linkedFiles)
      Takes a file and parses it, returning the ParseResult
      Parameters:
      file - the file to parse
      Returns:
      the result of this parsing as a ParseResult
    • parse

      public ParseResult parse​(java.io.File file)
      Takes a file and parses it, returning the ParseResult
      Parameters:
      file - the file to parse
      Returns:
      the result of this parsing as a ParseResult
    • parse

      public ParseResult parse​(java.lang.String ruleName, java.lang.String input)
    • parse

      public ParseResult parse​(java.lang.String ruleName, java.lang.String input, java.lang.String fileName, Position position, int lineNumber, int offset)
    • evaluate

      public static boolean evaluate​(java.lang.String hash)
    • readGrammarFiles

      public void readGrammarFiles()
    • setLinkedFileHandler

      public void setLinkedFileHandler​(LinkedFileHandler aLinkedFileHandler)
      retroactively change the linked file handler if an analyzer is already constructed
    • getLinkedFileHandler

      public LinkedFileHandler getLinkedFileHandler()
    • setAnalyzerGenerator

      public void setAnalyzerGenerator​(AnalyzerGeneratorHandler aAnalyzerGenerator)
      retroactively change the analyzer generator if an analyzer is already constructed
    • getAnalyzerGenerator

      public AnalyzerGeneratorHandler getAnalyzerGenerator()
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object