Package io.vertigo.commons.peg.rule
Class PegRules
java.lang.Object
io.vertigo.commons.peg.rule.PegRules
Factory of all PeRules.
- Author:
- pchretien
-
Method Summary
Modifier and TypeMethodDescriptionstatic PegRule<PegRule.Dummy> blanks()static PegRule<PegRule.Dummy> comparison(PegRule<?> valueRule) Rule for simple comparisons.delayedComparison(PegRule<A> valueRule) Rule for comparisons with delayed term resolution.static <A,B extends Enum<B> & PegOperatorTerm<R>, R>
PegRule<PegSolver<A, R, R>> delayedOperation(PegRule<A> operandRule, Class<B> operatorClass, boolean isOperatorSpaced) Rule to resolve operations.delayedOperationAndComparison(PegRule<A> valueRule) Rule for make operations and then compare.static <A,B extends Enum<B> & PegOperatorTerm<R>, R>
PegRule<PegSolver<A, R, R>> delayedOperationLazy(PegRule<A> operandRule, Class<B> operatorClass, boolean isOperatorSpaced) Rule to resolve operations, non greedy.static <R> PegRule<R> Named a Rule.static <R> PegRule<R> Name a rule with a message key for error message.static <R> PegRule<R> Name a rule with a fixed error message.static StringnamedRulesAsHtml(PegRule<?> rootRule) static <A,B extends Enum<B> & PegOperatorTerm<A>>
PegRule<A> Rule to resolve operations.static <A,B extends Enum<B> & PegOperatorTerm<A>>
PegRule<A> operationLazy(PegRule<A> operandRule, Class<B> operatorClass, boolean isOperatorSpaced) Rule to resolve operations, non greedy.static <O> PegRule<O> static PegRule<PegRule.Dummy> static PegRule<PegRule.Dummy> skipBlanks(String blanks) word(boolean emptyAccepted, String checkedChars, PegWordRuleMode mode, String readableExpression) zeroOrMore(PegRule<R> rule, boolean untilEnd)
-
Method Details
-
named
Named a Rule.- Parameters:
innerRule- Rule to nameruleName- Rule name- Returns:
- Named rule
-
named
Name a rule with a fixed error message.- Type Parameters:
R- Type of the product text parsing- Parameters:
ruleName- Rule nameerrorMessage- Fixed error messagemainRule- Rule to name- Returns:
- Named rule
-
named
public static <R> PegRule<R> named(PegRule<R> innerRule, String ruleName, io.vertigo.core.locale.LocaleMessageKey messageKey) Name a rule with a message key for error message.- Type Parameters:
R- Type of the product text parsing- Parameters:
ruleName- Rule namemessageKey- Message key for error messagemainRule- Rule to name- Returns:
- Named rule
-
optional
- Parameters:
rule- Inner rule- Returns:
- Optional rule
-
term
- Parameters:
term- Terminal- Returns:
- Term rule
-
sequence
- Parameters:
rules- rules list- Returns:
- sequence rule of inner rules
-
sequence
- Parameters:
rules- rules list- Returns:
- sequence rule of inner rules
-
choice
- Parameters:
rules- the list of rules to test- Returns:
- choice rule of inner rules
-
choice
- Parameters:
rules- the list of rules to test- Returns:
- choice rule of inner rules
-
zeroOrMore
- Parameters:
rule- Rule to repeatuntilEnd- If text should be parsed entirely- Returns:
- zeroOrMore rule
-
oneOrMore
- Parameters:
rule- Rule to repeatuntilEnd- If text should be parsed entirely- Returns:
- oneOrMore rule
-
skipBlanks
- Parameters:
blanks- list of char to skip- Returns:
- Rule to match any blank char
-
skipBlanks
-
blanks
- Parameters:
blanks- list of char to skip- Returns:
- Rule to match any blank char
-
blanks
-
word
public static PegRule<String> word(boolean emptyAccepted, String checkedChars, PegWordRuleMode mode, String readableExpression) - Parameters:
emptyAccepted- Si les mots vides sont acceptéscheckedChars- Liste des caractères vérifiésmode- Indique le comportement du parseur : si les caractères vérifiés sont les seuls acceptés, sinon les seuls rejetés, et si l'echappement est autoriséreadableExpression- Expression nommée- Returns:
- Word rule (capture a word)
-
parseAll
- Type Parameters:
O- Result object- Parameters:
innerRule- InnerRule- Returns:
- Rule to ensure innerRull match whole text
-
namedRulesAsHtml
- Parameters:
rootRule- Root rule to start with- Returns:
- Html railroad diagram
-
delayedOperation
public static <A,B extends Enum<B> & PegOperatorTerm<R>, PegRule<PegSolver<A,R> R, delayedOperationR>> (PegRule<A> operandRule, Class<B> operatorClass, boolean isOperatorSpaced) Rule to resolve operations. The result is not resolved immediately but through a solver that resolve operands to Objects handled by the operator class.- Type Parameters:
A- Type of the operandB- Type of the operatorR- Type of the result- Parameters:
operandRule- Rule to match operands. Actual values are resolved later by the solver.operatorClass- enum of type PegOperatorTermisOperatorSpaced- if operators need to be spaced from operands- Returns:
- the rule
-
delayedOperationLazy
public static <A,B extends Enum<B> & PegOperatorTerm<R>, PegRule<PegSolver<A,R> R, delayedOperationLazyR>> (PegRule<A> operandRule, Class<B> operatorClass, boolean isOperatorSpaced) Rule to resolve operations, non greedy. The result is not resolved immediately but through a solver that resolve operands to Objects handled by the operator class.- Type Parameters:
A- Type of the operandB- Type of the operatorR- Type of the result- Parameters:
operandRule- Rule to match operandsoperatorClass- enum of type PegOperatorTermisOperatorSpaced- if operators need to be spaced from operands- Returns:
- the rule
-
operation
public static <A,B extends Enum<B> & PegOperatorTerm<A>> PegRule<A> operation(PegRule<A> operandRule, Class<B> operatorClass, boolean isOperatorSpaced) Rule to resolve operations. The operandRule must have in output the same type as handled by the operator.- Type Parameters:
A- Type of the operandB- Type of the operator- Parameters:
operandRule- Rule to match operandsoperatorClass- enum of type PegOperatorTermisOperatorSpaced- if operators need to be spaced from operands- Returns:
- the rule
-
operationLazy
public static <A,B extends Enum<B> & PegOperatorTerm<A>> PegRule<A> operationLazy(PegRule<A> operandRule, Class<B> operatorClass, boolean isOperatorSpaced) Rule to resolve operations, non greedy. The operandRule must have in output the same type as handled by the operator.- Type Parameters:
A- Type of the operandB- Type of the operator- Parameters:
operandRule- Rule to match operandsoperatorClass- enum of type PegOperatorTermisOperatorSpaced- if operators need to be spaced from operands- Returns:
- the rule
-
delayedComparison
Rule for comparisons with delayed term resolution. Eg : "$test == true" Supported comparators are : =, !=, invalid input: '<', invalid input: '<'=, >, >=- Type Parameters:
A- the type of the main rule result- Parameters:
valueRule- Rule to match each side of the comparison. Actual values are resolved later by the solver.- Returns:
- the rule
-
comparison
Rule for simple comparisons. Eg : "15 > 12" Supported comparators are : =, !=, invalid input: '<', invalid input: '<'=, >, >=- Parameters:
valueRule- Rule to match each side of the comparison- Returns:
- the rule
-
delayedOperationAndComparison
public static <A> PegRule<PegSolver<A,Object, delayedOperationAndComparisonBoolean>> (PegRule<A> valueRule) Rule for make operations and then compare. Eg : $test + $test2 == 5
returns a function that takes a function to parse the terms (String -> Object) and returns the result of the comparison.invalid reference
#handle
Supported comparators are : =, !=, invalid input: '<', invalid input: '<'=, >, >=
Supported operators are : +, -, *, /- Type Parameters:
A- The raw value type from the term parser rule- Parameters:
valueRule- Rule to match the values individually. Actuel values are resolved later by the solver.- Returns:
- the rule
-