Expand description
Lexical analyzer for omniLua.
Scans a ZIO byte stream into Token values one character at a time,
with one-token lookahead. One core lexes Lua 5.1 through 5.5; the lexical
differences between versions (which operators exist, escape handling,
reserved words, error wording) are gated on the active LuaVersion and are
the behavioural invariant this crate guarantees.
This file was originally a line-by-line port of llex.c but has been
idiomatized and the C correspondence removed (see GRADUATED.md); behaviour
is held by bytecode parity plus the lexical-error / line-number oracle, not
by matching the C source.
Structs§
- LexBuffer
- Growable token-text buffer for the lexer.
- LexState
- Per-chunk lexer (and shared parser) state.
- LuaState
- Per-thread Lua execution state.
- LuaString
- Lua’s immutable byte-string value.
- LuaTable
- A Lua table: hybrid array + hash map.
- Token
- A single lexed token with its semantic payload.
- ZIO
- Buffered input stream wrapping an external chunk-reader callback.
Enums§
- LuaError
- The Lua error type. Carries a
LuaValuepayload because Lua errors can be any value (typically a string). - Token
Value - Semantic payload carried by a token.
Constants§
- EOZ
- End-of-stream sentinel returned by ZIO::getc.
- FIRST_
RESERVED - First token kind value that is not a single-byte character. Single-byte tokens are represented by their ASCII value (0-255).
- LUA_ENV
- Name of the global environment upvalue.
- NUM_
RESERVED - Number of reserved words (keywords).
- TK_AND
and- TK_
BREAK break- TK_
CONCAT ..(concatenation)- TK_
DBCOLON ::- TK_DO
do- TK_DOTS
...(vararg)- TK_ELSE
else- TK_
ELSEIF elseif- TK_END
end- TK_EOS
<eof>- TK_EQ
==- TK_
FALSE false- TK_FLT
<number>(float literal)- TK_FOR
for- TK_
FUNCTION function- TK_GE
>=- TK_GOTO
goto- TK_IDIV
//(floor division)- TK_IF
if- TK_IN
in- TK_INT
<integer>(integer literal)- TK_LE
<=- TK_
LOCAL local- TK_NAME
<name>(identifier)- TK_NE
~=- TK_NIL
nil- TK_NOT
not- TK_OR
or- TK_
REPEAT repeat- TK_
RETURN return- TK_SHL
<<- TK_SHR
>>- TK_
STRING <string>(string literal)- TK_THEN
then- TK_TRUE
true- TK_
UNTIL until- TK_
WHILE while(last keyword; NUM_RESERVED = TK_WHILE - FIRST_RESERVED + 1 = 22)
Statics§
- LUAX_
TOKENS - Display strings for tokens, indexed by
token - FIRST_RESERVED.
Functions§
- init
- Pre-intern
_ENVand every reserved word. - lex_
error - Build a syntax error, optionally annotated with the offending token text.
- lookahead
- Peek at the next token without consuming the current one.
- next
- Consume the current token; load the next one from the stream.
- sem_
error - Report a semantic error at the current line WITHOUT the
near <token>suffix. - set_
input - Initialise
lsfor lexing a new chunk from streamz. - syntax_
error - Report a syntax error at the current token.
- token2str
- Produce a human-readable token description (for error messages and the parser).