65 lines
2.7 KiB
Python
65 lines
2.7 KiB
Python
|
import color, mode2, tab2
|
||
|
from lex3 import Grammar, PatternRule, RegionRule
|
||
|
from mode.python import StringGrammar
|
||
|
from mode.c import CTabber
|
||
|
|
||
|
class JavaGrammar(Grammar):
|
||
|
rules = [
|
||
|
PatternRule(r'package', r'(?<=import ) *[a-zA-Z0-9_.*]+'),
|
||
|
|
||
|
RegionRule(r'comment', '/\*', Grammar, '\*/'),
|
||
|
PatternRule(r'comment', r'//.*$'),
|
||
|
|
||
|
PatternRule(r'keyword', r"(?:abstract|assert|boolean|break|byte|case|catch|char|class|continue|default|double|do|else|extends|finally|final|float|for|if|implements|import|instanceof|int|long|new|private|protected|public|return|short|static|switch|super|synchronized|throws|throw|try|void|while)(?![a-zA-Z_])"),
|
||
|
PatternRule(r'label', r'[a-zA-Z_][a-zA-Z0-9_]*(?=:)'),
|
||
|
|
||
|
PatternRule(r'builtin', r"(?:null|true|false|this)"),
|
||
|
PatternRule(r'identifier', r"[a-zA-Z_][a-zA-Z0-9_]*"),
|
||
|
PatternRule(r"unop", r"\+=|-=|\*=|/=|//=|%=|&=\|\^=|>>=|<<=|\*\*="),
|
||
|
PatternRule(r'binop', r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
|
||
|
|
||
|
PatternRule(r"delimiter", r"->|\.|\(|\)|\[|\]|{|}|@|,|:|`|;|=|\?"),
|
||
|
|
||
|
PatternRule(r"integer", r"(?:0(?![x0-9])|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?"),
|
||
|
PatternRule(r"float", r"[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+"),
|
||
|
RegionRule(r'string', '"', StringGrammar, '"'),
|
||
|
PatternRule(r'char', r"'.'|'\\.'|'\\[0-7]{3}'"),
|
||
|
PatternRule(r"eol", r"\n$"),
|
||
|
]
|
||
|
|
||
|
class Java(mode2.Fundamental):
|
||
|
#tabbercls = CTabber
|
||
|
grammar = JavaGrammar
|
||
|
opentokens = ('delimiter',)
|
||
|
opentags = {'(': ')', '[': ']', '{': '}'}
|
||
|
closetokens = ('delimiter',)
|
||
|
closetags = {')': '(', ']': '[', '}': '{'}
|
||
|
colors = {
|
||
|
'comment': ('red', 'default'),
|
||
|
'comment.start': ('red', 'default'),
|
||
|
'comment.end': ('red', 'default'),
|
||
|
'comment.null': ('red', 'default'),
|
||
|
|
||
|
'package': ('blue', 'default'),
|
||
|
'label': ('magenta', 'default'),
|
||
|
'keyword': ('cyan', 'default'),
|
||
|
'function': ('blue', 'default'),
|
||
|
'builtin': ('magenta', 'default'),
|
||
|
|
||
|
'char': ('green', 'default'),
|
||
|
'string.start': ('green', 'default'),
|
||
|
'string.octal': ('green', 'default'),
|
||
|
'string.escaped': ('green', 'default'),
|
||
|
'string.null': ('green', 'default'),
|
||
|
'string.end': ('green', 'default'),
|
||
|
'integer': ('green', 'default'),
|
||
|
'float': ('green', 'default'),
|
||
|
}
|
||
|
def __init__(self, w):
|
||
|
mode2.Fundamental.__init__(self, w)
|
||
|
self.add_bindings('close-paren', (')',))
|
||
|
self.add_bindings('close-brace', ('}',))
|
||
|
self.add_bindings('close-bracket', (']',))
|
||
|
def name(self):
|
||
|
return "Java"
|