Module

lexie/name

src/lexie/name.pooka

Every 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

function

reserved

src/lexie/name.pooka:25
reserved() -> List(String)
INFERREDfn() -> List(String)

Names a generated token class must not have: Pooka's own, and the ones the generated modules already use.

function

is_reserved

src/lexie/name.pooka:53
is_reserved(name: String) -> Bool
INFERREDfn(String) -> Bool

Is this one of the names in reserved()?

function

token_name

src/lexie/name.pooka:67
token_name(
  text: String,
  overrides: List(#(String, String)),
  section: String
) -> Result(String, String)
INFERREDfn(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.

Pooka
import lexie/name

let ordinary = name.token_name("int", [], "Keyword") // Ok("IntKeyword")
let renamed = name.token_name("|>", [#("|>", "Pipe")], "Operator") // Ok("Pipe")
function

derive

src/lexie/name.pooka:97
derive(text: String) -> Result(String, String)
INFERREDfn(String) -> Result(String, String)

The name for a piece of text, without overrides.

Pooka
import lexie/name

assert name.derive("==") == Ok("EqualEqual")
assert name.derive("set-car!") == Ok("SetMinusCarBang")
function

code

src/lexie/name.pooka:167
code(character: String) -> Int
INFERREDfn(String) -> Int

The code of a single-character string, or -1.

function

is_letter

src/lexie/name.pooka:175
is_letter(character: String) -> Bool
INFERREDfn(String) -> Bool

Is this a single ASCII letter?

function

is_digit

src/lexie/name.pooka:183
is_digit(character: String) -> Bool
INFERREDfn(String) -> Bool

Is this a single ASCII digit?

function

is_ascii

src/lexie/name.pooka:189
is_ascii(text: String) -> Bool
INFERREDfn(String) -> Bool

Is every character of the text ASCII?

function

symbol_name

src/lexie/name.pooka:194
symbol_name(symbol: String) -> Option(String)
INFERREDfn(String) -> Option(String)

Spelled-out names for ASCII symbols.

function

is_valid_class

src/lexie/name.pooka:233
is_valid_class(name: String) -> Bool
INFERREDfn(String) -> Bool

Is this a valid Pooka class name: an uppercase letter, then letters and digits?

function

is_valid_module

src/lexie/name.pooka:284
is_valid_module(path: String) -> Bool
INFERREDfn(String) -> Bool

A module path: lowercase snake_case pieces, separated by /.