2009-03-30 01:10:25 -04:00
|
|
|
import os.path
|
|
|
|
from method.shell import Interact
|
|
|
|
from mode import Fundamental
|
2008-05-02 19:18:17 -04:00
|
|
|
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule, NocasePatternRule
|
2009-03-30 01:10:25 -04:00
|
|
|
from tab import Tabber
|
2008-05-02 19:18:17 -04:00
|
|
|
|
2009-02-26 14:37:43 -05:00
|
|
|
class CommentGrammar(Grammar): pass
|
|
|
|
CommentGrammar.rules = [
|
|
|
|
RegionRule(r'comment', r'{-', CommentGrammar, r'-}'),
|
|
|
|
PatternRule(r'data', r'(?:[^{-]|{(?!-)|-(?!}))+'),
|
|
|
|
]
|
2008-05-02 19:18:17 -04:00
|
|
|
|
|
|
|
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})'),
|
2009-02-26 14:37:43 -05:00
|
|
|
PatternRule(r'data', r'[^\\"]+'),
|
2008-05-02 19:18:17 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
class HaskellGrammar(Grammar):
|
|
|
|
rules = [
|
2009-02-26 14:37:43 -05:00
|
|
|
PatternRule(r'comment', r'--(?!>).*$'),
|
2008-05-02 19:18:17 -04:00
|
|
|
RegionRule(r'comment', r'{-', CommentGrammar, r'-}'),
|
2009-02-26 14:37:43 -05:00
|
|
|
|
|
|
|
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}))'"),
|
|
|
|
|
2009-03-03 15:15:14 -05:00
|
|
|
PatternRule(r'spaces', r' +'),
|
|
|
|
PatternRule(r'eol', r'\n'),
|
|
|
|
PatternRule(r'delimiter', r'[\[\](){};]'),
|
|
|
|
|
2009-02-26 14:37:43 -05:00
|
|
|
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_'])"),
|
2008-05-02 19:18:17 -04:00
|
|
|
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_']*"),
|
2009-03-03 15:15:14 -05:00
|
|
|
PatternRule(r'hs_operator', r'`[a-z_][a-zA-Z0-9_\']*`'),
|
2009-02-26 14:37:43 -05:00
|
|
|
PatternRule(r'operator', r'@|!|>@>|>>=|>>|=>|::|->|;|<-|\\\\|\.\.|!!|:|\+\+|\||\.|\\|>=|>|/=|==|<=|<|\|\||&&|\^\^|\*\*|##|\^|/|\*|-|\+|='),
|
2008-05-02 19:18:17 -04:00
|
|
|
]
|
|
|
|
|
2009-03-30 01:10:25 -04:00
|
|
|
class HugsStart(Interact):
|
2009-03-03 21:10:32 -05:00
|
|
|
args = []
|
|
|
|
def _execute(self, w, **vargs):
|
2009-03-30 01:10:25 -04:00
|
|
|
Interact._execute(self, w, bname='*Hugs*', cmd='hugs')
|
|
|
|
class HugsLoadFile(Interact):
|
2009-03-04 01:31:06 -05:00
|
|
|
args = []
|
|
|
|
def _execute(self, w, **vargs):
|
2009-03-30 01:10:25 -04:00
|
|
|
Interact._execute(self, w, bname='*Hugs*', cmd='hugs')
|
2009-03-04 01:31:06 -05:00
|
|
|
b = w.application.get_buffer_by_name('*Hugs*')
|
|
|
|
path = os.path.realpath(w.buffer.path)
|
|
|
|
b.pipe_write(':load "%s"\n' % path)
|
2009-03-03 21:10:32 -05:00
|
|
|
|
2009-03-30 01:10:25 -04:00
|
|
|
class HaskellTabber(Tabber):
|
2009-02-26 14:37:43 -05:00
|
|
|
pass
|
|
|
|
|
2009-03-30 01:10:25 -04:00
|
|
|
class Haskell(Fundamental):
|
2009-03-17 15:24:10 -04:00
|
|
|
name = 'Haskell'
|
|
|
|
extensions = ['.hs']
|
|
|
|
tabwidth = 4
|
|
|
|
commentc = '--'
|
|
|
|
grammar = HaskellGrammar
|
2009-03-03 15:15:14 -05:00
|
|
|
opentokens = ('delimiter',)
|
|
|
|
opentags = {'(': ')', '{': '}', '[': ']'}
|
|
|
|
closetokens = ('delimiter',)
|
|
|
|
closetags = {')': '(', '}': '{', ']': '['}
|
2009-03-17 15:24:10 -04:00
|
|
|
colors = {
|
2009-02-26 14:37:43 -05:00
|
|
|
'hs_constructor': ('magenta', 'default', 'bold'),
|
|
|
|
'hs_declaration': ('blue', 'default', 'bold'),
|
|
|
|
'hs_variable': ('yellow', 'default', 'bold'),
|
2009-03-03 15:15:14 -05:00
|
|
|
'hs_operator': ('cyan', 'default', 'bold'),
|
2009-02-26 14:37:43 -05:00
|
|
|
'string.gap.start': ('red', 'default', 'bold'),
|
|
|
|
'string.gap.null': ('red', 'default', 'bold'),
|
|
|
|
'string.gap.end': ('red', 'default', 'bold'),
|
2008-05-02 19:18:17 -04:00
|
|
|
}
|
2009-03-03 21:10:32 -05:00
|
|
|
_bindings = {
|
|
|
|
'close-paren': (')',),
|
|
|
|
'close-brace': ('}',),
|
|
|
|
'close-bracket': (']',),
|
|
|
|
}
|
2009-03-04 01:31:06 -05:00
|
|
|
actions = [HugsStart, HugsLoadFile]
|
2008-05-02 19:18:17 -04:00
|
|
|
|
|
|
|
install = Haskell.install
|