2011-12-15 23:51:11 -05:00
|
|
|
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)'),
|
2011-12-16 11:54:32 -05:00
|
|
|
|
|
|
|
# pseudo keywords
|
2011-12-15 23:51:11 -05:00
|
|
|
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)'),
|
|
|
|
|
2011-12-16 11:54:32 -05:00
|
|
|
# parse type args
|
2011-12-15 23:51:11 -05:00
|
|
|
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'),
|
|
|
|
|
2011-12-16 11:54:32 -05:00
|
|
|
RegionRule('javap.string', r'"', None, r'"'),
|
2011-12-15 23:51:11 -05:00
|
|
|
|
2011-12-16 11:54:32 -05:00
|
|
|
PatternRule('javap.const', r'#\d+'),
|
|
|
|
PatternRule('javap.int', r'\d+'),
|
2011-12-15 23:51:11 -05:00
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
2011-12-16 11:54:32 -05:00
|
|
|
_bindings = {}
|
2011-12-15 23:51:11 -05:00
|
|
|
|
|
|
|
install = Javap.install
|