pmacs3/mode/roy.py

117 lines
3.2 KiB
Python
Raw Permalink Normal View History

import os.path
import time
import tab
from mode.javascript import RegexGrammar, StringGrammar1, StringGrammar2
from mode import Fundamental
from method.shell import Interact
from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
chr1 = '[a-zA-Z_]'
chr2 = '[a-zA-Z_0-9]'
word = chr1 + chr2 + '*'
typ = '[A-Z]' + chr2 + '*'
class TypeDefGrammar(Grammar): pass
class StructDefGrammar(Grammar): pass
class RoyGrammar(Grammar): pass
RoyGrammar.rules = [
PatternRule('comment', r'//.*$'),
PatternRule('spaces', r'[ \t]+'),
PatternRule('eol', r'\n'),
RegionRule('string', "'", StringGrammar1, "'"),
RegionRule('string', '"', StringGrammar2, '"'),
#RegionRule('struct', '{', StructDefGrammar, '}'),
PatternRule('roy.number', r'-?[1-9][0-9]*(?:\.[0-9]+)?(?:e-?[0-9]+)?'),
PatternMatchRule('', '(' + word + ')(:)',
'roy.member', 'delimiter'),
PatternMatchRule('', '(' + word + ')( +)(:)',
'roy.member', 'spaces', 'delimiter'),
PatternMatchRule('', r'(\\)(' + word + ')', 'delimiter', 'roy.member'),
PatternMatchRule('', r'(' + word + ')( +)(<-)',
'roy.member', 'spaces', 'delimiter'),
PatternRule('roy.type', typ),
PatternMatchRule('', '(let)( +)(' + word + ')',
'roy.keyword', 'spaces', 'roy.variable'),
PatternRule('delimiter', r'(?:->|<-|:|=|,|\(|\)|{|}|\[|\]|\+|\|)'),
PatternRule('roy.keyword', '(?:do|else|if|let|type)(?!' + chr2 + ')'),
PatternRule('roy.bareword', word),
]
class RoyStart(Interact):
args = []
reuse = True
def _execute(self, w, **vargs):
cmd = w.application.config.get('roy.cmd', './roy')
Interact._execute(self, w, bname='*Roy*', cmd=cmd)
# white is for delimiters, operators, numbers
default = ('default', 'default')
# magenta is for reserved words
lo_magenta = ('magenta202', 'default')
hi_magenta = ('magenta505', 'default')
# red is for comments
lo_red = ('red300', 'default')
hi_red = ('red511', 'default')
# orange is unused
hi_orange = ('yellow531', 'default')
lo_orange = ('yellow520', 'default')
# yellow is for class names
hi_yellow = ('yellow551', 'default')
lo_yellow = ('yellow330', 'default')
# green is for strings
lo_green = ('green030', 'default')
hi_green = ('green050', 'default')
# cyan is for keywords and some operators
lo_cyan = ('cyan033', 'default')
hi_cyan = ('cyan155', 'default')
# blue is for functions and methods
lo_blue = ('blue113', 'default')
hi_blue = ('blue225', 'default')
class Roy(Fundamental):
name = 'Roy'
extensions = ['.roy']
tabwidth = 2
grammar = RoyGrammar
#tabbercls = JavascriptTabber2
#tagcls = JavascriptTagManager
commentc = '//'
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
'roy.member': hi_blue,
'roy.number': hi_orange,
'roy.type': hi_magenta,
'roy.keyword': hi_cyan,
}
config = {'roy.cmd': 'roy'}
actions = [RoyStart]
_bindings = {
'close-paren': (')',),
'close-brace': ('}',),
'close-bracket': (']',),
}
install = Roy.install