glexer

Types

pub opaque type Lexer
pub type Position {
  Position(byte_offset: Int)
}

Constructors

  • Position(byte_offset: Int)

Functions

pub fn discard_comments(lexer: Lexer) -> Lexer
pub fn discard_whitespace(lexer: Lexer) -> Lexer
pub fn lex(lexer: Lexer) -> List(#(Token, Position))
pub fn new(source: String) -> Lexer
pub fn to_source(tokens: List(#(Token, Position))) -> String

Turn a sequence of tokens back to their Gleam source code representation.

pub fn unescape_string(string: String) -> Result(String, Nil)

Convert the value of a string token to the string it represents.

This function can fail if the original string contains invalid escape sequences.

unescape_string("\\\"X\\\" marks the spot")
// --> Ok("\"X\" marks the spot")

unescape_string("\\u{1F600}")
// --> Ok("😀")

unescape_string("\\x")
// --> Error(Nil)
Search Document