ConfigurableExpressionParser

open class ConfigurableExpressionParser<S : Scanner<*>, C, R>(val parsePrimary: (S, C) -> R, operators: ConfigurableExpressionParser.Operators<S, C, R>)

A simple configurable expression parser.

  • S is the scanner type

  • C is the type of the parsing context, typically holding variable definitions etc.

  • R is the type of the parsed expression.

The parser is primarily configured by defining operators using the prefix, infix and suffix companion functions, defining operator names, types and precedences.

Constructors

Link copied to clipboard
constructor(parsePrimary: (S, C) -> R, vararg operators: ConfigurableExpressionParser.Operators<S, C, R>)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
interface Operator<S, C, R>

Internal operator representation, consisting of the precedence and a build function.

Link copied to clipboard

Maps operator names to their arity, precedence and build function.

Properties

Link copied to clipboard
val parsePrimary: (S, C) -> R

Functions

Link copied to clipboard
fun parseExpression(scanner: S, context: C, precedence: Int = -1): R

Parser an expression from the given tokenizer. Leftover tokens will be ignored and may be handled by the caller.