Skip to main content

Crate lua_lex

Crate lua_lex 

Source
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 LuaValue payload because Lua errors can be any value (typically a string).
TokenValue
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 _ENV and 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 ls for lexing a new chunk from stream z.
syntax_error
Report a syntax error at the current token.
token2str
Produce a human-readable token description (for error messages and the parser).