Package quickparse.grammar
Class Rule.Builder
java.lang.Object
quickparse.grammar.Rule.Builder
- Enclosing class:
- Rule
public static class Rule.Builder
extends java.lang.Object
Class that implements the Builder creational design pattern, that is used to build new
rules.-
Method Summary
Modifier and Type Method Description Rulebuild()Builds the rule.Rule.Builderconstruct(java.lang.String name)Specifies a construct to insert in the body of therule.Ruleproduces(java.lang.String... symbols)Sets the list of symbols that compose the head construct of therule.
Invoking this method is equivalent to invoke one or more times theconstruct(String)and thetoken(String, String)methods, and then invoking thebuild()method to tget the rule.
An invocation of this method must be done by coding the symbols as plain strings: a Construct Symbol is specified by simply indicating the name of the symbol as string (e.g., "if" or "else"); a Token Symbol is specified by indicating the name of the symbol, followed by a colon and a regular expression that matches it (e.g., "var_name:[a-zA-Z][a-zA-Z0-9\_]*", for a Java variable name) This method can be helpful to simplify the definition of agrammardirectly in the code and to render it more readable by humans, respect to invoking many and many times theconstruct(String)and thetoken(String, String)methods in the same grammar.Rule.Buildertoken(java.lang.String name, java.lang.String pattern)Specifies a token to insert in the body of therule.
-
Method Details
-
produces
Sets the list of symbols that compose the head construct of therule.
Invoking this method is equivalent to invoke one or more times theconstruct(String)and thetoken(String, String)methods, and then invoking thebuild()method to tget the rule.
An invocation of this method must be done by coding the symbols as plain strings:- a Construct Symbol is specified by simply indicating the name of the symbol as string (e.g., "if" or "else");
- a Token Symbol is specified by indicating the name of the symbol, followed by a colon and a regular expression that matches it (e.g., "var_name:[a-zA-Z][a-zA-Z0-9\_]*", for a Java variable name)
grammardirectly in the code and to render it more readable by humans, respect to invoking many and many times theconstruct(String)and thetoken(String, String)methods in the same grammar.- Parameters:
symbols- the body symbols- Returns:
- a new
rule - See Also:
construct(String),token(String, String)
-
construct
Specifies a construct to insert in the body of therule. A construct is identified by its name only.- Parameters:
name- the construct name- Returns:
- this same
builder
-
token
Specifies a token to insert in the body of therule. A token is identified by its name and by its pattern. The pattern of a token is a Regular Expression that is interpreted by the Java Regular Expression framework.- Parameters:
name- the token namepattern- the Regular Expression that matches the token symbol.- Returns:
- this same
builder
-
build
Builds the rule.- Returns:
- a new
Ruleinstance
-