nibble/lexer

Types

pub type Error {
  NoMatchFound(row: Int, col: Int, lexeme: String)
}

Constructors

  • NoMatchFound(row: Int, col: Int, lexeme: String)
pub opaque type Lexer(a, mode)
pub type Match(a, mode) {
  Keep(a, mode)
  Skip
  Drop(mode)
  NoMatch
}

Constructors

  • Keep(a, mode)
  • Skip
  • Drop(mode)
  • NoMatch
pub opaque type Matcher(a, mode)
pub type Span {
  Span(
    row_start: Int,
    col_start: Int,
    row_end: Int,
    col_end: Int,
  )
}

Constructors

  • Span(row_start: Int, col_start: Int, row_end: Int, col_end: Int)
pub type Token(a) {
  Token(span: Span, lexeme: String, value: a)
}

Constructors

  • Token(span: Span, lexeme: String, value: a)

Functions

pub fn advanced(matchers: fn(a) -> List(Matcher(b, a))) -> Lexer(
  b,
  a,
)
pub fn comment(start: String, to_value: fn(String) -> a) -> Matcher(
  a,
  b,
)
pub fn custom(f: fn(a, String, String) -> Match(b, a)) -> Matcher(
  b,
  a,
)
pub fn drop(f: fn(String, String) -> Bool) -> Matcher(a, b)
pub fn float(to_value: fn(Float) -> a) -> Matcher(a, b)
pub fn float_with_separator(separator: String, to_value: fn(Float) ->
    a) -> Matcher(a, b)
pub fn identifier(start: String, inner: String, reserved: Set(
    String,
  ), to_value: fn(String) -> a) -> Matcher(a, b)
pub fn ignore(matcher: Matcher(a, b)) -> Matcher(c, b)
pub fn int(to_value: fn(Int) -> a) -> Matcher(a, b)
pub fn int_with_separator(separator: String, to_value: fn(Int) ->
    a) -> Matcher(a, b)
pub fn into(matcher: Matcher(a, b), f: fn(b) -> b) -> Matcher(
  a,
  b,
)
pub fn keep(f: fn(String, String) -> Result(a, Nil)) -> Matcher(
  a,
  b,
)
pub fn keyword(str: String, breaker: String, value: a) -> Matcher(
  a,
  b,
)
pub fn map(matcher: Matcher(a, b), f: fn(a) -> c) -> Matcher(c, b)
pub fn number(from_int: fn(Int) -> a, from_float: fn(Float) -> a) -> Matcher(
  a,
  b,
)
pub fn number_with_separator(separator: String, from_int: fn(Int) ->
    a, from_float: fn(Float) -> a) -> Matcher(a, b)
pub fn run(source: String, lexer: Lexer(a, Nil)) -> Result(
  List(Token(a)),
  Error,
)
pub fn run_advanced(source: String, mode: a, lexer: Lexer(b, a)) -> Result(
  List(Token(b)),
  Error,
)
pub fn simple(matchers: List(Matcher(a, Nil))) -> Lexer(a, Nil)
pub fn skip(matcher: Matcher(a, b)) -> Matcher(c, b)
pub fn spaces(token: a) -> Matcher(a, b)
pub fn spaces_(to_value: fn(String) -> a) -> Matcher(a, b)
pub fn string(char: String, to_value: fn(String) -> a) -> Matcher(
  a,
  b,
)
pub fn symbol(str: String, breaker: String, value: a) -> Matcher(
  a,
  b,
)
pub fn then(matcher: Matcher(a, b), f: fn(a) -> Match(c, b)) -> Matcher(
  c,
  b,
)
pub fn token(str: String, value: a) -> Matcher(a, b)
pub fn try_identifier(start: String, inner: String, reserved: Set(
    String,
  ), to_value: fn(String) -> a) -> Result(
  Matcher(a, b),
  CompileError,
)
pub fn variable(reserved: Set(String), to_value: fn(String) -> a) -> Matcher(
  a,
  b,
)
pub fn whitespace(token: a) -> Matcher(a, b)
Search Document