pmacs3/mode/console.py

38 lines
1.6 KiB
Python

import color, mode
from lex import Grammar, PatternRule, RegionRule
from mode.python import StringGrammar, PythonGrammar
class ReprGrammar(Grammar):
rules = [
RegionRule(r'string', r'"', StringGrammar, r'"'),
RegionRule(r'string', r"'", StringGrammar, r"'"),
]
class ConsoleGrammar(Grammar):
rules = [
PatternRule(r'console_mesg', r'^[A-Za-z].*$'),
PatternRule(r'console_input', r'^>>>.*$'),
PatternRule(r'console_input', r'^-->.*$'),
RegionRule(r'string', r'"', StringGrammar, r'"'),
RegionRule(r'string', r"'", StringGrammar, r"'"),
#RegionRule(r'console_repr', r"<", ReprGrammar, r">"),
PatternRule(r'console_reserved', r'True|False|None'),
PatternRule(r'console_bareword', r'[a-zA-Z_][a-zA-Z0-9_]*'),
]
class Console(mode.Fundamental):
modename = 'Console'
grammar = ConsoleGrammar()
colors = {
'console_mesg': ('magenta', 'default', 'bold'),
'console_input': ('cyan', 'default', 'bold'),
'console_reserved': ('magenta', 'default', 'bold'),
'console_bareword': ('default', 'default', 'bold'),
'console_repr.start': ('default', 'default', 'bold'),
'console_repr.null': ('blue', 'default', 'bold'),
'console_repr.string.start': ('cyan', 'default', 'bold'),
'console_repr.string.null': ('cyan', 'default', 'bold'),
'console_repr.string.end': ('cyan', 'default', 'bold'),
'console_repr.end': ('default', 'default', 'bold'),
}
install = Console.install