diff options
author | Sven Efftinge <sven@efftinge.de> | 2012-04-07 09:13:25 +0200 |
---|---|---|
committer | Sven Efftinge <sven@efftinge.de> | 2012-04-07 09:13:25 +0200 |
commit | 99e64fc2fdce7497ea4e5f6a63cd84effbfa26e2 (patch) | |
tree | 04fab5282312d9358a5bc1112ba0133a3b61b1ca | |
parent | b70d989a1b9c06b62e816a65675402f8c44ab363 (diff) | |
download | pygments-99e64fc2fdce7497ea4e5f6a63cd84effbfa26e2.tar.gz |
Added lexer for Xtend http://xtend-lang.org
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/jvm.py | 66 | ||||
-rw-r--r-- | tests/examplefiles/example.xtend | 34 |
3 files changed, 101 insertions, 0 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 8bcc1744..8002ecb7 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -250,6 +250,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 b56d4582..d98207d6 100644 --- a/pygments/lexers/jvm.py +++ b/pygments/lexers/jvm.py @@ -845,3 +845,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 |