pmacs3/mode/idris.py

103 lines
3.4 KiB
Python
Raw Normal View History

import os.path
#from method.shell import Interact
from mode import Fundamental
from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
from tab import Tabber
class CommentGrammar(Grammar): pass
CommentGrammar.rules = [
RegionRule(r'comment', r'{-', CommentGrammar, r'-}'), #nested
PatternRule(r'data', r'(?:[^{-]|{(?!-)|-(?!}))+'),
]
class StringGrammar(Grammar):
rules = [
PatternRule(r'escaped', r'\\.'),
PatternRule(r'data', r'[^\\"]+'),
]
class IdrisGrammar(Grammar):
rules = [
PatternRule(r'comment', r'--.*$'),
RegionRule(r'comment', r'{-', CommentGrammar, r'-}'),
# %access and such
PatternMatchRule('x', r'(%[a-z]+)( +)([^ \t\n]+)', 'idris.keyword', 'spaces', 'idris.directive'),
# probably too simple
PatternRule(r'integer', r'-?[0-9]+'),
PatternRule(r'float', r'-?[0-9]+\.[0-9]+(?:[eE][+-]?[0-9]+)?|-?[0-9]+[eE][+-]?[0-9]+'),
PatternRule(r'char', r"'[^'\\]'"),
PatternRule(r'spaces', r'[ \t]+'),
PatternRule(r'eol', r'\n'),
2021-09-30 23:58:35 -04:00
PatternRule(r'delimiter', r'[\[\](){},;$]'),
PatternRule(r'idris.xyz', r'(?:=>|->|<-|=|:)(?![-!#$%&\*\+./<=>\?@\\^|~:])'),
PatternMatchRule('x', r"(module)( +)([a-zA-Z0-9_']+)", "idris.keyword", "spaces", "idris.module"),
#PatternMatchRule('x', r"(record|data|codata|class)( +)([a-zA-Z0-9_']+)", "idris.keyword", "spaces", "idris.def"),
# maybe wrong?
PatternRule(r'idris.operator', r"[-!#$%&\*\+./<=>\?@\\^|~:]+"),
RegionRule(r'string', r'"', StringGrammar, r'"'),
PatternRule(r'idris.keyword', r"(?:with|where|using|try|trivial|total|then|term|syntax|solve|rewrite|refine|record|public|private|prefix|pattern|partial|parameters|of|namespace|mutual|module|let|intros|instance|infixr|infixl|infix|in|import|if|focus|exact|else|dsl|do|data|compute|codata|class|case|attack|abstract)(?![a-zA-Z0-9_'])"),
2021-09-30 23:58:35 -04:00
PatternRule(r'idris.builtin', "(?:_|implicit|default|auto)(?![a-zA-Z0-9_'])"),
PatternRule(r'idris.name', r"['_]?[A-Z][a-zA-Z0-9_']+"),
PatternRule(r'idris.word', r"[a-zA-Z0-9_']+"),
]
class IdrisTabber(Tabber):
pass
c_default = ('default', 'default')
lo_magenta = ('magenta202', 'default')
hi_magenta = ('magenta505', 'default')
lo_red = ('red300', 'default')
hi_red = ('red511', 'default')
hi_orange = ('yellow531', 'default')
lo_orange = ('yellow520', 'default')
hi_yellow = ('yellow551', 'default')
lo_yellow = ('yellow330', 'default')
lo_green = ('green030', 'default')
hi_green = ('green050', 'default')
lo_cyan = ('cyan033', 'default')
hi_cyan = ('cyan155', 'default')
lo_blue = ('blue113', 'default')
hi_blue = ('blue225', 'default')
class Idris(Fundamental):
name = 'Idris'
extensions = ['.idr']
tabwidth = 2
commentc = '--'
grammar = IdrisGrammar
opentokens = ('delimiter',)
opentags = {'(': ')', '{': '}', '[': ']'}
closetokens = ('delimiter',)
closetags = {')': '(', '}': '{', ']': '['}
colors = {
'idris.keyword': hi_magenta,
2021-09-30 23:58:35 -04:00
'idris.builtin': hi_magenta,
'idris.module': hi_yellow,
2021-09-30 23:58:35 -04:00
'idris.name': hi_blue,
'idris.xyz': hi_cyan,
'idris.directive': hi_orange,
}
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
}
#actions = [HugsStart, HugsLoadFile]
install = Idris.install