2008-05-03 13:31:30 -04:00
|
|
|
import commands, os.path, sets, string, sys, traceback
|
|
|
|
import color, completer, default, mode, method, regex, tab
|
|
|
|
from point import Point
|
|
|
|
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule, NocasePatternRule
|
|
|
|
|
2008-10-15 00:49:39 -04:00
|
|
|
class AtomGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
NocasePatternRule(r'escaped', r'\\(?:[bdefnrstv\\"\']|\^[a-z]|\d{1,3})'),
|
|
|
|
NocasePatternRule(r'data', r"[^\\']+"),
|
|
|
|
]
|
|
|
|
|
2008-05-03 13:31:30 -04:00
|
|
|
class StringGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
NocasePatternRule(r'escaped', r'\\(?:[bdefnrstv\\"\']|\^[a-z]|\d{1,3})'),
|
2008-10-15 00:49:39 -04:00
|
|
|
NocasePatternRule(r'data', r'[^\\"]+'),
|
2008-05-03 13:31:30 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
class ErlangGrammar(Grammar):
|
|
|
|
rules = [
|
2008-05-29 19:05:15 -04:00
|
|
|
PatternRule(r'eol', r'\n'),
|
2008-05-03 13:31:30 -04:00
|
|
|
PatternRule(r'comment', r'%.*$'),
|
|
|
|
PatternRule(r'erl_attribute', r'-[a-z][a-zA-Z0-9_@]+'),
|
|
|
|
PatternRule(r'erl_reserved', r"(?:xor|when|try|rem|receive|query|orelse|or|of|not|let|if|fun|end|div|cond|catch|case|bxor|bsr|bsl|bor|bnot|begin|band|andalso|and|after)(?![a-zA-Z0-9_'])"),
|
2008-07-14 19:24:26 -04:00
|
|
|
PatternRule(r'erl_arity', r'[a-z][a-zA-Z0-9_@]*/(?:0|[1-9][0-9]*)'),
|
2008-05-11 23:37:57 -04:00
|
|
|
PatternRule(r'erl_function', r'[a-z][a-zA-Z0-9_@]*(?= *\()'),
|
|
|
|
PatternRule(r'erl_namespace', r'[a-z][a-zA-Z0-9_@]*(?=:)'),
|
2008-05-03 13:31:30 -04:00
|
|
|
PatternRule(r'erl_builtin', r"whereis|unregister|unlink|tuple_to_list|tuple_size|trunc|tl|time|throw|term_to_binary|term_to_binary|statistics|split_binary|spawn_opt|spawn_opt|spawn_opt|spawn_opt|spawn_monitor|spawn_monitor|spawn_link|spawn_link|spawn_link|spawn_link|spawn|spawn|spawn|spawn|size|setelement|self|round|registered|register|put|purge_module|process_info|process_info|process_flag|process_flag|processes|pre_loaded|port_control|port_connect|port_command|port_close|pid_to_list|open_port|now|nodes|nodes|node|node|monitor_node|module_loaded|make_ref|load_module|list_to_tuple|list_to_pid|list_to_integer|list_to_float|list_to_existing_atom|list_to_bitstring|list_to_binary|list_to_atom|link|length|is_tuple|is_reference|is_record|is_record|is_process_alive|is_port|is_pid|is_number|is_list|is_integer|is_function|is_function|is_float|is_boolean|is_bitstring|is_binary|is_atom|is_alive|iolist_to_binary|iolist_size|iolist|iodata|integer_to_list|hd|halt|halt|group_leader|group_leader|get_keys|get|get|garbage_collect|garbage_collect|float_to_list|float|ext_binary|exit|exit|erase|erase|ence|element|disconnect_node|delete_module|date|concat_binary|check_process_code|byte_size|bitstring_to_list|bit_size|binary_to_term|binary_to_list|binary_to_list|atom_to_list|atom_to_list|apply|apply|apply|abs"),
|
2008-10-15 00:49:39 -04:00
|
|
|
RegionRule(r'erl_atom', r"'", AtomGrammar, r"'"),
|
2008-05-03 13:31:30 -04:00
|
|
|
RegionRule(r'string', r'"', StringGrammar, r'"'),
|
|
|
|
PatternRule(r'erl_atom', r"[a-z][a-zA-Z0-9_@]*"),
|
|
|
|
PatternRule(r'erl_variable', r"[A-Z_][a-zA-Z0-9_@]*"),
|
|
|
|
PatternRule(r'delimiter', r'->|<<|>>|\(|\)|{|}|\[|\]|\.|;|,|\|'),
|
2008-05-29 19:05:15 -04:00
|
|
|
PatternRule(r'operator', r'\+\+|--|==|/=|=<|<|>=|>|=:=|=/=>|-|\+|\*|/|:|#|!]'),
|
2008-05-03 13:31:30 -04:00
|
|
|
NocasePatternRule(r'number', r'\$.|[+-]?\d+#[a-z0-9]+|[+-]?\d+\.\d+|[+-]?\.\d+|[+-]?\d+'),
|
|
|
|
]
|
|
|
|
|
2008-05-29 19:05:15 -04:00
|
|
|
class ErlangTabber(tab.StackTabber):
|
2008-07-14 19:24:26 -04:00
|
|
|
enterlvl = ('after', 'begin', 'case', 'catch', 'fun', 'if', 'query', 'receive')
|
|
|
|
def _handle_close_token(self, currlvl, y, i):
|
|
|
|
self._opt_pop(*self.enterlvl)
|
|
|
|
return tab.StackTabber._handle_close_token(self, currlvl, y, i)
|
2008-05-29 19:05:15 -04:00
|
|
|
def _handle_other_token(self, currlvl, y, i):
|
|
|
|
token = self.get_token(y, i)
|
|
|
|
rtoken = self.get_next_right_token(y, i)
|
|
|
|
ltoken = self.get_next_left_token(y, i)
|
|
|
|
|
2008-07-14 19:24:26 -04:00
|
|
|
if token.name == 'eol':
|
|
|
|
pass
|
|
|
|
elif token.name == 'string.start':
|
|
|
|
self._append('string', None)
|
|
|
|
elif token.name == 'string.end':
|
|
|
|
self._opt_pop('string')
|
2008-05-29 19:05:15 -04:00
|
|
|
elif token.name == 'delimiter':
|
|
|
|
if token.string == '->':
|
|
|
|
if rtoken is None or rtoken.name == 'comment':
|
|
|
|
level = self.get_curr_level() + self.mode.tabwidth
|
|
|
|
else:
|
|
|
|
level = rtoken.x
|
|
|
|
self._append(token.string, level)
|
|
|
|
elif token.string == '.':
|
|
|
|
self.markers = []
|
|
|
|
elif token.string == ';':
|
|
|
|
self._pop()
|
|
|
|
elif token.name == 'erl_reserved':
|
|
|
|
if token.string in self.enterlvl:
|
|
|
|
if rtoken is None or rtoken.name == 'comment':
|
|
|
|
level = self.get_curr_level() + self.mode.tabwidth
|
|
|
|
else:
|
|
|
|
level = rtoken.x
|
|
|
|
self._append(token.string, level)
|
2008-07-14 19:24:26 -04:00
|
|
|
elif token.string == 'of':
|
|
|
|
self._opt_pop('case')
|
2008-05-29 19:05:15 -04:00
|
|
|
elif token.string == 'end':
|
|
|
|
self._opt_pop('->')
|
|
|
|
self._pop_unless('->')
|
2008-07-14 19:24:26 -04:00
|
|
|
currlvl = self.get_curr_level()
|
2008-05-29 19:05:15 -04:00
|
|
|
return currlvl
|
|
|
|
|
2008-05-03 13:31:30 -04:00
|
|
|
class Erlang(mode.Fundamental):
|
|
|
|
modename = 'Erlang'
|
|
|
|
extensions = ['.erl']
|
|
|
|
tabwidth = 4
|
2008-05-29 19:05:15 -04:00
|
|
|
tabbercls = ErlangTabber
|
2008-05-03 13:31:30 -04:00
|
|
|
grammar = ErlangGrammar
|
|
|
|
opentokens = ('delimiter',)
|
|
|
|
opentags = {'(': ')', '[': ']', '{': '}'}
|
|
|
|
closetokens = ('delimiter',)
|
|
|
|
closetags = {')': '(', ']': '[', '}': '{'}
|
|
|
|
colors = {
|
2008-05-11 23:37:57 -04:00
|
|
|
'erl_attribute': ('cyan', 'default', 'bold'),
|
|
|
|
'erl_reserved': ('cyan', 'default', 'bold'),
|
|
|
|
'erl_arity': ('magenta', 'default', 'bold'),
|
|
|
|
'erl_namespace': ('magenta', 'default', 'bold'),
|
2008-10-07 23:39:22 -04:00
|
|
|
'erl_function': ('blue', 'default', 'bold'),
|
2008-05-11 23:37:57 -04:00
|
|
|
'erl_builtin': ('magenta', 'default', 'bold'),
|
|
|
|
'erl_variable': ('yellow', 'default', 'bold'),
|
|
|
|
'erl_operator': ('default', 'default', 'bold'),
|
|
|
|
'erl_atom': ('magenta', 'default', 'bold'),
|
|
|
|
'erl_atom.start': ('magenta', 'default', 'bold'),
|
|
|
|
'erl_atom.null': ('magenta', 'default', 'bold'),
|
|
|
|
'erl_atom.end': ('magenta', 'default', 'bold'),
|
2008-05-03 13:31:30 -04:00
|
|
|
}
|
|
|
|
def __init__(self, w):
|
|
|
|
mode.Fundamental.__init__(self, w)
|
|
|
|
self.add_bindings('close-paren', (')',))
|
|
|
|
self.add_bindings('close-brace', ('}',))
|
|
|
|
self.add_bindings('close-bracket', (']',))
|
|
|
|
|
|
|
|
install = Erlang.install
|