Parser.Lexer

is a submodule of common-token parsers: whitespace handling, integers, identifiers, and literal symbols.

alpha-num

defn

(Fn [] (Parser Char))

                        (alpha-num)
                    

matches one ASCII letter or digit. Returns the byte.

binary-int

defn

(Fn [] (Parser Int))

                        (binary-int)
                    

parses a binary integer literal: 0b or 0B prefix followed by one or more binary digits (0 or 1). Returns an Int. Fails on overflow.

block-comment

defn

(Fn [String, String] (Parser ()))

                        (block-comment open close)
                    

skips a block comment delimited by open and close, with nesting support. An open inside the comment increments the depth, and each close decrements it. The comment ends when depth reaches zero. Fails (consumed) if EOF is reached before the comment closes. Returns unit.

digit

defn

(Fn [] (Parser Char))

                        (digit)
                    

matches one ASCII digit (0-9). Returns the byte.

float

defn

(Fn [] (Parser Double))

                        (float)
                    

parses a floating-point number and returns a Double. Handles optional leading -, integer part, decimal point with fractional digits, and optional exponent (e/E with optional sign). At least one digit must appear in the integer or fractional part. Uses slice-of and Double.from-string for conversion.

hex-int

defn

(Fn [] (Parser Int))

                        (hex-int)
                    

parses a hexadecimal integer literal: 0x or 0X prefix followed by one or more hex digits (0-9, a-f, A-F). Returns an Int. Fails on overflow.

identifier

defn

(Fn [] (Parser String))

                        (identifier)
                    

parses a C-style identifier: a letter or underscore, followed by zero or more letters, digits, or underscores. Returns the matched text as a String.

integer

defn

(Fn [] (Parser Int))

                        (integer)
                    

parses an optional - sign followed by decimal digits as an Int. Fused into a single closure.

letter

defn

(Fn [] (Parser Char))

                        (letter)
                    

matches one ASCII letter (a-z, A-Z). Returns the byte.

lexeme

defn

(Fn [(Parser a)] (Parser a))

                        (lexeme p)
                    

runs p, then skips trailing whitespace. Returns p's value.

line-comment

defn

(Fn [String] (Parser ()))

                        (line-comment prefix)
                    

skips a line comment: matches the literal prefix prefix, then consumes all bytes until end of line or end of input. The newline itself is not consumed. Returns unit.

lower

defn

(Fn [] (Parser Char))

                        (lower)
                    

matches one ASCII lowercase letter (a-z). Returns the byte.

octal-int

defn

(Fn [] (Parser Int))

                        (octal-int)
                    

parses an octal integer literal: 0o or 0O prefix followed by one or more octal digits (0-7). Returns an Int. Fails on overflow.

space

defn

(Fn [] (Parser Char))

                        (space)
                    

matches one ASCII whitespace byte (space, tab, CR, LF). Returns the byte.

symbol

defn

(Fn [String] (Parser String))

                        (symbol s)
                    

matches the literal string s, then skips trailing whitespace.

unsigned-int

defn

(Fn [] (Parser Int))

                        (unsigned-int)
                    

parses one or more decimal digits as an Int. Fused into a single closure for performance — does not go through bind/map.

upper

defn

(Fn [] (Parser Char))

                        (upper)
                    

matches one ASCII uppercase letter (A-Z). Returns the byte.

whitespace

defn

(Fn [] (Parser ()))

                        (whitespace)
                    

consumes zero or more ASCII whitespace bytes (space, tab, CR, LF). Always succeeds; the result is unit.