summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian R. Jackson <brian@jaxzin.com>2012-02-25 00:45:06 -0500
committerBrian R. Jackson <brian@jaxzin.com>2012-02-25 00:45:06 -0500
commita8791bedb48bb00c6775fb31533b72fc9668734e (patch)
treea8e62ca415879594db4be008d3c2e83360d81aa6
parent5558d3ba11cc7b2d1e16228ce3c5402b7d48072c (diff)
downloadpygments-a8791bedb48bb00c6775fb31533b72fc9668734e.tar.gz
Added support for Tea. http://teatrove.org
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/compiled.py2
-rw-r--r--pygments/lexers/jvm.py47
-rw-r--r--pygments/lexers/templates.py48
-rw-r--r--tests/examplefiles/example.tea34
5 files changed, 129 insertions, 3 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 6714ea4a..7c251351 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -225,6 +225,7 @@ LEXERS = {
'SystemVerilogLexer': ('pygments.lexers.hdl', 'systemverilog', ('sv',), ('*.sv', '*.svh'), ('text/x-systemverilog',)),
'TclLexer': ('pygments.lexers.agile', 'Tcl', ('tcl',), ('*.tcl',), ('text/x-tcl', 'text/x-script.tcl', 'application/x-tcl')),
'TcshLexer': ('pygments.lexers.shell', 'Tcsh', ('tcsh', 'csh'), ('*.tcsh', '*.csh'), ('application/x-csh',)),
+ 'TeaTemplateLexer': ('pygments.lexers.templates', 'Tea', ('tea',), ('*.tea',), ('text/x-tea',)),
'TexLexer': ('pygments.lexers.text', 'TeX', ('tex', 'latex'), ('*.tex', '*.aux', '*.toc'), ('text/x-tex', 'text/x-latex')),
'TextLexer': ('pygments.lexers.special', 'Text only', ('text',), ('*.txt',), ('text/plain',)),
'UrbiscriptLexer': ('pygments.lexers.other', 'UrbiScript', ('urbiscript',), ('*.u',), ('application/x-urbiscript',)),
diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py
index eeab8d57..171f55c9 100644
--- a/pygments/lexers/compiled.py
+++ b/pygments/lexers/compiled.py
@@ -21,7 +21,7 @@ from pygments.scanner import Scanner
# backwards compatibility
from pygments.lexers.functional import OcamlLexer
-from pygments.lexers.jvm import JavaLexer, ScalaLexer
+from pygments.lexers.jvm import JavaLexer, ScalaLexer, TeaLangLexer
__all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer',
'DylanLexer', 'ObjectiveCLexer', 'FortranLexer', 'GLShaderLexer',
diff --git a/pygments/lexers/jvm.py b/pygments/lexers/jvm.py
index 83b45613..fbd2b9ed 100644
--- a/pygments/lexers/jvm.py
+++ b/pygments/lexers/jvm.py
@@ -676,3 +676,50 @@ class ClojureLexer(RegexLexer):
(r'(\(|\))', Punctuation),
],
}
+
+class TeaLangLexer(RegexLexer):
+ """
+ For `Tea <http://teatrove.org/>`_ source code. Only used within a TeaTemplateLexer.
+ """
+
+ 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'(and|break|else|foreach|if|in|not|or|reverse)\b',
+ Keyword),
+ (r'(as|call|define)\b', Keyword.Declaration),
+ (r'(true|false|null)\b', Keyword.Constant),
+ (r'(template)(\s+)', bygroups(Keyword.Declaration, Text), 'template'),
+ (r'(import)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
+ (r'"(\\\\|\\"|[^"])*"', String),
+ (r'\'(\\\\|\\\'|[^\'])*\'', String),
+ (r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Operator, Name.Attribute)),
+ (r'[a-zA-Z_][a-zA-Z0-9_]*:', Name.Label),
+ (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name),
+ (r'(isa|[.]{3}|[.]{2}|[=#!<>+-/%&;,.\*\\\(\)\[\]\{\}])', 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)
+ ],
+ 'template': [
+ (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
+ ],
+ 'import': [
+ (r'[a-zA-Z0-9_.]+\*?', Name.Namespace, '#pop')
+ ],
+ }
+
diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py
index 717d689f..35564af1 100644
--- a/pygments/lexers/templates.py
+++ b/pygments/lexers/templates.py
@@ -14,7 +14,7 @@ import re
from pygments.lexers.web import \
PhpLexer, HtmlLexer, XmlLexer, JavascriptLexer, CssLexer
from pygments.lexers.agile import PythonLexer, PerlLexer
-from pygments.lexers.compiled import JavaLexer
+from pygments.lexers.compiled import JavaLexer, TeaLangLexer
from pygments.lexer import Lexer, DelegatingLexer, RegexLexer, bygroups, \
include, using, this
from pygments.token import Error, Punctuation, \
@@ -37,7 +37,7 @@ __all__ = ['HtmlPhpLexer', 'XmlPhpLexer', 'CssPhpLexer',
'EvoqueLexer', 'EvoqueHtmlLexer', 'EvoqueXmlLexer',
'ColdfusionLexer', 'ColdfusionHtmlLexer',
'VelocityLexer', 'VelocityHtmlLexer', 'VelocityXmlLexer',
- 'SspLexer']
+ 'SspLexer', 'TeaTemplateLexer']
class ErbLexer(Lexer):
@@ -1581,3 +1581,47 @@ class SspLexer(DelegatingLexer):
if '<%' in text and '%>' in text:
rv += 0.1
return rv
+
+class TeaTemplateRootLexer(RegexLexer):
+ """
+ Base for the `TeaTemplateLexer`. Yields `Token.Other` for area outside of
+ code blocks.
+
+ *New in Pygments 1.5.*
+ """
+
+ tokens = {
+ 'root': [
+ (r'<%\S?', Keyword, 'sec'),
+ (r'[^<]+', Other),
+ (r'<', Other),
+ ],
+ 'sec': [
+ (r'%>', Keyword, '#pop'),
+ # note: '\w\W' != '.' without DOTALL.
+ (r'[\w\W]+?(?=%>|\Z)', using(TeaLangLexer)),
+ ],
+ }
+
+
+class TeaTemplateLexer(DelegatingLexer):
+ """
+ Lexer for Tea Templates. http://teatrove.org
+
+ *New in Pygments 1.5.*
+ """
+ name = 'Tea'
+ aliases = ['tea']
+ filenames = ['*.tea']
+ mimetypes = ['text/x-tea']
+
+ def __init__(self, **options):
+ super(TeaTemplateLexer, self).__init__(XmlLexer, TeaTemplateRootLexer, **options)
+
+ def analyse_text(text):
+ rv = TeaLangLexer.analyse_text(text) - 0.01
+ if looks_like_xml(text):
+ rv += 0.4
+ if '<%' in text and '%>' in text:
+ rv += 0.1
+ return rv
diff --git a/tests/examplefiles/example.tea b/tests/examplefiles/example.tea
new file mode 100644
index 00000000..6859e34d
--- /dev/null
+++ b/tests/examplefiles/example.tea
@@ -0,0 +1,34 @@
+<% template example() {...}
+a = 123
+b = "test";
+c = 4.5
+d = call other()
+f = other2()
+
+define g as String
+
+h = true
+i = false
+j = null
+%>
+<html>
+<head>
+<title>Example<title>
+<body>
+<a href="http://example.com">Test link</a>
+<% // Second block
+if(a == 123 and b == "test") {
+ 'yes'
+} else {
+ 'no'
+}
+
+foreach(i in 1..10) {
+ i & ","
+}
+
+foreach(i in #(1,2,3) reverse {
+ i & ";"
+}
+
+%> \ No newline at end of file