In package com.copperleaf.kudzu.parser

class com.copperleaf.kudzu.parser.LazyParser

A shim to allow parsers to be mutually recursive. Unlike most parsers, the Lazy parser does not do anything on its own or return its own node. At parse-time, it acts as as if it is its parser, and not like it wraps its parser.

For simpler instantiation of parsers that recursively calls itself, you can initialize the LazyParser with a lambda to evaluate and return a parser instead of assigning it after creation. The receiver of that lambda is the lazy parser being initialized.

Predicts true when:

  • its parser predicts true

Parsing fails when:

  • its parser fails to parse

Fields

lateinit var parser: Parser

Constructors

constructor(name: String = "", creator: Parser.()->Parser)

Parameters:
  • name: String = ""
  • creator: Function1
constructor(name: String = "")

A shim to allow parsers to be mutually recursive. Unlike most parsers, the Lazy parser does not do anything on its own or return its own node. At parse-time, it acts as as if it is its parser, and not like it wraps its parser.

For simpler instantiation of parsers that recursively calls itself, you can initialize the LazyParser with a lambda to evaluate and return a parser instead of assigning it after creation. The receiver of that lambda is the lazy parser being initialized.

Predicts true when:

  • its parser predicts true

Parsing fails when:

  • its parser fails to parse

Parameters:
  • name: String = ""

Methods

fun predict(input: ParserContext): Boolean

Parameters:
fun parse(input: ParserContext): <Node, ParserContext>

Parameters:

Extensions

fun checkNotEmpty(input: ParserContext)

Parameters: