summaryrefslogtreecommitdiff
path: root/pygments/lexers/jvm.py
diff options
context:
space:
mode:
authorEnrique Zamudio <alterbass@gmail.com>2012-09-26 13:56:41 -0500
committerEnrique Zamudio <alterbass@gmail.com>2012-09-26 13:56:41 -0500
commit1e8d10aaf3b7bed6adb4f0706cf30e8a46f3b598 (patch)
tree01c7a72d47ec99708f811e00f081a1beb8c0eb54 /pygments/lexers/jvm.py
parentae714451a8eda58af9468728277ccaeb6fd011f7 (diff)
parent520215091a7b8e4dad1da581b76d10e1d8faf67c (diff)
downloadpygments-1e8d10aaf3b7bed6adb4f0706cf30e8a46f3b598.tar.gz
merge from birkenfeld/pygments-main
Diffstat (limited to 'pygments/lexers/jvm.py')
-rw-r--r--pygments/lexers/jvm.py142
1 files changed, 113 insertions, 29 deletions
diff --git a/pygments/lexers/jvm.py b/pygments/lexers/jvm.py
index 3ccbb2a5..0eb38d4a 100644
--- a/pygments/lexers/jvm.py
+++ b/pygments/lexers/jvm.py
@@ -21,7 +21,7 @@ from pygments import unistring as uni
__all__ = ['JavaLexer', 'ScalaLexer', 'GosuLexer', 'GosuTemplateLexer',
'GroovyLexer', 'IokeLexer', 'ClojureLexer', 'KotlinLexer',
- 'CeylonLexer', 'XtendLexer', 'AspectJLexer']
+ 'XtendLexer', 'AspectJLexer']
class JavaLexer(RegexLexer):
@@ -36,15 +36,12 @@ class JavaLexer(RegexLexer):
flags = re.MULTILINE | re.DOTALL
- #: optional Comment or Whitespace
- _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
-
tokens = {
'root': [
# method names
- (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # return arguments
- r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
- r'(\s*)(\()', # signature start
+ (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]<>]*\s+)+?)' # return arguments
+ r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
+ r'(\s*)(\()', # signature start
bygroups(using(this), Name.Function, Text, Operator)),
(r'[^\S\n]+', Text),
(r'//.*?\n', Comment.Single),
@@ -82,6 +79,45 @@ class JavaLexer(RegexLexer):
}
+class AspectJLexer(JavaLexer):
+ """
+ For `AspectJ <http://www.eclipse.org/aspectj/>`_ source code.
+
+ *New in Pygments 1.6.*
+ """
+
+ 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.
@@ -94,9 +130,6 @@ class ScalaLexer(RegexLexer):
flags = re.MULTILINE | re.DOTALL
- #: optional Comment or Whitespace
- _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
-
# don't use raw unicode strings!
op = u'[-~\\^\\*!%&\\\\<>\\|+=:/?@\u00a6-\u00a7\u00a9\u00ac\u00ae\u00b0-\u00b1\u00b6\u00d7\u00f7\u03f6\u0482\u0606-\u0608\u060e-\u060f\u06e9\u06fd-\u06fe\u07f6\u09fa\u0b70\u0bf3-\u0bf8\u0bfa\u0c7f\u0cf1-\u0cf2\u0d79\u0f01-\u0f03\u0f13-\u0f17\u0f1a-\u0f1f\u0f34\u0f36\u0f38\u0fbe-\u0fc5\u0fc7-\u0fcf\u109e-\u109f\u1360\u1390-\u1399\u1940\u19e0-\u19ff\u1b61-\u1b6a\u1b74-\u1b7c\u2044\u2052\u207a-\u207c\u208a-\u208c\u2100-\u2101\u2103-\u2106\u2108-\u2109\u2114\u2116-\u2118\u211e-\u2123\u2125\u2127\u2129\u212e\u213a-\u213b\u2140-\u2144\u214a-\u214d\u214f\u2190-\u2328\u232b-\u244a\u249c-\u24e9\u2500-\u2767\u2794-\u27c4\u27c7-\u27e5\u27f0-\u2982\u2999-\u29d7\u29dc-\u29fb\u29fe-\u2b54\u2ce5-\u2cea\u2e80-\u2ffb\u3004\u3012-\u3013\u3020\u3036-\u3037\u303e-\u303f\u3190-\u3191\u3196-\u319f\u31c0-\u31e3\u3200-\u321e\u322a-\u3250\u3260-\u327f\u328a-\u32b0\u32c0-\u33ff\u4dc0-\u4dff\ua490-\ua4c6\ua828-\ua82b\ufb29\ufdfd\ufe62\ufe64-\ufe66\uff0b\uff1c-\uff1e\uff5c\uff5e\uffe2\uffe4\uffe8-\uffee\ufffc-\ufffd]+'
@@ -126,7 +159,7 @@ class ScalaLexer(RegexLexer):
(r'(true|false|null)\b', Keyword.Constant),
(r'(import|package)(\s+)', bygroups(Keyword, Text), 'import'),
(r'(type)(\s+)', bygroups(Keyword, Text), 'type'),
- (r'""".*?"""', String),
+ (r'""".*?"""(?!")', String),
(r'"(\\\\|\\"|[^"])*"', String),
(r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char),
# (ur'(\.)(%s|%s|`[^`]+`)' % (idrest, op), bygroups(Operator,
@@ -198,9 +231,6 @@ class GosuLexer(RegexLexer):
flags = re.MULTILINE | re.DOTALL
- #: optional Comment or Whitespace
- _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
-
tokens = {
'root': [
# method names
@@ -299,9 +329,6 @@ class GroovyLexer(RegexLexer):
flags = re.MULTILINE | re.DOTALL
- #: optional Comment or Whitespace
- _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
-
tokens = {
'root': [
# method names
@@ -645,7 +672,7 @@ class ClojureLexer(RegexLexer):
(r"\\(.|[a-z]+)", String.Char),
# keywords
- (r':' + valid_name, String.Symbol),
+ (r'::?' + valid_name, String.Symbol),
# special operators
(r'~@|[`\'#^~&]', Operator),
@@ -691,9 +718,6 @@ class TeaLangLexer(RegexLexer):
flags = re.MULTILINE | re.DOTALL
- #: optional Comment or Whitespace
- _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
-
tokens = {
'root': [
# method names
@@ -826,20 +850,15 @@ class KotlinLexer(RegexLexer):
# for the range of allowed unicode characters in identifiers,
# see http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf
- def _escape(st):
- return st.replace(u'\\', ur'\\').replace(u'-', ur'\-').\
- replace(u'[', ur'\[').replace(u']', ur'\]')
-
levels = {
'none': '@?[_a-zA-Z][a-zA-Z0-9_]*',
'basic': ('@?[_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl + ']' +
'[' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Nl +
uni.Nd + uni.Pc + uni.Cf + uni.Mn + uni.Mc + ']*'),
'full': ('@?(?:_|[^' +
- _escape(uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl')) + '])'
- + '[^' + _escape(uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo',
- 'Nl', 'Nd', 'Pc', 'Cf', 'Mn',
- 'Mc')) + ']*'),
+ uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + '])'
+ + '[^' + uni.allexcept('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl',
+ 'Nd', 'Pc', 'Cf', 'Mn', 'Mc') + ']*'),
}
tokens = {}
@@ -907,3 +926,68 @@ class KotlinLexer(RegexLexer):
self._tokens = self._all_tokens[level]
RegexLexer.__init__(self, **options)
+
+
+class XtendLexer(RegexLexer):
+ """
+ For `Xtend <http://xtend-lang.org/>`_ source code.
+
+ *New in Pygments 1.6.*
+ """
+
+ name = 'Xtend'
+ aliases = ['xtend']
+ filenames = ['*.xtend']
+ mimetypes = ['text/x-xtend']
+
+ flags = re.MULTILINE | re.DOTALL
+
+ tokens = {
+ 'root': [
+ # method names
+ (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # return arguments
+ r'([a-zA-Z_$][a-zA-Z0-9_$]*)' # method name
+ r'(\s*)(\()', # signature start
+ bygroups(using(this), Name.Function, Text, Operator)),
+ (r'[^\S\n]+', Text),
+ (r'//.*?\n', Comment.Single),
+ (r'/\*.*?\*/', Comment.Multiline),
+ (r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator),
+ (r'(assert|break|case|catch|continue|default|do|else|finally|for|'
+ r'if|goto|instanceof|new|return|switch|this|throw|try|while|IF|'
+ r'ELSE|ELSEIF|ENDIF|FOR|ENDFOR|SEPARATOR|BEFORE|AFTER)\b',
+ Keyword),
+ (r'(def|abstract|const|enum|extends|final|implements|native|private|'
+ r'protected|public|static|strictfp|super|synchronized|throws|'
+ r'transient|volatile)\b', Keyword.Declaration),
+ (r'(boolean|byte|char|double|float|int|long|short|void)\b',
+ Keyword.Type),
+ (r'(package)(\s+)', bygroups(Keyword.Namespace, Text)),
+ (r'(true|false|null)\b', Keyword.Constant),
+ (r'(class|interface)(\s+)', bygroups(Keyword.Declaration, Text),
+ 'class'),
+ (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
+ (r"(''')", String, 'template'),
+ (ur"(\u00BB)", String, 'template'),
+ (r'"(\\\\|\\"|[^"])*"', String),
+ (r"'(\\\\|\\'|[^'])*'", String),
+ (r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Label),
+ (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name),
+ (r'[~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator),
+ (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
+ (r'0x[0-9a-f]+', Number.Hex),
+ (r'[0-9]+L?', Number.Integer),
+ (r'\n', Text)
+ ],
+ 'class': [
+ (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
+ ],
+ 'import': [
+ (r'[a-zA-Z0-9_.]+\*?', Name.Namespace, '#pop')
+ ],
+ 'template': [
+ (r"'''", String, '#pop'),
+ (ur"\u00AB", String, '#pop'),
+ (r'.', String)
+ ],
+ }