From b673ef2a528702a1ff8eca2eb9d650cc4b07d834 Mon Sep 17 00:00:00 2001 From: moculus Date: Thu, 26 Feb 2009 19:37:43 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- application.py | 1 + mode/haskell.py | 46 +++++++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/application.py b/application.py index 1e3d174..8fafc97 100755 --- a/application.py +++ b/application.py @@ -48,6 +48,7 @@ class Application(object): 'number': ('default', 'default', 'bold'), 'label': ('magenta', 'default', 'bold'), 'keyword': ('cyan', 'default', 'bold'), + 'reserved': ('cyan', 'default', 'bold'), 'function': ('blue', 'default', 'bold'), 'builtin': ('magenta', 'default', 'bold'), 'method': ('cyan', 'default', 'bold'), diff --git a/mode/haskell.py b/mode/haskell.py index 67896f4..753952d 100644 --- a/mode/haskell.py +++ b/mode/haskell.py @@ -3,31 +3,40 @@ 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'{-', None, r'-}'), - PatternRule(r'data', r'(?:[^{-]|{(?!-)|-(?!}))+'), - ] +class CommentGrammar(Grammar): pass +CommentGrammar.rules = [ + RegionRule(r'comment', r'{-', CommentGrammar, r'-}'), + PatternRule(r'data', 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})'), - PatternRule(r'data', r'[^\\]+'), + PatternRule(r'data', r'[^\\"]+'), ] class HaskellGrammar(Grammar): rules = [ - PatternRule(r'comment', r'--.*$'), + 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'integer', r'[0-9]+|0[oO][0-7]+|0[xX][0-7]+'), + PatternRule(r'float', r'[0-9]+\.[0-9]+(?:[eE][+-]?[0-9]+)?|[0-9]+[eE][+-]?[0-9]+'), + PatternRule(r'char', r"'[^'\\]'"), + PatternRule(r'char', 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}))'"), + + RegionRule(r'string', r'"', StringGrammar, r'"'), + PatternRule(r'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'operator', r'@|!|>@>|>>=|>>|=>|::|->|;|<-|\\\\|\.\.|!!|:|\+\+|\||\.|\\|>=|>|/=|==|<=|<|\|\||&&|\^\^|\*\*|##|\^|/|\*|-|\+|='), ] +class HaskellTabber(tab.Tabber): + pass + class Haskell(mode.Fundamental): modename = 'Haskell' extensions = ['.hs'] @@ -40,17 +49,12 @@ class Haskell(mode.Fundamental): #closetokens = ('delimiter',) #closetags = {')': '('} colors = { - 'hs_reserved': ('cyan', 'default', 'bold'), - 'hs_constructor': ('magenta', 'default', 'bold'), - 'hs_declaration': ('blue', 'default', 'bold'), - 'hs_operator': ('green', 'default', 'bold'), - 'hs_string.start': ('green', 'default', 'bold'), - 'hs_string.null': ('green', 'default', 'bold'), - 'hs_string.end': ('green', 'default', 'bold'), - 'hs_string.escaped': ('magenta', 'default', 'bold'), - 'hs_string.gap.start': ('red', 'default', 'bold'), - 'hs_string.gap.null': ('red', 'default', 'bold'), - 'hs_string.gap.end': ('red', 'default', 'bold'), + 'hs_constructor': ('magenta', 'default', 'bold'), + 'hs_declaration': ('blue', 'default', 'bold'), + 'hs_variable': ('yellow', 'default', 'bold'), + 'string.gap.start': ('red', 'default', 'bold'), + 'string.gap.null': ('red', 'default', 'bold'), + 'string.gap.end': ('red', 'default', 'bold'), } install = Haskell.install