gecko/builder

Types

pub opaque type Builder(tt)
pub type LiteralBuilder(tt) =
  #(String, tt)
pub type RegexBuilder(tt) =
  #(String, fn(String) -> tt)

Values

pub fn comment(
  builder: Builder(tt),
  regex: String,
  token: fn(String) -> tt,
) -> Builder(tt)

Set the comment regex for the builder.

The regex is used to match comments in the input.

pub fn compile(builder: Builder(tt), eof: tt) -> lexer.Lexer(tt)

Compile the builder into a Lexer, panicking on error.

Returns a Lexer, or panics if there is a problem.

pub fn compile_safe(
  builder: Builder(tt),
  eof: tt,
) -> Result(lexer.Lexer(tt), String)

Compile the builder into a Lexer, returning a Result.

Returns Ok(Lexer) on success, or Error(String) if there is a problem.

pub fn float(
  builder: Builder(tt),
  regex: String,
  float: fn(Float) -> tt,
) -> Builder(tt)

Set the float regex for the builder.

The regex is used to match floats, and the token function receives a parsed Float.

pub fn float_universal(
  builder: Builder(tt),
  regex: String,
  token: fn(String) -> tt,
) -> Builder(tt)

Set a universal float-matching regex for the builder.

The regex is used to match floats as strings, and the token function receives the matched string.

pub fn ident(
  builder: Builder(tt),
  regex: String,
  token: fn(String) -> tt,
) -> Builder(tt)

Set the identifier regex for the builder.

The regex is used to match identifiers in the input.

pub fn init() -> Builder(tt)

Initialize a new empty Builder.

pub fn keywords(
  builder: Builder(tt),
  list: List(#(String, tt)),
) -> Builder(tt)

Set the list of keyword tokens for the builder.

Keywords are matched as literal strings.

pub fn number(
  builder: Builder(tt),
  regex: String,
  number: fn(Int) -> tt,
) -> Builder(tt)

Set the number regex for the builder.

The regex is used to match numbers, and the token function receives a parsed Int.

pub fn number_universal(
  builder: Builder(tt),
  regex: String,
  token: fn(String) -> tt,
) -> Builder(tt)

Set a universal number-matching regex for the builder.

The regex is used to match numbers as strings, and the token function receives the matched string.

pub fn regexes(
  builder: Builder(tt),
  regexes: List(#(String, fn(String) -> tt)),
) -> Builder(tt)

Set additional regex token matchers for the builder.

These regexes are tried after keywords and tokens.

pub fn string(
  builder: Builder(tt),
  regex: String,
  token: fn(String) -> tt,
) -> Builder(tt)

Set the string regex for the builder.

The regex is used to match string literals in the input.

pub fn tokens(
  builder: Builder(tt),
  list: List(#(String, tt)),
) -> Builder(tt)

Set the list of non-keyword literal tokens for the builder.

Tokens are matched as literal strings.

Search Document