Introduction
Usage
Usage call for a single module, provided as Module:Call
(or call.lua), would be like this
mw.lexPage( 'Module:Test' )
Given that the page is recognized as a module containing code the lexer can parse, that is it has the correct content model, it will build a table containing a table entry for each line in the source file. Each found token will be added in the order they are found.
Each token has the following structure:
{ type = string, -- one of the token types below data = string, -- the source code that makes up the token posFirst = number, -- the position (inclusive) within that line that the token starts posLast = number -- the position (inclusive) within that line that the token ends }
Each token can have one of the following types:
whitespace
: Spaces, newlines, tabs, and carriage returnscomment
: Either multi-line or single-line commentsstring_start
andstring_end
: starts and ends of a string. There will be no non-string tokens between these two.- string: Part of a string that isn't an escape
escape
: A string escape, like \n, only found inside stringskeyword
: Keywords. Like "while", "end", "do", etcvalue
: Special values. Only true, false, and nilident
: Identifier. Variables, function names, etcnumber
: Numbers, including both base 10 (and scientific notation) and hexadecimalsymbol
: Symbols, like brackets, parenthesis, ., .., etcvararg
:...
operator
: Operators, like+
,-
,%
,=
,==
,>=
,<=
,~=
, etclabel_start
andlabel_end
: The starts and ends of labels. Always equal to'::'
. Between them there can only bewhitespace
andlabel
tokens.label
: Basically anident
between alabel_start
andlabel_end
.unidentified
: Anything that isn't one of the above tokens. Consider them errors. Invalid escapes are also unidentified.
Example
For the following Lua code, provided as Module:Test1
(or test1.lua):
-- comment
This is what you get when you put it through the lexer:
{ { { ["data"] = "-- comment", ["posFirst"] = 1, ["posLast"] = 10, ["type"] = "comment", }, }, }
There are two other example modules provided for testing purposes; Module:Test2
(or test2.lua) and Module:Test3
(or test3.lua). All test modules can be loaded as prepared pages.