pmacs3/mode/javap.py

93 lines
3.1 KiB
Python
Raw Normal View History

from mode import Fundamental
from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
class JavapGrammar(Grammar):
rules = [
PatternMatchRule('x', '^(package)( )(.+)$',
'javap.keyword', 'spaces', 'javap.package'),
PatternRule('javap.keyword', '(?:static|public|protected|private|final|abstract)'),
# pseudo keywords
PatternMatchRule('x', '(--class)( +)([^ ]+)',
'javap.pseudo', 'spaces', 'javap.type'),
PatternMatchRule('x', '(--field)( +)([^ ]+)( +)([^ ]+)',
'javap.pseudo', 'spaces', 'javap.type', 'spaces', 'javap.type'),
PatternRule('javap.pseudo', '--(?:method|iface|string|field)'),
# parse type args
PatternMatchRule('x', '([^ ]+)( +)(\()',
'javap.type', 'spaces', 'javap.delim'),
PatternMatchRule('x', '(class|extends|implements)( )([^ ]+)',
'javap.keyword', 'spaces', 'javap.type'),
PatternMatchRule('x', '([^ ]+)( )([^ ]+)( )(\()',
'javap.type', 'spaces', 'javap.method', 'spaces', 'javap.delim'),
PatternMatchRule('x', '([^ ]+)( )([^ ]+)( )({)(})',
'javap.type', 'spaces', 'javap.method', 'spaces', 'javap.delim', 'javap.delim'),
PatternMatchRule('x', '([^ ]+)(,)( )',
'javap.type', 'javap.delim', 'spaces'),
PatternMatchRule('x', '([^ ]+)(\))',
'javap.type', 'javap.delim'),
PatternMatchRule('x', '^( +)(\d+)( +)([^ ]+)',
'spaces', 'javap.byte', 'spaces', 'javap.ins'),
RegionRule('javap.string', r'"', None, r'"'),
PatternRule('javap.const', r'#\d+'),
PatternRule('javap.int', r'\d+'),
PatternRule('spaces', r' +'),
PatternRule('eol', r'\n'),
]
# white is for delimiters, operators, numbers
c_default = ('default', 'default')
# magenta is for keywords/builtins, translation, globs
lo_magenta = ('magenta202', 'default')
hi_magenta = ('magenta505', 'default')
# red is for comments, pods, endblocks
lo_red = ('red300', 'default')
hi_red = ('red511', 'default')
# orange are for arrays and hashes
hi_orange = ('yellow531', 'default')
lo_orange = ('yellow520', 'default')
# yellow is for scalars and prototypes
hi_yellow = ('yellow551', 'default')
lo_yellow = ('yellow330', 'default')
# green is for strings and hash keys
lo_green = ('green030', 'default')
hi_green = ('green050', 'default')
# cyan is for quotes, evals, regexes, subs
lo_cyan = ('cyan033', 'default')
hi_cyan = ('cyan155', 'default')
# blue is unused
lo_blue = ('blue113', 'default')
hi_blue = ('blue225', 'default')
class Javap(Fundamental):
name = 'Javap'
grammar = JavapGrammar()
colors = {
'javap.package': hi_yellow,
'javap.type': hi_cyan,
'javap.method': hi_blue,
'javap.byte': lo_orange,
'javap.ins': hi_orange,
'javap.const': hi_yellow,
'javap.keyword': hi_magenta,
'javap.pseudo': hi_magenta,
}
_bindings = {}
install = Javap.install