import commands from method import Method from mode import Fundamental from lex import Grammar, PatternRule, RegionRule, PatternMatchRule from mode.python import StringGrammar1, StringGrammar2 chr1 = '[a-zA-Z_]' chr2 = '[a-zA-Z_0-9]' word = chr1 + chr2 + '*' class LuaGrammar(Grammar): rules = [ PatternRule(r'comment', r'--.*$'), PatternRule(r'spaces', r' +'), PatternRule(r'eol', r'\n'), RegionRule(r'string', r"'", StringGrammar1, r"'"), RegionRule(r'string', r'"', StringGrammar2, r'"'), PatternRule(r'keyword', r'(?:while|until|true|then|return|repeat|or|not|nil|local|in|if|function|for|false|end|elseif|else|do|break|and)(?!'+chr2+')'), PatternMatchRule('x', '(function)( +)('+word+')', 'keyword', 'spaces', 'function'), PatternRule(r'lua_identifier', word), PatternRule(r'delimiter', r'(?:[=(){}\[\];:,.])'), PatternRule(r'operator', r'(?:\.\.\.|\.\.|==|~=|<=|>=|<|>)'), PatternRule(r"integer", r"(?