Class Parser.Lazy<T>

java.lang.Object
com.google.common.labs.parse.Parser<T>
com.google.common.labs.parse.Parser.Lazy<T>
Enclosing class:
Parser<T>

public static final class Parser.Lazy<T> extends Parser<T>
A lazy parser, to be used for recursive grammars.

For example, to create a parser for a simple calculator that supports single-digit numbers, addition, and parentheses, you can write:


 var lazy = new Parser.Lazy<Integer>();
 Parser<Integer> num = Parser.single(CharPredicate.inRange('0', '9')).map(c -> c - '0');
 Parser<Integer> atomic = lazy.between("(", ")").or(num);
 Parser<Integer> expr =
     atomic.atLeastOnceDelimitedBy("+")
         .map(nums -> nums.stream().mapToInt(n -> n).sum());
 return lazy.delegateTo(expr);
 
  • Constructor Details

    • Lazy

      public Lazy()
  • Method Details

    • delegateTo

      public Parser<T> delegateTo(Parser<T> parser)
      Sets and returns the delegate parser.