From 541f241d7d36ab0f436202fde11a30becd0d14cb Mon Sep 17 00:00:00 2001 From: moculus Date: Fri, 2 May 2008 23:18:17 +0000 Subject: [PATCH] prelim haskell support --HG-- branch : pmacs2 --- application.py | 2 +- mode/haskell.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 mode/haskell.py diff --git a/application.py b/application.py index 6f0de4e..9086987 100755 --- a/application.py +++ b/application.py @@ -128,7 +128,7 @@ class Application(object): 'make', 'mini', 'mutt', 'nasm', 'ocaml', 'perl', 'python', 'replace', 'rst', 'scheme', 'search', 'sh', 'sql', 'tt', 'text', 'text2', 'which', 'xml', 'cheetah', 'colortext', - 'latex', 'insertmini', 'conf') + 'latex', 'insertmini', 'conf', 'haskell') for name in names: exec("import mode.%s; mode.%s.install(self)" % (name, name)) diff --git a/mode/haskell.py b/mode/haskell.py new file mode 100644 index 0000000..abdd3f9 --- /dev/null +++ b/mode/haskell.py @@ -0,0 +1,59 @@ +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 + +class CommentGrammar(Grammar): + rules = [ + RegionRule(r'comment', r'{-', mode.lisp.StringGrammar, r'-}'), + ] + +class StringGrammar(Grammar): + rules = [ + RegionRule(r'gap', r'\\ *\n$', Grammar, r'^ *[^ \n]'), + NocasePatternRule(r'escaped', r'\\(?:NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS|US|SP|DEL|[&abfnrtv\\"\']|\^[a-z]|\d{1,3}|o[0-7]{0,3}|x(?:[0-9a-f]){0,2})'), + ] + +class HaskellGrammar(Grammar): + rules = [ + PatternRule(r'comment', r'--.*$'), + RegionRule(r'comment', r'{-', CommentGrammar, r'-}'), + RegionRule(r'hs_string', r'"', StringGrammar, r'"'), + PatternRule(r'hs_reserved', r"(?:_|where|type|then|of|newtype|module|let|instance|infixr|infixl|infix|in|import|if|else|do|deriving|default|data|class|case)(?![a-zA-Z0-9_'])"), + PatternRule(r'hs_declaration', r"^[a-z_][a-zA-Z0-9_']*"), + PatternRule(r'hs_variable', r"[a-z_][a-zA-Z0-9_']*"), + PatternRule(r'hs_constructor', r"[A-Z][a-zA-Z0-9_']*"), + #PatternRule(r'hs_operator', r'(?:=>|=|::|\||->|==|=)'), + PatternRule(r'hs_operator', r'@|!|>@>|>>=|>>|=>|::|->|;|<-|\\\\|\.\.|!!|:|\+\+|\||\.|\\|>=|>|/=|==|<=|<|\|\||&&|\^\^|\*\*|\^|/|\*|-|\+|='), + ] + +class Haskell(mode.Fundamental): + modename = 'Haskell' + extensions = ['.hs'] + tabwidth = 4 + #tabbercls = mode.lisp.LispTabber + grammar = HaskellGrammar + #opentokens = ('delimiter',) + #opentags = {'(': ')'} + #closetokens = ('delimiter',) + #closetags = {')': '('} + colors = { + 'hs_reserved': ('cyan', 'default'), + 'hs_constructor': ('magenta', 'default'), + 'hs_declaration': ('blue', 'default'), + 'hs_operator': ('green', 'default'), + 'hs_string.start': ('green', 'default'), + 'hs_string.null': ('green', 'default'), + 'hs_string.end': ('green', 'default'), + 'hs_string.escaped': ('magenta', 'default'), + 'hs_string.gap.start': ('red', 'default'), + 'hs_string.gap.null': ('red', 'default'), + 'hs_string.gap.end': ('red', 'default'), + } + 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 = Haskell.install