Package org.parboiled

Class BaseParser<V>

java.lang.Object
org.parboiled.BaseActions<V>
org.parboiled.BaseParser<V>
Type Parameters:
V - the type of the parser values
All Implemented Interfaces:
org.parboiled.ContextAware<V>

public abstract class BaseParser<V> extends BaseActions<V>
Base class of all parboiled parsers. Defines the basic rule creation methods.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.parboiled.Rule
    Matches any character except Chars.EOI.
    static final org.parboiled.Rule
    Matches the special Chars.DEDENT character produces by the org.parboiled.buffers.IndentDedentInputBuffer
    static final org.parboiled.Rule
    Matches nothing and always succeeds.
    static final org.parboiled.Rule
    Matches the Chars.EOI (end of input) character.
    static final org.parboiled.Rule
    Matches the special Chars.INDENT character produces by the org.parboiled.buffers.IndentDedentInputBuffer
    static final org.parboiled.Rule
    Matches nothing and always fails.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.parboiled.Action
    ACTION(boolean expression)
    Explicitly marks the wrapped expression as an action expression.
    org.parboiled.Rule
    AnyOf(char[] characters)
    Creates a new rule that matches any of the characters in the given char array.
    org.parboiled.Rule
    AnyOf(String characters)
    Creates a new rule that matches any of the characters in the given string.
    org.parboiled.Rule
    AnyOf(org.parboiled.support.Characters characters)
    Creates a new rule that matches any of the given characters.
    org.parboiled.Rule
    Ch(char c)
    Explicitly creates a rule matching the given character.
    org.parboiled.Rule
    CharRange(char cLow, char cHigh)
    Creates a rule matching a range of characters from cLow to cHigh (both inclusively).
    org.parboiled.Rule
    FirstOf(Object[] rules)
    Creates a new rule that successively tries all of the given subrules and succeeds when the first one of its subrules matches.
    org.parboiled.Rule
    FirstOf(Object rule, Object rule2, Object... moreRules)
    Creates a new rule that successively tries all of the given subrules and succeeds when the first one of its subrules matches.
    protected org.parboiled.Rule
    fromCharArray(char[] array)
    Used internally to convert the given char array to a parser rule.
    protected org.parboiled.Rule
    Used internally to convert the given character literal to a parser rule.
    protected org.parboiled.Rule
    Used internally to convert the given string literal to a parser rule.
    org.parboiled.Rule
    IgnoreCase(char c)
    Explicitly creates a rule matching the given character case-independently.
    org.parboiled.Rule
    IgnoreCase(char... characters)
    Explicitly creates a rule matching the given string in a case-independent fashion.
    org.parboiled.Rule
    Explicitly creates a rule matching the given string in a case-independent fashion.
    <P extends BaseParser<V>>
    P
    Creates a new instance of this parsers class using the no-arg constructor.
    org.parboiled.Rule
    NoneOf(char[] characters)
    Creates a new rule that matches all characters except the ones in the given char array and EOI.
    org.parboiled.Rule
    NoneOf(String characters)
    Creates a new rule that matches all characters except the ones in the given string and EOI.
    org.parboiled.Rule
    NTimes(int repetitions, Object rule)
    Creates a new rule that repeatedly matches a given sub rule a certain fixed number of times.
    org.parboiled.Rule
    NTimes(int repetitions, Object rule, Object separator)
    Creates a new rule that repeatedly matches a given sub rule a certain fixed number of times, optionally separated by a given separator rule.
    org.parboiled.Rule
    Creates a new rule that tries repeated matches of its subrule and succeeds if the subrule matches at least once.
    org.parboiled.Rule
    OneOrMore(Object rule, Object rule2, Object... moreRules)
    Creates a new rule that tries repeated matches of a sequence of the given subrules and succeeds if the sequence matches at least once.
    org.parboiled.Rule
    Creates a new rule that tries a match on its subrule and always succeeds, independently of the matching success of its sub rule.
    org.parboiled.Rule
    Optional(Object rule, Object rule2, Object... moreRules)
    Creates a new rule that tries a match on the sequence of the given subrules and always succeeds, independently of the matching success of its sub sequence.
    org.parboiled.Rule
    Sequence(Object[] rules)
    Creates a new rule that only succeeds if all of its subrule succeed, one after the other.
    org.parboiled.Rule
    Sequence(Object rule, Object rule2, Object... moreRules)
    Creates a new rule that only succeeds if all of its subrule succeed, one after the other.
    org.parboiled.Rule
    String(char... characters)
    Explicitly creates a rule matching the given string.
    org.parboiled.Rule
    String(String string)
    Explicitly creates a rule matching the given string.
    org.parboiled.Rule
    Test(Object rule)
    Creates a new rule that acts as a syntactic predicate, i.e.
    org.parboiled.Rule
    Test(Object rule, Object rule2, Object... moreRules)
    Creates a new rule that acts as a syntactic predicate, i.e.
    org.parboiled.Rule
    Creates a new rule that acts as an inverse syntactic predicate, i.e.
    org.parboiled.Rule
    TestNot(Object rule, Object rule2, Object... moreRules)
    Creates a new rule that acts as an inverse syntactic predicate, i.e.
    org.parboiled.Rule
    Converts the given object to a rule.
    org.parboiled.Rule[]
    toRules(Object... objects)
    Converts the given object array to an array of rules.
    org.parboiled.Rule
    Creates a new rule that tries repeated matches of its subrule.
    org.parboiled.Rule
    ZeroOrMore(Object rule, Object rule2, Object... moreRules)
    Creates a new rule that tries repeated matches of the sequence of the given sub rules.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EOI

      public static final org.parboiled.Rule EOI
      Matches the Chars.EOI (end of input) character.
    • INDENT

      public static final org.parboiled.Rule INDENT
      Matches the special Chars.INDENT character produces by the org.parboiled.buffers.IndentDedentInputBuffer
    • DEDENT

      public static final org.parboiled.Rule DEDENT
      Matches the special Chars.DEDENT character produces by the org.parboiled.buffers.IndentDedentInputBuffer
    • ANY

      public static final org.parboiled.Rule ANY
      Matches any character except Chars.EOI.
    • EMPTY

      public static final org.parboiled.Rule EMPTY
      Matches nothing and always succeeds.
    • NOTHING

      public static final org.parboiled.Rule NOTHING
      Matches nothing and always fails.
  • Constructor Details

    • BaseParser

      public BaseParser()
  • Method Details

    • newInstance

      public <P extends BaseParser<V>> P newInstance()
      Creates a new instance of this parsers class using the no-arg constructor. If no no-arg constructor exists this method will fail with a java.lang.NoSuchMethodError. Using this method is faster than using Parboiled.createParser(Class, Object...) for creating new parser instances since this method does not use reflection.
      Type Parameters:
      P - the parser class
      Returns:
      a new parser instance
    • Ch

      public org.parboiled.Rule Ch(char c)
      Explicitly creates a rule matching the given character. Normally you can just specify the character literal directly in you rule description. However, if you don't want to go through fromCharLiteral(char), e.g. because you redefined it, you can also use this wrapper.

      Note: This methods carries a Cached annotation, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      c - the char to match
      Returns:
      a new rule
    • IgnoreCase

      public org.parboiled.Rule IgnoreCase(char c)
      Explicitly creates a rule matching the given character case-independently.

      Note: This methods carries a Cached annotation, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      c - the char to match independently of its case
      Returns:
      a new rule
    • CharRange

      public org.parboiled.Rule CharRange(char cLow, char cHigh)
      Creates a rule matching a range of characters from cLow to cHigh (both inclusively).

      Note: This methods carries a Cached annotation, which means that multiple invocations with the same arguments will yield the same rule instance.

      Parameters:
      cLow - the start char of the range (inclusively)
      cHigh - the end char of the range (inclusively)
      Returns:
      a new rule
    • AnyOf

      public org.parboiled.Rule AnyOf(String characters)
      Creates a new rule that matches any of the characters in the given string.

      Note: This methods provides caching, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      characters - the characters
      Returns:
      a new rule
    • AnyOf

      public org.parboiled.Rule AnyOf(char[] characters)
      Creates a new rule that matches any of the characters in the given char array.

      Note: This methods provides caching, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      characters - the characters
      Returns:
      a new rule
    • AnyOf

      public org.parboiled.Rule AnyOf(org.parboiled.support.Characters characters)
      Creates a new rule that matches any of the given characters.

      Note: This methods carries a Cached annotation, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      characters - the characters
      Returns:
      a new rule
    • NoneOf

      public org.parboiled.Rule NoneOf(String characters)
      Creates a new rule that matches all characters except the ones in the given string and EOI.

      Note: This methods provides caching, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      characters - the characters
      Returns:
      a new rule
    • NoneOf

      public org.parboiled.Rule NoneOf(char[] characters)
      Creates a new rule that matches all characters except the ones in the given char array and EOI.

      Note: This methods provides caching, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      characters - the characters
      Returns:
      a new rule
    • String

      public org.parboiled.Rule String(String string)
      Explicitly creates a rule matching the given string. Normally you can just specify the string literal directly in you rule description. However, if you want to not go through fromStringLiteral(String), e.g. because you redefined it, you can also use this wrapper.

      Note: This methods provides caching, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      string - the String to match
      Returns:
      a new rule
    • String

      public org.parboiled.Rule String(char... characters)
      Explicitly creates a rule matching the given string. Normally you can just specify the string literal directly in you rule description. However, if you want to not go through fromStringLiteral(String), e.g. because you redefined it, you can also use this wrapper.

      Note: This methods carries a Cached annotation, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      characters - the characters of the string to match
      Returns:
      a new rule
    • IgnoreCase

      public org.parboiled.Rule IgnoreCase(String string)
      Explicitly creates a rule matching the given string in a case-independent fashion.

      Note: This methods provides caching, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      string - the string to match
      Returns:
      a new rule
    • IgnoreCase

      public org.parboiled.Rule IgnoreCase(char... characters)
      Explicitly creates a rule matching the given string in a case-independent fashion.

      Note: This methods carries a Cached annotation, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      characters - the characters of the string to match
      Returns:
      a new rule
    • FirstOf

      public org.parboiled.Rule FirstOf(Object rule, Object rule2, Object... moreRules)
      Creates a new rule that successively tries all of the given subrules and succeeds when the first one of its subrules matches. If all subrules fail this rule fails as well.

      Note: This methods provides caching, which means that multiple invocations with the same arguments will yield the same rule instance.

      Parameters:
      rule - the first subrule
      rule2 - the second subrule
      moreRules - the other subrules
      Returns:
      a new rule
    • FirstOf

      public org.parboiled.Rule FirstOf(Object[] rules)
      Creates a new rule that successively tries all of the given subrules and succeeds when the first one of its subrules matches. If all subrules fail this rule fails as well.

      Note: This methods carries a Cached annotation, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      rules - the subrules
      Returns:
      a new rule
    • OneOrMore

      public org.parboiled.Rule OneOrMore(Object rule)
      Creates a new rule that tries repeated matches of its subrule and succeeds if the subrule matches at least once. If the subrule does not match at least once this rule fails.

      Note: This methods carries a Cached annotation, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      rule - the subrule
      Returns:
      a new rule
    • OneOrMore

      public org.parboiled.Rule OneOrMore(Object rule, Object rule2, Object... moreRules)
      Creates a new rule that tries repeated matches of a sequence of the given subrules and succeeds if the sequence matches at least once. If the sequence does not match at least once this rule fails.

      Note: This methods provides caching, which means that multiple invocations with the same arguments will yield the same rule instance.

      Parameters:
      rule - the first subrule
      rule2 - the second subrule
      moreRules - the other subrules
      Returns:
      a new rule
    • Optional

      public org.parboiled.Rule Optional(Object rule)
      Creates a new rule that tries a match on its subrule and always succeeds, independently of the matching success of its sub rule.

      Note: This methods carries a Cached annotation, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      rule - the subrule
      Returns:
      a new rule
    • Optional

      public org.parboiled.Rule Optional(Object rule, Object rule2, Object... moreRules)
      Creates a new rule that tries a match on the sequence of the given subrules and always succeeds, independently of the matching success of its sub sequence.

      Note: This methods provides caching, which means that multiple invocations with the same arguments will yield the same rule instance.

      Parameters:
      rule - the first subrule
      rule2 - the second subrule
      moreRules - the other subrules
      Returns:
      a new rule
    • Sequence

      public org.parboiled.Rule Sequence(Object rule, Object rule2, Object... moreRules)
      Creates a new rule that only succeeds if all of its subrule succeed, one after the other.

      Note: This methods provides caching, which means that multiple invocations with the same arguments will yield the same rule instance.

      Parameters:
      rule - the first subrule
      rule2 - the second subrule
      moreRules - the other subrules
      Returns:
      a new rule
    • Sequence

      public org.parboiled.Rule Sequence(Object[] rules)
      Creates a new rule that only succeeds if all of its subrule succeed, one after the other.

      Note: This methods carries a Cached annotation, which means that multiple invocations with the same arguments will yield the same rule instance.

      Parameters:
      rules - the sub rules
      Returns:
      a new rule
    • Test

      public org.parboiled.Rule Test(Object rule)

      Creates a new rule that acts as a syntactic predicate, i.e. tests the given sub rule against the current input position without actually matching any characters. Succeeds if the sub rule succeeds and fails if the sub rule rails. Since this rule does not actually consume any input it will never create a parse tree node.

      Also it carries a SuppressNode annotation, which means all sub nodes will also never create a parse tree node. This can be important for actions contained in sub rules of this rule that otherwise expect the presence of certain parse tree structures in their context. Also see SkipActionsInPredicates

      Note: This methods carries a Cached annotation, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      rule - the subrule
      Returns:
      a new rule
    • Test

      public org.parboiled.Rule Test(Object rule, Object rule2, Object... moreRules)

      Creates a new rule that acts as a syntactic predicate, i.e. tests the sequence of the given sub rule against the current input position without actually matching any characters. Succeeds if the sub sequence succeeds and fails if the sub sequence rails. Since this rule does not actually consume any input it will never create a parse tree node.

      Also it carries a SuppressNode annotation, which means all sub nodes will also never create a parse tree node. This can be important for actions contained in sub rules of this rule that otherwise expect the presence of certain parse tree structures in their context. Also see SkipActionsInPredicates

      Note: This methods provides caching, which means that multiple invocations with the same arguments will yield the same rule instance.

      Parameters:
      rule - the first subrule
      rule2 - the second subrule
      moreRules - the other subrules
      Returns:
      a new rule
    • TestNot

      public org.parboiled.Rule TestNot(Object rule)

      Creates a new rule that acts as an inverse syntactic predicate, i.e. tests the given sub rule against the current input position without actually matching any characters. Succeeds if the sub rule fails and fails if the sub rule succeeds. Since this rule does not actually consume any input it will never create a parse tree node.

      Also it carries a SuppressNode annotation, which means all sub nodes will also never create a parse tree node. This can be important for actions contained in sub rules of this rule that otherwise expect the presence of certain parse tree structures in their context. Also see SkipActionsInPredicates

      Note: This methods carries a Cached annotation, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      rule - the subrule
      Returns:
      a new rule
    • TestNot

      public org.parboiled.Rule TestNot(Object rule, Object rule2, Object... moreRules)

      Creates a new rule that acts as an inverse syntactic predicate, i.e. tests the sequence of the given sub rules against the current input position without actually matching any characters. Succeeds if the sub sequence fails and fails if the sub sequence succeeds. Since this rule does not actually consume any input it will never create a parse tree node.

      Also it carries a SuppressNode annotation, which means all sub nodes will also never create a parse tree node. This can be important for actions contained in sub rules of this rule that otherwise expect the presence of certain parse tree structures in their context. Also see SkipActionsInPredicates

      Note: This methods provides caching, which means that multiple invocations with the same arguments will yield the same rule instance.

      Parameters:
      rule - the first subrule
      rule2 - the second subrule
      moreRules - the other subrules
      Returns:
      a new rule
    • ZeroOrMore

      public org.parboiled.Rule ZeroOrMore(Object rule)
      Creates a new rule that tries repeated matches of its subrule. Succeeds always, even if the subrule doesn't match even once.

      Note: This methods carries a Cached annotation, which means that multiple invocations with the same argument will yield the same rule instance.

      Parameters:
      rule - the subrule
      Returns:
      a new rule
    • ZeroOrMore

      public org.parboiled.Rule ZeroOrMore(Object rule, Object rule2, Object... moreRules)
      Creates a new rule that tries repeated matches of the sequence of the given sub rules. Succeeds always, even if the sub sequence doesn't match even once.

      Note: This methods provides caching, which means that multiple invocations with the same arguments will yield the same rule instance.

      Parameters:
      rule - the first subrule
      rule2 - the second subrule
      moreRules - the other subrules
      Returns:
      a new rule
    • NTimes

      public org.parboiled.Rule NTimes(int repetitions, Object rule)
      Creates a new rule that repeatedly matches a given sub rule a certain fixed number of times.

      Note: This methods provides caching, which means that multiple invocations with the same arguments will yield the same rule instance.

      Parameters:
      repetitions - The number of repetitions to match. Must be >= 0.
      rule - the sub rule to match repeatedly.
      Returns:
      a new rule
    • NTimes

      public org.parboiled.Rule NTimes(int repetitions, Object rule, Object separator)
      Creates a new rule that repeatedly matches a given sub rule a certain fixed number of times, optionally separated by a given separator rule.

      Note: This methods provides caching, which means that multiple invocations with the same arguments will yield the same rule instance.

      Parameters:
      repetitions - The number of repetitions to match. Must be >= 0.
      rule - the sub rule to match repeatedly.
      separator - the separator to match, if null the individual sub rules will be matched without separator.
      Returns:
      a new rule
    • ACTION

      public static org.parboiled.Action ACTION(boolean expression)
      Explicitly marks the wrapped expression as an action expression. parboiled transforms the wrapped expression into an Action instance during parser construction.
      Parameters:
      expression - the expression to turn into an Action
      Returns:
      the Action wrapping the given expression
    • fromCharLiteral

      protected org.parboiled.Rule fromCharLiteral(char c)
      Used internally to convert the given character literal to a parser rule. You can override this method, e.g. for specifying a Sequence that automatically matches all trailing whitespace after the character.
      Parameters:
      c - the character
      Returns:
      the rule
    • fromStringLiteral

      protected org.parboiled.Rule fromStringLiteral(String string)
      Used internally to convert the given string literal to a parser rule. You can override this method, e.g. for specifying a Sequence that automatically matches all trailing whitespace after the string.
      Parameters:
      string - the string
      Returns:
      the rule
    • fromCharArray

      protected org.parboiled.Rule fromCharArray(char[] array)
      Used internally to convert the given char array to a parser rule. You can override this method, e.g. for specifying a Sequence that automatically matches all trailing whitespace after the characters.
      Parameters:
      array - the char array
      Returns:
      the rule
    • toRules

      public org.parboiled.Rule[] toRules(Object... objects)
      Converts the given object array to an array of rules.
      Parameters:
      objects - the objects to convert
      Returns:
      the rules corresponding to the given objects
    • toRule

      public org.parboiled.Rule toRule(Object obj)
      Converts the given object to a rule. This method can be overriden to enable the use of custom objects directly in rule specifications.
      Parameters:
      obj - the object to convert
      Returns:
      the rule corresponding to the given object