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 returns
  • comment: Either multi-line or single-line comments
  • string_start and string_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 strings
  • keyword: Keywords. Like "while", "end", "do", etc
  • value: Special values. Only true, false, and nil
  • ident: Identifier. Variables, function names, etc
  • number: Numbers, including both base 10 (and scientific notation) and hexadecimal
  • symbol: Symbols, like brackets, parenthesis, ., .., etc
  • vararg: ...
  • operator: Operators, like +, -, %, =, ==, >=, <=, ~=, etc
  • label_start and label_end: The starts and ends of labels. Always equal to '::'. Between them there can only be whitespace and label tokens.
  • label: Basically an ident between a label_start and label_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.

generated by LDoc TESTING