Package cruise.umple.parser.analysis
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 Summary
Fields Modifier and Type Field Description static java.util.HashMap<java.lang.String,ChoiceRule>
choicerules
static int
parsing
-
Constructor Summary
Constructors Constructor Description RuleBasedParser()
-
Method Summary
Modifier and Type Method Description boolean
addGrammarFile(java.lang.String aGrammarFile)
void
addParserAction(java.lang.String name, ParserAction action)
Adds a parser action to operate on an action token of the specified namevoid
delete()
static boolean
evaluate(java.lang.String hash)
static GrammarAnalyzer
getAnalyzer()
AnalyzerGeneratorHandler
getAnalyzerGenerator()
Position
getFailedPosition()
java.lang.String
getGrammarFile(int index)
java.lang.String[]
getGrammarFiles()
Token
getGRootToken()
LinkedFileHandler
getLinkedFileHandler()
ParseResult
getParseResult()
The parse's result, it will either have the value of success or failure, and should not be null after a parseToken
getRootToken()
the Root Token that will be contain the result of the parse of the umple fileboolean
hasFailedPosition()
boolean
hasGrammarFiles()
int
indexOfGrammarFile(java.lang.String aGrammarFile)
int
numberOfGrammarFiles()
void
parse(ChoiceRule root, Token token, java.lang.String filename, int line, ParserDataPackage data)
void
parse(ChoiceRule root, Token token, java.lang.String filename, ParserDataPackage data)
Takes a root rule and uses it to start parsing.ParseResult
parse(java.io.File file)
Takes a file and parses it, returning the ParseResultParseResult
parse(java.io.File file, java.io.File[] linkedFiles)
Takes a file and parses it, returning the ParseResultParseResult
parse(java.lang.String ruleName, java.lang.String input)
ParseResult
parse(java.lang.String ruleName, java.lang.String input, java.lang.String fileName, Position position, int lineNumber, int offset)
void
readGrammarFiles()
boolean
removeGrammarFile(java.lang.String aGrammarFile)
void
setAnalyzerGenerator(AnalyzerGeneratorHandler aAnalyzerGenerator)
retroactively change the analyzer generator if an analyzer is already constructedboolean
setFailedPosition(Position aNewFailedPosition)
void
setLinkedFileHandler(LinkedFileHandler aLinkedFileHandler)
retroactively change the linked file handler if an analyzer is already constructedboolean
setParseResult(ParseResult aParseResult)
boolean
setRootToken(Token aRootToken)
void
setupRules()
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.java.lang.String
toString()
-
Field Details
-
parsing
public static int parsing -
choicerules
-
-
Constructor Details
-
RuleBasedParser
public RuleBasedParser()
-
-
Method Details
-
setRootToken
-
setParseResult
-
addGrammarFile
public boolean addGrammarFile(java.lang.String aGrammarFile) -
removeGrammarFile
public boolean removeGrammarFile(java.lang.String aGrammarFile) -
getRootToken
the Root Token that will be contain the result of the parse of the umple file -
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
-
hasFailedPosition
public boolean hasFailedPosition() -
setFailedPosition
-
delete
public void delete() -
getAnalyzer
-
getGRootToken
-
parse
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
Adds a parser action to operate on an action token of the specified name- Parameters:
name
- the name of the token to perform the actionaction
- 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
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
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
-
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
retroactively change the linked file handler if an analyzer is already constructed -
getLinkedFileHandler
-
setAnalyzerGenerator
retroactively change the analyzer generator if an analyzer is already constructed -
getAnalyzerGenerator
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-