Module
lexie/name
src/lexie/name.pookaEvery token deserves a proper name, even !=.
Class names for tokens, derived from their source text.
Words become PascalCase, and an underscore between words joins them
(else_if becomes ElseIf). Symbols are spelled out (== becomes
EqualEqual, #( becomes HashLeftParen), and so is an underscore
anywhere else (_ becomes Underscore).
Any derived name can be replaced under [tokens.names].
Pooka reserves some names: True and False are words of the
language, and Int, Nil and the other built-in types cannot be
declared again. A derived name that would clash gets its section added:
the literal true becomes TrueLiteral.
API reference
reserved() -> List(String)
fn() -> List(String)Names a generated token class must not have: Pooka's own, and the ones the generated modules already use.
is_reserved(name: String) -> Bool
fn(String) -> BoolIs this one of the names in reserved()?
token_name(
text: String,
overrides: List(#(String, String)),
section: String
) -> Result(String, String)
fn(String, List(#(String, String)), String) -> Result(String, String)The class name for a fixed token, from [tokens.names] if it has one
there, or derived. section (such as Literal) is added to a derived
name that would clash with a reserved one.
import lexie/name
let ordinary = name.token_name("int", [], "Keyword") // Ok("IntKeyword")
let renamed = name.token_name("|>", [#("|>", "Pipe")], "Operator") // Ok("Pipe")
derive(text: String) -> Result(String, String)
fn(String) -> Result(String, String)The name for a piece of text, without overrides.
import lexie/name
assert name.derive("==") == Ok("EqualEqual")
assert name.derive("set-car!") == Ok("SetMinusCarBang")
code(character: String) -> Int
fn(String) -> IntThe code of a single-character string, or -1.
is_letter(character: String) -> Bool
fn(String) -> BoolIs this a single ASCII letter?
is_digit(character: String) -> Bool
fn(String) -> BoolIs this a single ASCII digit?
is_ascii(text: String) -> Bool
fn(String) -> BoolIs every character of the text ASCII?
symbol_name(symbol: String) -> Option(String)
fn(String) -> Option(String)Spelled-out names for ASCII symbols.
is_valid_class(name: String) -> Bool
fn(String) -> BoolIs this a valid Pooka class name: an uppercase letter, then letters and digits?
is_valid_module(path: String) -> Bool
fn(String) -> BoolA module path: lowercase snake_case pieces, separated by /.