atto/text_util
Values
pub fn binary() -> atto.Parser(Int, String, String, a, b)
Parse a binary number. Does not include a prefix such as 0b.
Examples
{
use <- drop(atto.match("0b"))
binary()
}
|> run(text.new("0b10010"), Nil)
// -> Ok(18)
pub fn char_lit() -> atto.Parser(String, String, String, a, b)
Parse a character literal as defined by the Gleam language.
pub fn decimal() -> atto.Parser(Int, String, String, a, b)
Parse a decimal number. See signed to parse a signed number.
Examples
signed(decimal(), int.negate)
|> run(text.new("-123"), Nil)
// -> Ok(-123)
pub fn float(
sign sign: Bool,
) -> atto.Parser(Float, String, String, a, b)
Parse a float number. See signed to parse a signed number.
Examples
signed(float(), float.negate)
|> run(text.new("-123.456"), Nil)
// -> Ok(-123.456)
pub fn hexadecimal() -> atto.Parser(Int, String, String, a, b)
Parse an octal number. Does not include a prefix such as 0x.
Examples
{
use <- drop(atto.match("0x"))
hexadecimal()
}
|> run(text.new("0x1a"), Nil)
// -> Ok(26)
pub fn hspaces() -> atto.Parser(String, String, String, a, b)
Parse zero or more horizontal ASCII whitespace characters.
pub fn hspaces1() -> atto.Parser(String, String, String, a, b)
Parse one or more horizontal ASCII whitespace characters.
pub fn number() -> atto.Parser(Float, String, String, a, b)
Parse a signed decimal or float number.
pub fn signed(
p: atto.Parser(a, String, String, c, e),
negate: fn(a) -> a,
) -> atto.Parser(a, String, String, c, e)
Given a parser for a number and a negation function, parse a signed number.
pub fn simple_char_lit() -> atto.Parser(String, String, a, b, c)
Parse a simple character literal, eg one without escape sequences.
pub fn spaces() -> atto.Parser(String, String, String, a, b)
Parse zero or more ASCII whitespace characters.
pub fn spaces1() -> atto.Parser(String, String, String, a, b)
Parse one or more ASCII whitespace characters.
pub fn string_lit(
char: atto.Parser(String, String, String, c, e),
) -> atto.Parser(String, String, String, c, e)
Parse a string literal using the given character parser.
pub fn upper() -> atto.Parser(String, String, a, b, c)
Parse an uppercase ASCII character.
pub fn ws(
p: atto.Parser(a, String, String, b, c),
) -> atto.Parser(a, String, String, b, c)
Parse zero or more ASCII whitespace characters, returning a parsed value. This is useful for parsers that need to ignore whitespace.
Examples
atto.match("foo") |> text_utils.ws()