Commits

Alexander Kriegisch  committed 4e4676a

Add AspectJLexer as subclass of JavaLexer

  • Participants
  • Parent commits 26bcb42

Comments (0)

Files changed (2)

File pygments/lexers/_mapping.py

     'AntlrRubyLexer': ('pygments.lexers.parsers', 'ANTLR With Ruby Target', ('antlr-ruby', 'antlr-rb'), ('*.G', '*.g'), ()),
     'ApacheConfLexer': ('pygments.lexers.text', 'ApacheConf', ('apacheconf', 'aconf', 'apache'), ('.htaccess', 'apache.conf', 'apache2.conf'), ('text/x-apacheconf',)),
     'AppleScriptLexer': ('pygments.lexers.other', 'AppleScript', ('applescript',), ('*.applescript',), ()),
+    'AspectJLexer': ('pygments.lexers.jvm', 'AspectJ', ('aspectj',), ('*.aj',), ('text/x-aspectj',)),
     'AsymptoteLexer': ('pygments.lexers.other', 'Asymptote', ('asy', 'asymptote'), ('*.asy',), ('text/x-asymptote',)),
     'AutohotkeyLexer': ('pygments.lexers.other', 'autohotkey', ('ahk',), ('*.ahk', '*.ahkl'), ('text/x-autohotkey',)),
     'AwkLexer': ('pygments.lexers.other', 'Awk', ('awk', 'gawk', 'mawk', 'nawk'), ('*.awk',), ('application/x-awk',)),

File pygments/lexers/jvm.py

 from pygments import unistring as uni
 
 
-__all__ = ['JavaLexer', 'ScalaLexer', 'GosuLexer', 'GosuTemplateLexer',
-           'GroovyLexer', 'IokeLexer', 'ClojureLexer', 'KotlinLexer']
+__all__ = ['JavaLexer', 'AspectJLexer', 'ScalaLexer', 'GosuLexer',
+           'GosuTemplateLexer', 'GroovyLexer', 'IokeLexer', 'ClojureLexer',
+           'KotlinLexer']
 
 
 class JavaLexer(RegexLexer):
     }
 
 
+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
+
+
 class ScalaLexer(RegexLexer):
     """
     For `Scala <http://www.scala-lang.org>`_ source code.