diff options
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/jvm.py | 69 | ||||
-rw-r--r-- | tests/examplefiles/example.xtend | 34 |
3 files changed, 103 insertions, 1 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 952aa643..fb89f212 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -262,6 +262,7 @@ LEXERS = { 'XmlPhpLexer': ('pygments.lexers.templates', 'XML+PHP', ('xml+php',), (), ('application/xml+php',)), 'XmlSmartyLexer': ('pygments.lexers.templates', 'XML+Smarty', ('xml+smarty',), (), ('application/xml+smarty',)), 'XsltLexer': ('pygments.lexers.web', 'XSLT', ('xslt',), ('*.xsl', '*.xslt'), ('application/xsl+xml', 'application/xslt+xml')), + 'XtendLexer': ('pygments.lexers.jvm', 'Xtend', ('xtend',), ('*.xtend',), ('text/x-xtend',)), 'YamlLexer': ('pygments.lexers.text', 'YAML', ('yaml',), ('*.yaml', '*.yml'), ('text/x-yaml',)), } diff --git a/pygments/lexers/jvm.py b/pygments/lexers/jvm.py index 64338e46..a5c09e41 100644 --- a/pygments/lexers/jvm.py +++ b/pygments/lexers/jvm.py @@ -20,7 +20,8 @@ from pygments import unistring as uni __all__ = ['JavaLexer', 'ScalaLexer', 'GosuLexer', 'GosuTemplateLexer', - 'GroovyLexer', 'IokeLexer', 'ClojureLexer', 'KotlinLexer'] + 'GroovyLexer', 'IokeLexer', 'ClojureLexer', 'KotlinLexer', + 'XtendLexer'] class JavaLexer(RegexLexer): @@ -845,3 +846,69 @@ 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.5.* + """ + + name = 'Xtend' + aliases = ['xtend'] + filenames = ['*.xtend'] + mimetypes = ['text/x-xtend'] + + 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 + 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) + ], + } diff --git a/tests/examplefiles/example.xtend b/tests/examplefiles/example.xtend new file mode 100644 index 00000000..f6a51f7a --- /dev/null +++ b/tests/examplefiles/example.xtend @@ -0,0 +1,34 @@ +package beer + +import static extension beer.BottleSupport.* +import org.junit.Test + +class BottleSong { + + @Test + def void singIt() { + println(singTheSong(99)) + } + + def singTheSong(int all) ''' + «FOR i : all .. 1» + «i.Bottles» of beer on the wall, «i.bottles» of beer. + Take one down and pass it around, «(i - 1).bottles» of beer on the wall. + + «ENDFOR» + No more bottles of beer on the wall, no more bottles of beer. + Go to the store and buy some more, «all.bottles» of beer on the wall. + ''' + + def private java.lang.String bottles(int i) { + switch i { + case 0 : 'no more bottles' + case 1 : 'one bottle' + default : '''«i» bottles''' + }.toString + } + + def String Bottles(int i) { + bottles(i).toFirstUpper + } +}
\ No newline at end of file |