2007-08-14 09:43:23 -04:00
|
|
|
import commands, os.path, sets, string, sys, traceback
|
|
|
|
import color, completer, default, mode2, method, regex, tab2
|
|
|
|
from point2 import Point
|
|
|
|
from lex3 import Grammar, PatternRule, RegionRule, NocasePatternRule
|
|
|
|
|
|
|
|
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"[()]"),
|
|
|
|
|
2007-08-14 09:43:23 -04:00
|
|
|
PatternRule(r'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_])"),
|
|
|
|
|
|
|
|
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}'"),
|
|
|
|
|
|
|
|
RegionRule(r'string', r'"', StringGrammar, '"'),
|
|
|
|
|
|
|
|
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'[!?~][-!$%&*+\./:<=>?@^|~]*'),
|
|
|
|
]
|
|
|
|
|
|
|
|
class Ocaml(mode2.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 = {
|
2007-08-14 09:43:23 -04:00
|
|
|
'comment.start': ('red', 'default'),
|
|
|
|
'comment.null': ('red', 'default'),
|
|
|
|
'comment.end': ('red', 'default'),
|
|
|
|
'linenum': ('red', 'default'),
|
|
|
|
|
|
|
|
'keyword': ('cyan', 'default'),
|
|
|
|
|
|
|
|
#'builtin': ('magenta', 'default'),
|
|
|
|
#'builtin_exception': ('magenta', 'default'),
|
|
|
|
#'builtin_function': ('magenta', 'default'),
|
|
|
|
|
|
|
|
'label': ('blue', 'default'),
|
|
|
|
'optlabel': ('blue', 'default'),
|
|
|
|
|
|
|
|
'string.start': ('green', 'default'),
|
|
|
|
'string.null': ('green', 'default'),
|
|
|
|
'string.octal': ('magenta', 'default'),
|
|
|
|
'string.hex': ('magenta', 'default'),
|
|
|
|
'string.escaped': ('magenta', 'default'),
|
|
|
|
'string.end': ('green', 'default'),
|
|
|
|
'char': ('green', 'default'),
|
|
|
|
'integer': ('default', 'default'),
|
|
|
|
'float': ('default', 'default'),
|
|
|
|
}
|
|
|
|
def __init__(self, w):
|
|
|
|
mode2.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
|