TK_LCOMMENT '--[[-------------------------------------------------------------------- llex.lua: Lua 5.1 lexical analyzer in Lua This file is part of LuaSrcDiet, based on Yueliang material. Copyright (c) 2008,2011 Kein-Hong Man The COPYRIGHT file describes the conditions under which this software may be distributed. ----------------------------------------------------------------------]]' TK_EOL LF TK_EOL LF TK_LCOMMENT '--[[-------------------------------------------------------------------- -- NOTES: -- * This is a version of the native 5.1.x lexer from Yueliang 0.4.0, -- with significant modifications to handle LuaSrcDiet's needs: -- (1) llex.error is an optional error function handler -- (2) seminfo for strings include their delimiters and no -- translation operations are performed on them -- * ADDED shbang handling has been added to support executable scripts -- * NO localized decimal point replacement magic -- * NO limit to number of lines -- * NO support for compatible long strings (LUA_COMPAT_LSTR) ----------------------------------------------------------------------]]' TK_EOL LF TK_EOL LF TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'base' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME '_G' TK_EOL LF TK_EOL LF TK_NAME 'module' TK_SPACE ' ' TK_STRING '"llex"' TK_EOL LF TK_EOL LF TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'string' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'base' TK_OP '.' TK_NAME 'require' TK_SPACE ' ' TK_STRING '"string"' TK_EOL LF TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'find' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'string' TK_OP '.' TK_NAME 'find' TK_EOL LF TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'match' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'string' TK_OP '.' TK_NAME 'match' TK_EOL LF TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'sub' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'string' TK_OP '.' TK_NAME 'sub' TK_EOL LF TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_COMMENT '-- initialize keyword list, variables' TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_EOL LF TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'kw' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_OP '{' TK_OP '}' TK_EOL LF TK_KEYWORD 'for' TK_SPACE ' ' TK_NAME 'v' TK_SPACE ' ' TK_KEYWORD 'in' TK_SPACE ' ' TK_NAME 'string' TK_OP '.' TK_NAME 'gmatch' TK_OP '(' TK_LSTRING '[[ and break do else elseif end false for function if in local nil not or repeat return then true until while]]' TK_OP ',' TK_SPACE ' ' TK_STRING '"%S+"' TK_OP ')' TK_SPACE ' ' TK_KEYWORD 'do' TK_EOL LF TK_SPACE ' ' TK_NAME 'kw' TK_OP '[' TK_NAME 'v' TK_OP ']' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_KEYWORD 'true' TK_EOL LF TK_KEYWORD 'end' TK_EOL LF TK_EOL LF TK_COMMENT '-- see init() for module variables (externally visible):' TK_EOL LF TK_COMMENT '-- tok, seminfo, tokln' TK_EOL LF TK_EOL LF TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_COMMENT '-- source stream' TK_EOL LF TK_SPACE ' ' TK_NAME 'sourceid' TK_OP ',' TK_SPACE ' ' TK_COMMENT '-- name of source' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_OP ',' TK_SPACE ' ' TK_COMMENT '-- position of lexer' TK_EOL LF TK_SPACE ' ' TK_NAME 'buff' TK_OP ',' TK_SPACE ' ' TK_COMMENT '-- buffer for strings' TK_EOL LF TK_SPACE ' ' TK_NAME 'ln' TK_SPACE ' ' TK_COMMENT '-- line number' TK_EOL LF TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_COMMENT '-- add information to token listing' TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_EOL LF TK_KEYWORD 'local' TK_SPACE ' ' TK_KEYWORD 'function' TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_NAME 'token' TK_OP ',' TK_SPACE ' ' TK_NAME 'info' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_OP '#' TK_NAME 'tok' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_NAME 'tok' TK_OP '[' TK_NAME 'i' TK_OP ']' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'token' TK_EOL LF TK_SPACE ' ' TK_NAME 'seminfo' TK_OP '[' TK_NAME 'i' TK_OP ']' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'info' TK_EOL LF TK_SPACE ' ' TK_NAME 'tokln' TK_OP '[' TK_NAME 'i' TK_OP ']' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'ln' TK_EOL LF TK_KEYWORD 'end' TK_EOL LF TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_COMMENT '-- handles line number incrementation and end-of-line characters' TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_EOL LF TK_KEYWORD 'local' TK_SPACE ' ' TK_KEYWORD 'function' TK_SPACE ' ' TK_NAME 'inclinenumber' TK_OP '(' TK_NAME 'i' TK_OP ',' TK_SPACE ' ' TK_NAME 'is_tok' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'sub' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'sub' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'old' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'sub' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_SPACE ' ' TK_COMMENT '-- skip '\n' or '\r'' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'c' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'sub' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_OP '(' TK_NAME 'c' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_STRING '"\n"' TK_SPACE ' ' TK_KEYWORD 'or' TK_SPACE ' ' TK_NAME 'c' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_STRING '"\r"' TK_OP ')' TK_SPACE ' ' TK_KEYWORD 'and' TK_SPACE ' ' TK_OP '(' TK_NAME 'c' TK_SPACE ' ' TK_OP '~=' TK_SPACE ' ' TK_NAME 'old' TK_OP ')' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_SPACE ' ' TK_COMMENT '-- skip '\n\r' or '\r\n'' TK_EOL LF TK_SPACE ' ' TK_NAME 'old' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'old' TK_OP '..' TK_NAME 'c' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'is_tok' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_EOL"' TK_OP ',' TK_SPACE ' ' TK_NAME 'old' TK_OP ')' TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_NAME 'ln' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'ln' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'return' TK_SPACE ' ' TK_NAME 'i' TK_EOL LF TK_KEYWORD 'end' TK_EOL LF TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_COMMENT '-- initialize lexer for given source _z and source name _sourceid' TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_EOL LF TK_KEYWORD 'function' TK_SPACE ' ' TK_NAME 'init' TK_OP '(' TK_NAME '_z' TK_OP ',' TK_SPACE ' ' TK_NAME '_sourceid' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_NAME 'z' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME '_z' TK_SPACE ' ' TK_COMMENT '-- source' TK_EOL LF TK_SPACE ' ' TK_NAME 'sourceid' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME '_sourceid' TK_SPACE ' ' TK_COMMENT '-- name of source' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NUMBER '1' TK_SPACE ' ' TK_COMMENT '-- lexer's position in source' TK_EOL LF TK_SPACE ' ' TK_NAME 'ln' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NUMBER '1' TK_SPACE ' ' TK_COMMENT '-- line number' TK_EOL LF TK_SPACE ' ' TK_NAME 'tok' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_OP '{' TK_OP '}' TK_SPACE ' ' TK_COMMENT '-- lexed token list*' TK_EOL LF TK_SPACE ' ' TK_NAME 'seminfo' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_OP '{' TK_OP '}' TK_SPACE ' ' TK_COMMENT '-- lexed semantic information list*' TK_EOL LF TK_SPACE ' ' TK_NAME 'tokln' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_OP '{' TK_OP '}' TK_SPACE ' ' TK_COMMENT '-- line numbers for messages*' TK_EOL LF TK_SPACE ' ' TK_COMMENT '-- (*) externally visible thru' module' TK_EOL LF TK_SPACE ' ' TK_COMMENT '--------------------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_COMMENT '-- initial processing (shbang handling)' TK_EOL LF TK_SPACE ' ' TK_COMMENT '--------------------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'p' TK_OP ',' TK_SPACE ' ' TK_NAME '_' TK_OP ',' TK_SPACE ' ' TK_NAME 'q' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"^(#[^\r\n]*)(\r?\n?)"' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- skip first line' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_OP '#' TK_NAME 'q' TK_EOL LF TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_COMMENT"' TK_OP ',' TK_SPACE ' ' TK_NAME 'q' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_OP '#' TK_NAME 'r' TK_SPACE ' ' TK_OP '>' TK_SPACE ' ' TK_NUMBER '0' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_NAME 'inclinenumber' TK_OP '(' TK_NAME 'I' TK_OP ',' TK_SPACE ' ' TK_KEYWORD 'true' TK_OP ')' TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_KEYWORD 'end' TK_EOL LF TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_COMMENT '-- returns a chunk name or id, no truncation for long names' TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_EOL LF TK_KEYWORD 'function' TK_SPACE ' ' TK_NAME 'chunkid' TK_OP '(' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'sourceid' TK_SPACE ' ' TK_KEYWORD 'and' TK_SPACE ' ' TK_NAME 'match' TK_OP '(' TK_NAME 'sourceid' TK_OP ',' TK_SPACE ' ' TK_STRING '"^[=@]"' TK_OP ')' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'return' TK_SPACE ' ' TK_NAME 'sub' TK_OP '(' TK_NAME 'sourceid' TK_OP ',' TK_SPACE ' ' TK_NUMBER '2' TK_OP ')' TK_SPACE ' ' TK_COMMENT '-- remove first char' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'return' TK_SPACE ' ' TK_STRING '"[string]"' TK_EOL LF TK_KEYWORD 'end' TK_EOL LF TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_COMMENT '-- formats error message and throws error' TK_EOL LF TK_COMMENT '-- * a simplified version, does not report what token was responsible' TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_EOL LF TK_KEYWORD 'function' TK_SPACE ' ' TK_NAME 'errorline' TK_OP '(' TK_NAME 's' TK_OP ',' TK_SPACE ' ' TK_NAME 'line' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'e' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'error' TK_SPACE ' ' TK_KEYWORD 'or' TK_SPACE ' ' TK_NAME 'base' TK_OP '.' TK_NAME 'error' TK_EOL LF TK_SPACE ' ' TK_NAME 'e' TK_OP '(' TK_NAME 'string' TK_OP '.' TK_NAME 'format' TK_OP '(' TK_STRING '"%s:%d: %s"' TK_OP ',' TK_SPACE ' ' TK_NAME 'chunkid' TK_OP '(' TK_OP ')' TK_OP ',' TK_SPACE ' ' TK_NAME 'line' TK_SPACE ' ' TK_KEYWORD 'or' TK_SPACE ' ' TK_NAME 'ln' TK_OP ',' TK_SPACE ' ' TK_NAME 's' TK_OP ')' TK_OP ')' TK_EOL LF TK_KEYWORD 'end' TK_EOL LF TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'errorline' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'errorline' TK_EOL LF TK_EOL LF TK_COMMENT '------------------------------------------------------------------------' TK_EOL LF TK_COMMENT '-- count separators ("=") in a long string delimiter' TK_EOL LF TK_COMMENT '------------------------------------------------------------------------' TK_EOL LF TK_EOL LF TK_KEYWORD 'local' TK_SPACE ' ' TK_KEYWORD 'function' TK_SPACE ' ' TK_NAME 'skip_sep' TK_OP '(' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'sub' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'sub' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 's' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'sub' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'count' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_OP '#' TK_NAME 'match' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"=*"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NAME 'count' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'return' TK_SPACE ' ' TK_OP '(' TK_NAME 'sub' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_NAME 's' TK_OP ')' TK_SPACE ' ' TK_KEYWORD 'and' TK_SPACE ' ' TK_NAME 'count' TK_SPACE ' ' TK_KEYWORD 'or' TK_SPACE ' ' TK_OP '(' TK_OP '-' TK_NAME 'count' TK_OP ')' TK_SPACE ' ' TK_OP '-' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_KEYWORD 'end' TK_EOL LF TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_COMMENT '-- reads a long string or long comment' TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_EOL LF TK_KEYWORD 'local' TK_SPACE ' ' TK_KEYWORD 'function' TK_SPACE ' ' TK_NAME 'read_long_string' TK_OP '(' TK_NAME 'is_str' TK_OP ',' TK_SPACE ' ' TK_NAME 'sep' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_SPACE ' ' TK_COMMENT '-- skip 2nd '['' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'sub' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'sub' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'c' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'sub' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'c' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_STRING '"\r"' TK_SPACE ' ' TK_KEYWORD 'or' TK_SPACE ' ' TK_NAME 'c' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_STRING '"\n"' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- string starts with a newline?' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'inclinenumber' TK_OP '(' TK_NAME 'i' TK_OP ')' TK_SPACE ' ' TK_COMMENT '-- skip it' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'while' TK_SPACE ' ' TK_KEYWORD 'true' TK_SPACE ' ' TK_KEYWORD 'do' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'p' TK_OP ',' TK_SPACE ' ' TK_NAME 'q' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"([\r\n%]])"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_SPACE ' ' TK_COMMENT '-- (long range match)' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_KEYWORD 'not' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_NAME 'errorline' TK_OP '(' TK_NAME 'is_str' TK_SPACE ' ' TK_KEYWORD 'and' TK_SPACE ' ' TK_STRING '"unfinished long string"' TK_SPACE ' ' TK_KEYWORD 'or' TK_EOL LF TK_SPACE ' ' TK_STRING '"unfinished long comment"' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'p' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_STRING '"]"' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- delimiter test' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'skip_sep' TK_OP '(' TK_NAME 'i' TK_OP ')' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_NAME 'sep' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_NAME 'buff' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'sub' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_NAME 'buff' TK_OP ',' TK_SPACE ' ' TK_NAME 'I' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_SPACE ' ' TK_COMMENT '-- skip 2nd ']'' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'return' TK_SPACE ' ' TK_NAME 'buff' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'I' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'else' TK_SPACE ' ' TK_COMMENT '-- newline' TK_EOL LF TK_SPACE ' ' TK_NAME 'buff' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'buff' TK_OP '..' TK_STRING '"\n"' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'inclinenumber' TK_OP '(' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_COMMENT '--while' TK_EOL LF TK_KEYWORD 'end' TK_EOL LF TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_COMMENT '-- reads a string' TK_EOL LF TK_COMMENT '----------------------------------------------------------------------' TK_EOL LF TK_EOL LF TK_KEYWORD 'local' TK_SPACE ' ' TK_KEYWORD 'function' TK_SPACE ' ' TK_NAME 'read_string' TK_OP '(' TK_NAME 'del' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'I' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'find' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'sub' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'sub' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'while' TK_SPACE ' ' TK_KEYWORD 'true' TK_SPACE ' ' TK_KEYWORD 'do' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'p' TK_OP ',' TK_SPACE ' ' TK_NAME 'q' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"([\n\r\\\"\'])"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_SPACE ' ' TK_COMMENT '-- (long range match)' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_STRING '"\n"' TK_SPACE ' ' TK_KEYWORD 'or' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_STRING '"\r"' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_NAME 'errorline' TK_OP '(' TK_STRING '"unfinished string"' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'p' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_STRING '"\\"' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- handle escapes' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'sub' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_STRING '""' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_KEYWORD 'break' TK_SPACE ' ' TK_KEYWORD 'end' TK_SPACE ' ' TK_COMMENT '-- (EOZ error)' TK_EOL LF TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_OP '(' TK_STRING '"abfnrtv\n\r"' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_OP ',' TK_SPACE ' ' TK_NUMBER '1' TK_OP ',' TK_SPACE ' ' TK_KEYWORD 'true' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_COMMENT '------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- special escapes' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_OP '>' TK_SPACE ' ' TK_NUMBER '7' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'inclinenumber' TK_OP '(' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'else' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_COMMENT '------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'elseif' TK_SPACE ' ' TK_NAME 'find' TK_OP '(' TK_NAME 'r' TK_OP ',' TK_SPACE ' ' TK_STRING '"%D"' TK_OP ')' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- other non-digits' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_COMMENT '------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'else' TK_SPACE ' ' TK_COMMENT '-- \xxx sequence' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'p' TK_OP ',' TK_SPACE ' ' TK_NAME 'q' TK_OP ',' TK_SPACE ' ' TK_NAME 's' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"^(%d%d?%d?)"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'q' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 's' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_SPACE ' ' TK_OP '>' TK_SPACE ' ' TK_NUMBER '256' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- UCHAR_MAX' TK_EOL LF TK_SPACE ' ' TK_NAME 'errorline' TK_OP '(' TK_STRING '"escape sequence too large"' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_COMMENT '------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_COMMENT '--if p' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'else' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_NAME 'del' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- ending delimiter' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'return' TK_SPACE ' ' TK_NAME 'sub' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_NAME 'buff' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '-' TK_SPACE ' ' TK_NUMBER '1' TK_OP ')' TK_SPACE ' ' TK_COMMENT '-- return string' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_COMMENT '--if r' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'else' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'break' TK_SPACE ' ' TK_COMMENT '-- (error)' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_COMMENT '--if p' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_COMMENT '--while' TK_EOL LF TK_SPACE ' ' TK_NAME 'errorline' TK_OP '(' TK_STRING '"unfinished string"' TK_OP ')' TK_EOL LF TK_KEYWORD 'end' TK_EOL LF TK_EOL LF TK_COMMENT '------------------------------------------------------------------------' TK_EOL LF TK_COMMENT '-- main lexer function' TK_EOL LF TK_COMMENT '------------------------------------------------------------------------' TK_EOL LF TK_EOL LF TK_KEYWORD 'function' TK_SPACE ' ' TK_NAME 'llex' TK_OP '(' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'find' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'match' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'match' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'while' TK_SPACE ' ' TK_KEYWORD 'true' TK_SPACE ' ' TK_KEYWORD 'do' TK_COMMENT '--outer' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'I' TK_EOL LF TK_SPACE ' ' TK_COMMENT '-- inner loop allows break to be used to nicely section tests' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'while' TK_SPACE ' ' TK_KEYWORD 'true' TK_SPACE ' ' TK_KEYWORD 'do' TK_COMMENT '--inner' TK_EOL LF TK_SPACE ' ' TK_COMMENT '----------------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'p' TK_OP ',' TK_SPACE ' ' TK_NAME '_' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"^([_%a][_%w]*)"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_OP '#' TK_NAME 'r' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'kw' TK_OP '[' TK_NAME 'r' TK_OP ']' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_KEYWORD"' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_OP ')' TK_SPACE ' ' TK_COMMENT '-- reserved word (keyword)' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'else' TK_EOL LF TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_NAME"' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_OP ')' TK_SPACE ' ' TK_COMMENT '-- identifier' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'break' TK_SPACE ' ' TK_COMMENT '-- (continue)' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_COMMENT '----------------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'p' TK_OP ',' TK_SPACE ' ' TK_NAME '_' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"^(%.?)%d"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- numeral' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_STRING '"."' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME '_' TK_OP ',' TK_SPACE ' ' TK_NAME 'q' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"^%d*[%.%d]*([eE]?)"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'q' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_OP '#' TK_NAME 'r' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_NUMBER '1' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- optional exponent' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'match' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"^[%+%-]"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- optional sign' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME '_' TK_OP ',' TK_SPACE ' ' TK_NAME 'q' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"^[_%w]*"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'q' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'v' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'sub' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_NAME 'p' TK_OP ',' TK_SPACE ' ' TK_NAME 'q' TK_OP ')' TK_SPACE ' ' TK_COMMENT '-- string equivalent' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_KEYWORD 'not' TK_SPACE ' ' TK_NAME 'base' TK_OP '.' TK_NAME 'tonumber' TK_OP '(' TK_NAME 'v' TK_OP ')' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- handles hex test also' TK_EOL LF TK_SPACE ' ' TK_NAME 'errorline' TK_OP '(' TK_STRING '"malformed number"' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_NUMBER"' TK_OP ',' TK_SPACE ' ' TK_NAME 'v' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'break' TK_SPACE ' ' TK_COMMENT '-- (continue)' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_COMMENT '----------------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'p' TK_OP ',' TK_SPACE ' ' TK_NAME 'q' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_OP ',' TK_SPACE ' ' TK_NAME 't' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"^((%s)[ \t\v\f]*)"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 't' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_STRING '"\n"' TK_SPACE ' ' TK_KEYWORD 'or' TK_SPACE ' ' TK_NAME 't' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_STRING '"\r"' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- newline' TK_EOL LF TK_SPACE ' ' TK_NAME 'inclinenumber' TK_OP '(' TK_NAME 'i' TK_OP ',' TK_SPACE ' ' TK_KEYWORD 'true' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'else' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'q' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_SPACE ' ' TK_COMMENT '-- whitespace' TK_EOL LF TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_SPACE"' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'break' TK_SPACE ' ' TK_COMMENT '-- (continue)' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_COMMENT '----------------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'match' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"^%p"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_NAME 'buff' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_OP '(' TK_STRING '"-[\"\'.=<>~"' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_OP ',' TK_SPACE ' ' TK_NUMBER '1' TK_OP ',' TK_SPACE ' ' TK_KEYWORD 'true' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_COMMENT '-- two-level if block for punctuation/symbols' TK_EOL LF TK_SPACE ' ' TK_COMMENT '--------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_OP '<=' TK_SPACE ' ' TK_NUMBER '2' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_NUMBER '1' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- minus' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'c' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'match' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"^%-%-(%[?)"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'c' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '2' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'sep' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_OP '-' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'c' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_STRING '"["' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_NAME 'sep' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'skip_sep' TK_OP '(' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'sep' TK_SPACE ' ' TK_OP '>=' TK_SPACE ' ' TK_NUMBER '0' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- long comment' TK_EOL LF TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_LCOMMENT"' TK_OP ',' TK_SPACE ' ' TK_NAME 'read_long_string' TK_OP '(' TK_KEYWORD 'false' TK_OP ',' TK_SPACE ' ' TK_NAME 'sep' TK_OP ')' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'else' TK_SPACE ' ' TK_COMMENT '-- short comment' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'find' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"[\n\r]"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_SPACE ' ' TK_KEYWORD 'or' TK_SPACE ' ' TK_OP '(' TK_OP '#' TK_NAME 'z' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_COMMENT"' TK_OP ',' TK_SPACE ' ' TK_NAME 'sub' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_NAME 'buff' TK_OP ',' TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '-' TK_SPACE ' ' TK_NUMBER '1' TK_OP ')' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'break' TK_SPACE ' ' TK_COMMENT '-- (continue)' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_COMMENT '-- (fall through for "-")' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'else' TK_SPACE ' ' TK_COMMENT '-- [ or long string' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'sep' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'skip_sep' TK_OP '(' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'sep' TK_SPACE ' ' TK_OP '>=' TK_SPACE ' ' TK_NUMBER '0' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_LSTRING"' TK_OP ',' TK_SPACE ' ' TK_NAME 'read_long_string' TK_OP '(' TK_KEYWORD 'true' TK_OP ',' TK_SPACE ' ' TK_NAME 'sep' TK_OP ')' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'elseif' TK_SPACE ' ' TK_NAME 'sep' TK_SPACE ' ' TK_OP '==' TK_SPACE ' ' TK_OP '-' TK_NUMBER '1' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_OP"' TK_OP ',' TK_SPACE ' ' TK_STRING '"["' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'else' TK_EOL LF TK_SPACE ' ' TK_NAME 'errorline' TK_OP '(' TK_STRING '"invalid long string delimiter"' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'break' TK_SPACE ' ' TK_COMMENT '-- (continue)' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_COMMENT '--------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'elseif' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_OP '<=' TK_SPACE ' ' TK_NUMBER '5' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'p' TK_SPACE ' ' TK_OP '<' TK_SPACE ' ' TK_NUMBER '5' TK_SPACE ' ' TK_KEYWORD 'then' TK_SPACE ' ' TK_COMMENT '-- strings' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_STRING"' TK_OP ',' TK_SPACE ' ' TK_NAME 'read_string' TK_OP '(' TK_NAME 'r' TK_OP ')' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'break' TK_SPACE ' ' TK_COMMENT '-- (continue)' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'match' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"^%.%.?%.?"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_SPACE ' ' TK_COMMENT '-- .|..|... dots' TK_EOL LF TK_SPACE ' ' TK_COMMENT '-- (fall through)' TK_EOL LF TK_SPACE ' ' TK_COMMENT '--------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'else' TK_SPACE ' ' TK_COMMENT '-- relational' TK_EOL LF TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'match' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_STRING '"^%p=?"' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_COMMENT '-- (fall through)' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_OP '#' TK_NAME 'r' TK_EOL LF TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_OP"' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_OP ')' TK_SPACE ' ' TK_COMMENT '-- for other symbols, fall through' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'break' TK_SPACE ' ' TK_COMMENT '-- (continue)' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_COMMENT '----------------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'local' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'sub' TK_OP '(' TK_NAME 'z' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ',' TK_SPACE ' ' TK_NAME 'i' TK_OP ')' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'if' TK_SPACE ' ' TK_NAME 'r' TK_SPACE ' ' TK_OP '~=' TK_SPACE ' ' TK_STRING '""' TK_SPACE ' ' TK_KEYWORD 'then' TK_EOL LF TK_SPACE ' ' TK_NAME 'I' TK_SPACE ' ' TK_OP '=' TK_SPACE ' ' TK_NAME 'i' TK_SPACE ' ' TK_OP '+' TK_SPACE ' ' TK_NUMBER '1' TK_EOL LF TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_OP"' TK_OP ',' TK_SPACE ' ' TK_NAME 'r' TK_OP ')' TK_SPACE ' ' TK_COMMENT '-- other single-char tokens' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'break' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_EOL LF TK_SPACE ' ' TK_NAME 'addtoken' TK_OP '(' TK_STRING '"TK_EOS"' TK_OP ',' TK_SPACE ' ' TK_STRING '""' TK_OP ')' TK_SPACE ' ' TK_COMMENT '-- end of stream,' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'return' TK_SPACE ' ' TK_COMMENT '-- exit here' TK_EOL LF TK_SPACE ' ' TK_COMMENT '----------------------------------------------------------------' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_COMMENT '--while inner' TK_EOL LF TK_SPACE ' ' TK_KEYWORD 'end' TK_COMMENT '--while outer' TK_EOL LF TK_KEYWORD 'end' TK_EOL LF TK_EOS ''