Documentation ¶
Overview ¶
Package dsl provides facilities for parsing lisp-like domain-specific languages (DSL).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Index ¶
Index is a Predicate that evaluates to true only on its N-th invocation.
type Parser ¶
type Parser[T any] struct { // contains filtered or unexported fields }
A Parser holds the rules and logic for parsing a DSL.
func NewPredicateParser ¶
NewPredicateParser constructs a new Parser of a Lisp-like DSL, where the resulting type implements Predicate[E]. NewPredicateParser predefines a few useful functions: Not, And, Or, OnIndex.
func (*Parser[T]) DefineConstant ¶
DefineConstant adds a new constant to the Parser's supported DSL. Whenever the provided identifier is used within a constant context, the provided closure is invoked to instantiate an appropriate AST value.
func (*Parser[T]) DefineFunc ¶
DefineFunc adds a new func to the Parser's supported DSL. Whenever the provided identifier is used within a function invocation context, the provided closure is invoked to instantiate an appropriate AST value.
func (*Parser[T]) ParseFromPos ¶
ParseFromPos parses from the provided current position and associated scanner. If the parser fails to parse, it panics. This function is intended to be used when composing Parsers of various types.
type Predicate ¶
Predicate encodes conditional logic that yields a boolean.
type Scanner ¶
A Scanner holds the scanner's internal state while processing a given text.
func (*Scanner) Consume ¶
Consume scans the next token. If the token is not of the provided token, it panics. It returns the token itself.
func (*Scanner) ConsumeString ¶
ConsumeString scans the next token. It panics if the next token is not a string, or if unable to unquote the string. It returns the unquoted string contents.