0

AspectJ (*.aj) ファイルが構文強調表示されない理由を GitHub のサポート担当者に尋ねました。答えは、彼らは Pygments を使用しているが、AspectJ 用の既存のレクサーを認識していないというものでした。私は簡単なウェブ検索を行いましたが、どちらも見つかりませんでした。ここに誰かが書いたことがありますか、それとも既存のものへのリンクを教えてくれますか?

ずっと前に、Kconfig (Linux カーネル構成) ファイルのレクサーを作成しましたが、Python を話せないので、かなり苦労しました。ですから、再び頭を悩ませる前に、車輪を再発明するのではなく、まず質問したほうがよいと思いました。

4

2 に答える 2

2

私は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
于 2012-08-08T14:29:23.150 に答える
1

Javaレクサーから始める場合、aspectjの構文の強調表示は非常に簡単に実装できるはずです。レクサーは、いくつかの追加キーワードを除いてJavaのものと同じになります。

AspectJ固有のキーワードのリストについては、こちらを参照してください:http: //git.eclipse.org/c/ajdt/org.eclipse.ajdt.git/tree/org.eclipse.ajdt.core/src/org/eclipse/ ajdt / core / AspectJPlugin.java

そしてここでJavaキーワードについて:http: //git.eclipse.org/c/ajdt/org.eclipse.ajdt.git/tree/org.eclipse.ajdt.ui/src/org/eclipse/ajdt/internal/ui /editor/AspectJCodeScanner.java

于 2012-07-29T03:53:21.200 に答える