2008-12-07 00:02:28 -05:00
|
|
|
import commands
|
2009-03-30 01:10:25 -04:00
|
|
|
from method import Method
|
|
|
|
from mode import Fundamental
|
|
|
|
from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
|
2008-12-07 00:02:28 -05:00
|
|
|
from mode.python import StringGrammar1, StringGrammar2
|
|
|
|
|
2009-03-30 01:10:25 -04:00
|
|
|
chr1 = '[a-zA-Z_]'
|
|
|
|
chr2 = '[a-zA-Z_0-9]'
|
|
|
|
word = chr1 + chr2 + '*'
|
|
|
|
|
2008-12-07 00:02:28 -05:00
|
|
|
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'"'),
|
|
|
|
|
2009-03-30 01:10:25 -04:00
|
|
|
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),
|
2008-12-07 00:02:28 -05:00
|
|
|
|
|
|
|
PatternRule(r'delimiter', r'(?:[=(){}\[\];:,.])'),
|
|
|
|
PatternRule(r'operator', r'(?:\.\.\.|\.\.|==|~=|<=|>=|<|>)'),
|
|
|
|
|
|
|
|
PatternRule(r"integer", r"(?<![\.0-9a-zA-Z_])(?:0|-?[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?(?![\.0-9a-zA-Z_])"),
|
|
|
|
PatternRule(r"float", r"(?<![\.0-9a-zA-Z_])(?:-?[0-9]+\.[0-9]*|-?\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|-?\.[0-9]+)[eE][\+-]?[0-9]+)(?![\.0-9a-zA-Z_])"),
|
|
|
|
]
|
|
|
|
|
2009-03-30 01:10:25 -04:00
|
|
|
class LuaCheckSyntax(Method):
|
2008-12-07 00:02:28 -05:00
|
|
|
'''Check the syntax of a lua file'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
app = w.application
|
|
|
|
cmd = "luac -p %r" % (w.buffer.path)
|
|
|
|
(status, output) = commands.getstatusoutput(cmd)
|
|
|
|
if status == 0:
|
|
|
|
app.set_error("Syntax OK")
|
|
|
|
app.data_buffer("*Lua-Check-Syntax*", output, switch_to=False)
|
|
|
|
else:
|
|
|
|
app.data_buffer("*Lua-Check-Syntax*", output)
|
|
|
|
|
2009-03-30 01:10:25 -04:00
|
|
|
class Lua(Fundamental):
|
2009-03-17 15:24:10 -04:00
|
|
|
name = 'Lua'
|
2008-12-07 00:02:28 -05:00
|
|
|
extensions = ['.lua']
|
2009-02-15 12:06:35 -05:00
|
|
|
#tabbercls = mode.lisp.LispTabber
|
2008-12-07 00:02:28 -05:00
|
|
|
grammar = LuaGrammar
|
2009-02-15 12:06:35 -05:00
|
|
|
commentc = '--'
|
2008-12-07 00:02:28 -05:00
|
|
|
opentokens = ('delimiter',)
|
|
|
|
opentags = {'(': ')', '[': ']', '{': '}'}
|
|
|
|
closetokens = ('delimiter',)
|
|
|
|
closetags = {')': '(', ']': '[', '}': '{'}
|
|
|
|
colors = {}
|
2009-02-15 12:06:35 -05:00
|
|
|
actions = [LuaCheckSyntax]
|
2009-03-17 15:24:10 -04:00
|
|
|
_bindings = {
|
2009-02-15 12:06:35 -05:00
|
|
|
'close-paren': (')',),
|
|
|
|
'close-brace': ('}',),
|
|
|
|
'close-bracket': (']',),
|
|
|
|
'lua-check-syntax': ('C-c s',),
|
|
|
|
}
|
2008-12-07 00:02:28 -05:00
|
|
|
|
|
|
|
install = Lua.install
|