Class PegRules

java.lang.Object
io.vertigo.commons.peg.rule.PegRules

public final class PegRules extends Object
Factory of all PeRules.
Author:
pchretien
  • Method Details

    • named

      public static <R> PegRule<R> named(PegRule<R> innerRule, String ruleName)
      Named a Rule.
      Parameters:
      innerRule - Rule to name
      ruleName - Rule name
      Returns:
      Named rule
    • named

      public static <R> PegRule<R> named(PegRule<R> innerRule, String ruleName, String errorMessage)
      Name a rule with a fixed error message.
      Type Parameters:
      R - Type of the product text parsing
      Parameters:
      ruleName - Rule name
      errorMessage - Fixed error message
      mainRule - 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 name
      messageKey - Message key for error message
      mainRule - Rule to name
      Returns:
      Named rule
    • optional

      public static <R> PegRule<Optional<R>> optional(PegRule<R> rule)
      Parameters:
      rule - Inner rule
      Returns:
      Optional rule
    • term

      public static PegRule<String> term(String term)
      Parameters:
      term - Terminal
      Returns:
      Term rule
    • sequence

      public static PegRule<List<Object>> sequence(PegRule<?>... rules)
      Parameters:
      rules - rules list
      Returns:
      sequence rule of inner rules
    • sequence

      public static PegRule<List<Object>> sequence(List<PegRule<?>> rules)
      Parameters:
      rules - rules list
      Returns:
      sequence rule of inner rules
    • choice

      public static PegRule<PegChoice> choice(PegRule<?>... rules)
      Parameters:
      rules - the list of rules to test
      Returns:
      choice rule of inner rules
    • choice

      public static PegRule<PegChoice> choice(List<PegRule<?>> rules)
      Parameters:
      rules - the list of rules to test
      Returns:
      choice rule of inner rules
    • zeroOrMore

      public static <R> PegRule<List<R>> zeroOrMore(PegRule<R> rule, boolean untilEnd)
      Parameters:
      rule - Rule to repeat
      untilEnd - If text should be parsed entirely
      Returns:
      zeroOrMore rule
    • oneOrMore

      public static <R> PegRule<List<R>> oneOrMore(PegRule<R> rule, boolean untilEnd)
      Parameters:
      rule - Rule to repeat
      untilEnd - If text should be parsed entirely
      Returns:
      oneOrMore rule
    • skipBlanks

      public static PegRule<PegRule.Dummy> skipBlanks(String blanks)
      Parameters:
      blanks - list of char to skip
      Returns:
      Rule to match any blank char
    • skipBlanks

      public static PegRule<PegRule.Dummy> skipBlanks()
    • blanks

      public static PegRule<PegRule.Dummy> blanks(String blanks)
      Parameters:
      blanks - list of char to skip
      Returns:
      Rule to match any blank char
    • blanks

      public static PegRule<PegRule.Dummy> blanks()
    • word

      public static PegRule<String> word(boolean emptyAccepted, String checkedChars, PegWordRuleMode mode, String readableExpression)
      Parameters:
      emptyAccepted - Si les mots vides sont acceptés
      checkedChars - Liste des caractères vérifiés
      mode - 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

      public static <O> PegRule<O> parseAll(PegRule<O> innerRule)
      Type Parameters:
      O - Result object
      Parameters:
      innerRule - InnerRule
      Returns:
      Rule to ensure innerRull match whole text
    • namedRulesAsHtml

      public static String namedRulesAsHtml(PegRule<?> rootRule)
      Parameters:
      rootRule - Root rule to start with
      Returns:
      Html railroad diagram
    • delayedOperation

      public 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. 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 operand
      B - Type of the operator
      R - Type of the result
      Parameters:
      operandRule - Rule to match operands. Actual values are resolved later by the solver.
      operatorClass - enum of type PegOperatorTerm
      isOperatorSpaced - if operators need to be spaced from operands
      Returns:
      the rule
    • delayedOperationLazy

      public 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. 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 operand
      B - Type of the operator
      R - Type of the result
      Parameters:
      operandRule - Rule to match operands
      operatorClass - enum of type PegOperatorTerm
      isOperatorSpaced - 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 operand
      B - Type of the operator
      Parameters:
      operandRule - Rule to match operands
      operatorClass - enum of type PegOperatorTerm
      isOperatorSpaced - 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 operand
      B - Type of the operator
      Parameters:
      operandRule - Rule to match operands
      operatorClass - enum of type PegOperatorTerm
      isOperatorSpaced - if operators need to be spaced from operands
      Returns:
      the rule
    • delayedComparison

      public static <A> PegRule<PegSolver<A,Object,Boolean>> delayedComparison(PegRule<A> valueRule)
      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

      public static PegRule<Boolean> comparison(PegRule<?> valueRule)
      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,Boolean>> delayedOperationAndComparison(PegRule<A> valueRule)
      Rule for make operations and then compare. Eg : $test + $test2 == 5

      invalid reference
      #handle
      returns a function that takes a function to parse the terms (String -> Object) and returns the result of the comparison.

      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