Commits

svenefftinge committed f6a8e1d

Added lexer for Xtend http://xtend-lang.org

  • Participants
  • Parent commits 96e8b9c

Comments (0)

Files changed (3)

pygments/lexers/_mapping.py

     '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',)),
 }
 

pygments/lexers/jvm.py

             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)
+        ],
+    }

tests/examplefiles/example.xtend

+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
+	}
+}