Module macro.TokenList

A TokenList class for generating token lists.

There are also useful get_ methods for extracting values from the first token.

Functions

get_iden (tl) get an identifier from front of a token list.
get_number (tl) get an number from front of a token list.
get_string (tl) get a string from front of a token list.
strip_spaces (tl) takes a token list and strips spaces and comments.
pick (n, tl) pick the n-th token from this tokenlist.
name (name, no_space, res) append an identifier.
string (name, res) append a string.
number (val, res) append a number.
names (res, names) put out a list of names, separated by commas.
tokens (res, names, tl) put out a token list.
list (res, names, ltl) put out a list of token lists, separated by commas.
space (res, space) put out a space token.
keyword (res, keyw) put out a keyword token.
__tostring (tl) convert this tokenlist into a string.
__call (res, keyw, t, v) put out a operator token.


Functions

get_iden (tl)
get an identifier from front of a token list.

Parameters:

  • tl:

Returns:

    name
get_number (tl)
get an number from front of a token list.

Parameters:

  • tl:

Returns:

    number
get_string (tl)
get a string from front of a token list.

Parameters:

  • tl:

Returns:

    string value (without quotes)
strip_spaces (tl)
takes a token list and strips spaces and comments.

Parameters:

  • tl:

Returns:

    new tokenlist
pick (n, tl)
pick the n-th token from this tokenlist. Note that it returns the value and type, not the type and value.

Parameters:

  • n: (1 to #self)
  • tl:

Returns:

  1. token value
  2. token type
name (name, no_space, res)
append an identifier.

Parameters:

  • name: the identifier
  • no_space: true if you don't want a space after the iden
  • res:

Returns:

    self
string (name, res)
append a string.

Parameters:

  • name: the string
  • res:

Returns:

    self
number (val, res)
append a number.

Parameters:

  • val: the number
  • res:

Returns:

    self
names (res, names)
put out a list of names, separated by commas.

Parameters:

  • res: output token list
  • names: a list of strings

Returns:

    self
tokens (res, names, tl)
put out a token list.

Parameters:

  • res: output token list
  • names: a token list
  • tl:

Returns:

    self
list (res, names, ltl)
put out a list of token lists, separated by commas.

Parameters:

  • res: output token list
  • names: a list of strings
  • ltl:

Returns:

    self
space (res, space)
put out a space token.

Parameters:

  • res: output token list
  • space: a string containing only whitespace (default ' ')

Returns:

    self
keyword (res, keyw)
put out a keyword token.

Parameters:

  • res: output token list
  • keyw: a Lua keyword

Returns:

    self
__tostring (tl)
convert this tokenlist into a string.

Parameters:

  • tl:
__call (res, keyw, t, v)
put out a operator token. This is the overloaded call operator for token lists.

Parameters:

  • res: output token list
  • keyw: an operator string
  • t:
  • v: