2007-08-14 09:43:23 -04:00
|
|
|
import commands, os.path, sets, string, sys, traceback
|
2007-10-21 20:55:29 -04:00
|
|
|
import color, completer, default, mode, method, regex, tab
|
2007-10-21 20:50:11 -04:00
|
|
|
from point import Point
|
2007-10-21 20:52:48 -04:00
|
|
|
from lex import Grammar, PatternRule, RegionRule, NocasePatternRule
|
2007-08-14 09:43:23 -04:00
|
|
|
|
|
|
|
class StringGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(r'continuation', r'\\(?=\n$)'),
|
|
|
|
PatternRule(r'escaped', r"\\[\\ \"'ntbr]"),
|
|
|
|
PatternRule(r'octal', r'\\[0-9]{3}'),
|
|
|
|
PatternRule(r'hex', r'\\x[0-9A-Fa-f]{2}'),
|
|
|
|
]
|
|
|
|
|
|
|
|
class CommentGrammar(Grammar):
|
|
|
|
rules = []
|
|
|
|
CommentGrammar.rules.append(RegionRule(r'comment', r'\(\*', CommentGrammar, r'\*\)'))
|
|
|
|
|
|
|
|
class OcamlGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(r'spaces', r' +'),
|
|
|
|
PatternRule(r'eol', r'\n'),
|
|
|
|
RegionRule(r'comment', r'\(\*', CommentGrammar, r'\*\)'),
|
|
|
|
|
|
|
|
PatternRule(r'linenum', r'#[0-9]+ *(?:"(?:[^"\\]|\\[0-9]{3}|\\x[0-9A-Za-z]{2}|\\.)*")?'),
|
|
|
|
|
2007-08-16 11:20:46 -04:00
|
|
|
PatternRule(r'delimiter', r"[()]"),
|
|
|
|
|
2008-03-16 01:23:14 -04:00
|
|
|
PatternRule(r'ocaml_keyword', r"(?:with|while|when|virtual|val|type|try|true|to|then|struct|sig|rec|private|parser|or|open|of|object|new|mutable|module|mod|method|match|lxor|lsr|lsl|lor|let|lazy|land|initializer|inherti|include|in|if|functor|function|fun|for|false|external|exception|end|else|downto|done|do|constraint|class|begin|asr|assert|as|and)(?!['a-zA-Z0-9_])"),
|
2007-08-14 09:43:23 -04:00
|
|
|
|
|
|
|
PatternRule(r'builtin', r"(?:int|char|string|float|bool|false|true|unit|exn|array|list|option|int32|int64|nativeint|format4|lazy_t)(?!['a-zA-Z0-9_])"),
|
|
|
|
PatternRule(r'builtin_exception', r"(?:Match_failure|Assert_failure|Invalid_argument|Failure|Not_found|Out_of_memory|Stack_overflow|Sys_error|End_of_file|Division_by_zero|Sys_blocked_io|Undefined_recursive_module|Exit)(?!['a-zA-Z0-9_])"),
|
|
|
|
PatternRule(r'builtin_function', r"raise|invalid_arg|failwith"),
|
|
|
|
|
|
|
|
NocasePatternRule(r'identifier', r"[a-z_]['a-z0-9_]*"),
|
|
|
|
|
|
|
|
NocasePatternRule(r'integer', r"-?[0-9][0-9_]*"),
|
|
|
|
NocasePatternRule(r'integer', r"-?0x[0-9a-f][0-9a-f_]*"),
|
|
|
|
NocasePatternRule(r'integer', r"-?0o[0-7][0-7_]*"),
|
|
|
|
NocasePatternRule(r'integer', r"-?0b[01][01_]*"),
|
|
|
|
|
|
|
|
NocasePatternRule(r'float', r"-?[0-9][0-9_]*(?:\.[0-9_]*)?(?:e[+-]?[0-9][0-9_]*)?"),
|
|
|
|
|
|
|
|
PatternRule(r'char', r"'[^\\']'"),
|
|
|
|
PatternRule(r'char', r"'\\[\\ \"'ntbr]'"),
|
|
|
|
PatternRule(r'char', r"'\\[0-9]{3}'"),
|
|
|
|
PatternRule(r'char', r"'\\x[0-9A-Fa-f]{2}'"),
|
|
|
|
|
2008-03-16 01:23:14 -04:00
|
|
|
RegionRule(r'ocaml_string', r'"', StringGrammar, '"'),
|
2007-08-14 09:43:23 -04:00
|
|
|
|
|
|
|
PatternRule(r'label', r"~[a-z_]['a-zA-Z0-9_]*:"),
|
|
|
|
PatternRule(r'optlabel', r"\?[a-z_]['a-zA-Z0-9_]*:"),
|
|
|
|
|
|
|
|
PatternRule(r'infix', r'[-=<>@^|&+*/$%][-!$%&*+\./:<=>?@^|~]*'),
|
|
|
|
PatternRule(r'prefix', r'[!?~][-!$%&*+\./:<=>?@^|~]*'),
|
|
|
|
]
|
|
|
|
|
2007-10-21 20:55:29 -04:00
|
|
|
class Ocaml(mode.Fundamental):
|
2007-10-18 17:07:35 -04:00
|
|
|
modename = 'ocaml'
|
|
|
|
extensions = ['.mli', '.ml']
|
2007-08-14 09:43:23 -04:00
|
|
|
grammar = OcamlGrammar
|
2007-08-16 11:20:46 -04:00
|
|
|
opentokens = ('delimiter',)
|
|
|
|
opentags = {'(': ')'}
|
|
|
|
closetokens = ('delimiter',)
|
|
|
|
closetags = {')': '('}
|
2007-10-18 17:07:35 -04:00
|
|
|
colors = {
|
2008-03-16 01:23:14 -04:00
|
|
|
#'comment.start': ('red', 'default'),
|
|
|
|
#'comment.null': ('red', 'default'),
|
|
|
|
#'comment.end': ('red', 'default'),
|
2007-08-14 09:43:23 -04:00
|
|
|
'linenum': ('red', 'default'),
|
|
|
|
|
2008-03-16 01:23:14 -04:00
|
|
|
'ocaml_keyword': ('cyan', 'default'),
|
2007-08-14 09:43:23 -04:00
|
|
|
|
|
|
|
#'builtin': ('magenta', 'default'),
|
|
|
|
#'builtin_exception': ('magenta', 'default'),
|
|
|
|
#'builtin_function': ('magenta', 'default'),
|
|
|
|
|
2008-03-16 01:23:14 -04:00
|
|
|
'ocaml_label': ('blue', 'default'),
|
2007-08-14 09:43:23 -04:00
|
|
|
'optlabel': ('blue', 'default'),
|
|
|
|
|
2008-03-16 01:23:14 -04:00
|
|
|
'ocaml_string.start': ('green', 'default'),
|
|
|
|
'ocaml_string.null': ('green', 'default'),
|
|
|
|
'ocaml_string.octal': ('magenta', 'default'),
|
|
|
|
'ocaml_string.hex': ('magenta', 'default'),
|
|
|
|
'ocaml_string.escaped': ('magenta', 'default'),
|
|
|
|
'ocaml_string.end': ('green', 'default'),
|
|
|
|
#'char': ('green', 'default'),
|
|
|
|
#'integer': ('default', 'default'),
|
|
|
|
#'float': ('default', 'default'),
|
2007-08-14 09:43:23 -04:00
|
|
|
}
|
|
|
|
def __init__(self, w):
|
2007-10-21 20:55:29 -04:00
|
|
|
mode.Fundamental.__init__(self, w)
|
2007-08-16 11:20:46 -04:00
|
|
|
self.add_bindings('close-paren', (')',))
|
|
|
|
self.add_bindings('close-brace', ('}',))
|
|
|
|
self.add_bindings('close-bracket', (']',))
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = Ocaml.install
|