Package cruise.umple.parser.rules
Class Terminal
java.lang.Object
cruise.umple.parser.rules.ChoiceRule
cruise.umple.parser.rules.Terminal
public class Terminal extends ChoiceRule
Terminals are the only rules that actually don't use sub rules, instead, they use regex to compute whether there is a successful parse.
for example if the parse position is at "String name;" the terminal which was created with the ~ (alphanumeric) symbol, will parse the
String(excluding whitespace) and will return the position so that the next parse position will be "name;"
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description void
cannotHaveNewline()
This function removes the argument string from the regexvoid
delete()
boolean
getCanBeNull()
for determining whether "" is an acceptable parsejava.lang.String
getCannotBe()
A regex which, if matched by the parse, will cause the terminal to return -1(Failure).java.util.regex.Pattern
getCannotBePattern()
The pattern associated to the cannotBe attributeboolean
getCannotHaveNewline()
java.lang.String
getFirstValue()
For finding the first value of the next terminal in the rule.java.lang.String
getFollowing()
boolean
getFollowingOptional()
boolean
getLookBack()
(not used)boolean
getMustHaveSpaceFollowing()
boolean
getOnlyValue()
If true this is a STATIC token, which are things like braces and keywordsboolean
getOptional()
isOptional will return this value for Terminaljava.util.regex.Pattern
getPattern()
The main pattern, which is checked first for passingjava.util.regex.Pattern
getPattern2()
Usually null except in the case where you have a premodifier-less token [token] and then an optional rule of some kind, which means that the first parse should try to parse as if the second rule is present, that is the regex becomes regex+nextRule.getFirstValue()java.lang.String
getRegex()
the inner regex(i.e.boolean
getStrictRegex()
boolean
isOptional()
returns optionalChoiceRule
onlyValue()
onlyValue is used for determining if the terminal is a token or a STATIC.int
parse(Token token, int from, int max, java.lang.String input, ParserDataPackage data)
Returns the result of the regex matching the input string.void
redoRegex(java.lang.String regex)
re-initializes the regexvoid
redoRegex(java.lang.String regex, java.lang.String following, boolean optional)
re-initializes the regex with a given value that can follow the regex(this value should be commuted with getFirstValue).boolean
setCanBeNull(boolean aCanBeNull)
boolean
setCannotBe(java.lang.String aCannotBe)
boolean
setCannotBePattern(java.util.regex.Pattern aCannotBePattern)
boolean
setCannotHaveNewline(boolean aCannotHaveNewline)
boolean
setFollowing(java.lang.String aFollowing)
boolean
setFollowingOptional(boolean aFollowingOptional)
boolean
setLookBack(boolean aLookBack)
boolean
setMustHaveSpaceFollowing(boolean aMustHaveSpaceFollowing)
boolean
setOnlyValue(boolean aOnlyValue)
boolean
setOptional(boolean aOptional)
boolean
setPattern(java.util.regex.Pattern aPattern)
boolean
setPattern2(java.util.regex.Pattern aPattern2)
boolean
setRegex(java.lang.String aRegex)
boolean
setStrictRegex(boolean aStrictRegex)
static void
space(java.lang.String string)
to set the space (for the grammar it's " \t", for the UmpleGrammar " \t\n"java.lang.StringBuilder
toCannotBeString(java.lang.StringBuilder builder)
java.lang.StringBuilder
toDeclareString(java.lang.StringBuilder builder)
java.lang.StringBuilder
toRedoRegexString(java.lang.StringBuilder builder)
java.lang.String
toString()
Methods inherited from class cruise.umple.parser.rules.ChoiceRule
add, add, addAllTokens, addRule, addToken, dontCare, findPosition, get, getAction, getDeclared, getDontDelete, getFirstValueBuilder, getName, getNegate, getNoSpaces, getParent, getReset, getRule, getRules, hasRules, indexOf, indexOfRule, isNoSpaces, numberOfRules, optimize, optimizeCondition, remove, remove, removeRule, resetDeclare, setAction, setDeclared, setDontDelete, setFirstValueBuilder, setName, setNegate, setNoSpaces, setParent, setReset, setSubrules, size
-
Constructor Details
-
Method Details
-
setRegex
public boolean setRegex(java.lang.String aRegex) -
setCannotBe
public boolean setCannotBe(java.lang.String aCannotBe) -
setCannotBePattern
public boolean setCannotBePattern(java.util.regex.Pattern aCannotBePattern) -
setPattern
public boolean setPattern(java.util.regex.Pattern aPattern) -
setPattern2
public boolean setPattern2(java.util.regex.Pattern aPattern2) -
setOnlyValue
public boolean setOnlyValue(boolean aOnlyValue) -
setOptional
public boolean setOptional(boolean aOptional)- Overrides:
setOptional
in classChoiceRule
-
setLookBack
public boolean setLookBack(boolean aLookBack) -
setCanBeNull
public boolean setCanBeNull(boolean aCanBeNull) -
setStrictRegex
public boolean setStrictRegex(boolean aStrictRegex) -
setFollowingOptional
public boolean setFollowingOptional(boolean aFollowingOptional) -
setFollowing
public boolean setFollowing(java.lang.String aFollowing) -
setCannotHaveNewline
public boolean setCannotHaveNewline(boolean aCannotHaveNewline) -
setMustHaveSpaceFollowing
public boolean setMustHaveSpaceFollowing(boolean aMustHaveSpaceFollowing) -
getRegex
public java.lang.String getRegex()the inner regex(i.e. not the whitespace considerations or the neccessary trailing .* -
getCannotBe
public java.lang.String getCannotBe()A regex which, if matched by the parse, will cause the terminal to return -1(Failure). This is useful for such cases as a rolename consuming the "sorted" token -
getCannotBePattern
public java.util.regex.Pattern getCannotBePattern()The pattern associated to the cannotBe attribute -
getPattern
public java.util.regex.Pattern getPattern()The main pattern, which is checked first for passing -
getPattern2
public java.util.regex.Pattern getPattern2()Usually null except in the case where you have a premodifier-less token [token] and then an optional rule of some kind, which means that the first parse should try to parse as if the second rule is present, that is the regex becomes regex+nextRule.getFirstValue() -
getOnlyValue
public boolean getOnlyValue()If true this is a STATIC token, which are things like braces and keywords -
getOptional
public boolean getOptional()isOptional will return this value for Terminal- Overrides:
getOptional
in classChoiceRule
-
getLookBack
public boolean getLookBack()(not used) -
getCanBeNull
public boolean getCanBeNull()for determining whether "" is an acceptable parse -
getStrictRegex
public boolean getStrictRegex() -
getFollowingOptional
public boolean getFollowingOptional() -
getFollowing
public java.lang.String getFollowing() -
getCannotHaveNewline
public boolean getCannotHaveNewline() -
getMustHaveSpaceFollowing
public boolean getMustHaveSpaceFollowing() -
delete
public void delete()- Overrides:
delete
in classChoiceRule
-
parse
Returns the result of the regex matching the input string. Where the parseResult is the futurthest including spaces.- Overrides:
parse
in classChoiceRule
-
onlyValue
onlyValue is used for determining if the terminal is a token or a STATIC. -
space
public static void space(java.lang.String string)to set the space (for the grammar it's " \t", for the UmpleGrammar " \t\n" -
isOptional
public boolean isOptional()returns optional- Overrides:
isOptional
in classChoiceRule
-
getFirstValue
public java.lang.String getFirstValue()Description copied from class:ChoiceRule
For finding the first value of the next terminal in the rule. Within the context of a choice rule this means any of the choices are a possibility- Overrides:
getFirstValue
in classChoiceRule
-
redoRegex
public void redoRegex(java.lang.String regex)re-initializes the regex -
redoRegex
public void redoRegex(java.lang.String regex, java.lang.String following, boolean optional)re-initializes the regex with a given value that can follow the regex(this value should be commuted with getFirstValue). -
cannotHaveNewline
public void cannotHaveNewline()This function removes the argument string from the regex -
toDeclareString
public java.lang.StringBuilder toDeclareString(java.lang.StringBuilder builder)- Overrides:
toDeclareString
in classChoiceRule
-
toRedoRegexString
public java.lang.StringBuilder toRedoRegexString(java.lang.StringBuilder builder)- Overrides:
toRedoRegexString
in classChoiceRule
-
toCannotBeString
public java.lang.StringBuilder toCannotBeString(java.lang.StringBuilder builder)- Overrides:
toCannotBeString
in classChoiceRule
-
toString
public java.lang.String toString()- Overrides:
toString
in classChoiceRule
-