接口 Parser<T>

  • 类型参数:
    T - The AST node this parser will be returning.
    所有已知实现类:
    LazyParser

    public interface Parser<T>
    Main interface of the parser library, used to implement custom parsers.
    • 方法概要

      所有方法 实例方法 抽象方法 默认方法 
      修饰符和类型 方法 说明
      default <R> Parser<R> map​(java.util.function.Function<T,​R> function)
      Helper for converting a result of the parser into another type.
      default T parse​(java.lang.String input)
      Helper function to parse whole strings.
      T parse​(ParserContext context)
      The core of the parsing logic.
    • 方法详细资料

      • parse

        @Nullable
        T parse​(ParserContext context)
        The core of the parsing logic. The context argument specifies where in the input string we are currently parsing. The responsibility of this function is to do one of:
        • Consume a part of the input and return a non-null value.
        • Return null and keep the input context untouched. This can be achieved either by avoiding the calls to ParserContext.advance(int), or through the use of snapshotting (see ParserContext.snapshot()).
        参数:
        context - Context of the parser containing the parsed string and the position in that string.
        返回:
        Null-value if this parser did not match anything. Non-null if it matched.
      • parse

        default T parse​(java.lang.String input)
        Helper function to parse whole strings.
        参数:
        input - A string to parse.
        返回:
        A parsed out value (likely AST) or null, if it does not match.
      • map

        default <R> Parser<R> map​(java.util.function.Function<T,​R> function)
        Helper for converting a result of the parser into another type. More or less equivalent to Stream.map(Function).
        类型参数:
        R - The return type of the new parser.
        参数:
        function - Function that should be used to map the result of the given parser.
        返回:
        A new parser which returns the expected type.