Class Parser.Lazy<T>
java.lang.Object
com.google.common.labs.parse.Parser<T>
com.google.common.labs.parse.Parser.Lazy<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);
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.common.labs.parse.Parser
Parser.Lazy<T>, Parser.OrEmpty, Parser.ParseException
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondelegateTo
(Parser<T> parser) Sets and returns the delegate parser.Methods inherited from class com.google.common.labs.parse.Parser
anyOf, atLeastOnce, atLeastOnce, atLeastOnceDelimitedBy, atLeastOnceDelimitedBy, between, between, consecutive, expecting, flatMap, followedBy, followedBy, followedBy, literally, literally, map, notFollowedBy, notFollowedBy, optional, optionallyFollowedBy, optionallyFollowedBy, optionallyFollowedBy, or, or, orElse, parse, parseSkipping, parseSkipping, parseToStream, parseToStreamSkipping, parseToStreamSkipping, postfix, prefix, sequence, sequence, sequence, single, string, then, then, thenReturn, zeroOrMore, zeroOrMore, zeroOrMore, zeroOrMoreDelimitedBy, zeroOrMoreDelimitedBy
-
Constructor Details
-
Lazy
public Lazy()
-
-
Method Details
-
delegateTo
-