私はPythonを本当に話せないので、最初に「コピー、貼り付け、変更」ソリューションを作成した後、サブクラス化して大部分JavaLexer
のレキシングを委任する別のクイックアンドダーティソリューションをハックすることができました。JavaLexer
例外は
- AspectJ固有のキーワード、
- Java ラベルとしてではなく、AspectJ キーワードと「:」演算子および
- Java 名デコレーターとしてではなく、AspectJ キーワードとしての型間アノテーション宣言の処理。
私の小さなヒューリスティックな解決策にはいくつかの詳細が欠けていると確信していますが、アンドリュー・アイゼンバーグが言ったように、不完全ではあるが機能する解決策は、存在しない完全な解決策よりも優れています。
class AspectJLexer(JavaLexer):
"""
For `AspectJ <http://www.eclipse.org/aspectj/>`_ source code.
"""
name = 'AspectJ'
aliases = ['aspectj']
filenames = ['*.aj']
mimetypes = ['text/x-aspectj']
aj_keywords = [
'aspect', 'pointcut', 'privileged', 'call', 'execution',
'initialization', 'preinitialization', 'handler', 'get', 'set',
'staticinitialization', 'target', 'args', 'within', 'withincode',
'cflow', 'cflowbelow', 'annotation', 'before', 'after', 'around',
'proceed', 'throwing', 'returning', 'adviceexecution', 'declare',
'parents', 'warning', 'error', 'soft', 'precedence', 'thisJoinPoint',
'thisJoinPointStaticPart', 'thisEnclosingJoinPointStaticPart',
'issingleton', 'perthis', 'pertarget', 'percflow', 'percflowbelow',
'pertypewithin', 'lock', 'unlock', 'thisAspectInstance'
]
aj_inter_type = ['parents:', 'warning:', 'error:', 'soft:', 'precedence:']
aj_inter_type_annotation = ['@type', '@method', '@constructor', '@field']
def get_tokens_unprocessed(self, text):
for index, token, value in JavaLexer.get_tokens_unprocessed(self, text):
if token is Name and value in self.aj_keywords:
yield index, Keyword, value
elif token is Name.Label and value in self.aj_inter_type:
yield index, Keyword, value[:-1]
yield index, Operator, value[-1]
elif token is Name.Decorator and value in self.aj_inter_type_annotation:
yield index, Keyword, value
else:
yield index, token, value