diff options
author | Hiram Chirino <hiram@hiramchirino.com> | 2010-09-21 09:56:54 -0400 |
---|---|---|
committer | Hiram Chirino <hiram@hiramchirino.com> | 2010-09-21 09:56:54 -0400 |
commit | 00d50b8807011979ebc8c2287f7118ff3a645732 (patch) | |
tree | 836e3a729d33d75826e506e3670b1779c4541c77 | |
parent | a94b9443b115ddfabcdfc25b50bf7c4f035109a9 (diff) | |
download | pygments-00d50b8807011979ebc8c2287f7118ff3a645732.tar.gz |
added a scaml and jade lexer
-rw-r--r-- | pygments/lexers/_mapping.py | 2 | ||||
-rw-r--r-- | pygments/lexers/web.py | 219 |
2 files changed, 220 insertions, 1 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 7e72c713..b062317d 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -100,6 +100,7 @@ LEXERS = { 'IoLexer': ('pygments.lexers.agile', 'Io', ('io',), ('*.io',), ('text/x-iosrc',)), 'IokeLexer': ('pygments.lexers.agile', 'Ioke', ('ioke', 'ik'), ('*.ik',), ('text/x-iokesrc',)), 'IrcLogsLexer': ('pygments.lexers.text', 'IRC logs', ('irc',), ('*.weechatlog',), ('text/x-irclog',)), + 'JadeLexer': ('pygments.lexers.web', 'Jade', ('jade', 'JADE'), ('*.jade',), ('text/x-scaml',)), 'JavaLexer': ('pygments.lexers.compiled', 'Java', ('java',), ('*.java',), ('text/x-java',)), 'JavascriptDjangoLexer': ('pygments.lexers.templates', 'JavaScript+Django/Jinja', ('js+django', 'javascript+django', 'js+jinja', 'javascript+jinja'), (), ('application/x-javascript+django', 'application/x-javascript+jinja', 'text/x-javascript+django', 'text/x-javascript+jinja', 'text/javascript+django', 'text/javascript+jinja')), 'JavascriptErbLexer': ('pygments.lexers.templates', 'JavaScript+Ruby', ('js+erb', 'javascript+erb', 'js+ruby', 'javascript+ruby'), (), ('application/x-javascript+ruby', 'text/x-javascript+ruby', 'text/javascript+ruby')), @@ -175,6 +176,7 @@ LEXERS = { 'SLexer': ('pygments.lexers.math', 'S', ('splus', 's', 'r'), ('*.S', '*.R'), ('text/S-plus', 'text/S', 'text/R')), 'SassLexer': ('pygments.lexers.web', 'Sass', ('sass', 'SASS'), ('*.sass',), ('text/x-sass',)), 'ScalaLexer': ('pygments.lexers.compiled', 'Scala', ('scala',), ('*.scala',), ('text/x-scala',)), + 'ScamlLexer': ('pygments.lexers.web', 'Scaml', ('scaml', 'SCAML'), ('*.scaml',), ('text/x-scaml',)), 'SchemeLexer': ('pygments.lexers.functional', 'Scheme', ('scheme', 'scm'), ('*.scm',), ('text/x-scheme', 'application/x-scheme')), 'ScssLexer': ('pygments.lexers.web', 'SCSS', ('scss',), ('*.scss',), ('text/x-scss',)), 'SmalltalkLexer': ('pygments.lexers.other', 'Smalltalk', ('smalltalk', 'squeak'), ('*.st',), ('text/x-smalltalk',)), diff --git a/pygments/lexers/web.py b/pygments/lexers/web.py index 52e442fc..e56fb433 100644 --- a/pygments/lexers/web.py +++ b/pygments/lexers/web.py @@ -19,12 +19,13 @@ from pygments.token import \ from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, \ html_doctype_matches from pygments.lexers.agile import RubyLexer +from pygments.lexers.compiled import ScalaLexer __all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'CssLexer', 'PhpLexer', 'ActionScriptLexer', 'XsltLexer', 'ActionScript3Lexer', 'MxmlLexer', 'HaxeLexer', 'HamlLexer', 'SassLexer', 'ScssLexer', - 'ObjectiveJLexer', 'CoffeeScriptLexer', 'JbstLexer'] + 'ObjectiveJLexer', 'CoffeeScriptLexer', 'JbstLexer', 'ScamlLexer', 'JadeLexer'] class JavascriptLexer(RegexLexer): @@ -1698,3 +1699,219 @@ class JbstLexer(RegexLexer): (r'.+', using(HtmlLexer)), ], } + +class ScamlLexer(ExtendedRegexLexer): + """ + For Scaml markup. + Scaml is Haml for Scala. + See: http://scalate.fusesource.org/documentation/scaml-reference.html#features + """ + + name = 'Scaml' + aliases = ['scaml', 'SCAML'] + filenames = ['*.scaml'] + mimetypes = ['text/x-scaml'] + + flags = re.IGNORECASE + # Scaml does not yet support the " |\n" notation to + # wrap long lines. Once it does, use the custom faux + # dot instead. + # _dot = r'(?: \|\n(?=.* \|)|.)' + _dot = r'.' + + tokens = { + 'root': [ + (r'[ \t]*\n', Text), + (r'[ \t]*', _indentation), + ], + + 'css': [ + (r'\.[a-z0-9_:-]+', Name.Class, 'tag'), + (r'\#[a-z0-9_:-]+', Name.Function, 'tag'), + ], + + 'eval-or-plain': [ + (r'[&!]?==', Punctuation, 'plain'), + (r'([&!]?[=~])(' + _dot + '*\n)', + bygroups(Punctuation, using(ScalaLexer)), + 'root'), + (r'', Text, 'plain'), + ], + + 'content': [ + include('css'), + (r'%[a-z0-9_:-]+', Name.Tag, 'tag'), + (r'!!!' + _dot + '*\n', Name.Namespace, '#pop'), + (r'(/)(\[' + _dot + '*?\])(' + _dot + '*\n)', + bygroups(Comment, Comment.Special, Comment), + '#pop'), + (r'/' + _dot + '*\n', _starts_block(Comment, 'html-comment-block'), + '#pop'), + (r'-#' + _dot + '*\n', _starts_block(Comment.Preproc, + 'scaml-comment-block'), '#pop'), + (r'(-@\s*)(import)?(' + _dot + '*\n)', + bygroups(Punctuation, Keyword, using(ScalaLexer)), + '#pop'), + (r'(-)(' + _dot + '*\n)', + bygroups(Punctuation, using(ScalaLexer)), + '#pop'), + (r':' + _dot + '*\n', _starts_block(Name.Decorator, 'filter-block'), + '#pop'), + include('eval-or-plain'), + ], + + 'tag': [ + include('css'), + (r'\{(,\n|' + _dot + ')*?\}', using(ScalaLexer)), + (r'\[' + _dot + '*?\]', using(ScalaLexer)), + (r'\(', Text, 'html-attributes'), + (r'/[ \t]*\n', Punctuation, '#pop:2'), + (r'[<>]{1,2}(?=[ \t=])', Punctuation), + include('eval-or-plain'), + ], + + 'plain': [ + (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), + (r'(#\{)(' + _dot + '*?)(\})', + bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), + (r'\n', Text, 'root'), + ], + + 'html-attributes': [ + (r'\s+', Text), + (r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'), + (r'[a-z0-9_:-]+', Name.Attribute), + (r'\)', Text, '#pop'), + ], + + 'html-attribute-value': [ + (r'[ \t]+', Text), + (r'[a-z0-9_]+', Name.Variable, '#pop'), + (r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'), + (r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'), + (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'), + (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'), + ], + + 'html-comment-block': [ + (_dot + '+', Comment), + (r'\n', Text, 'root'), + ], + + 'scaml-comment-block': [ + (_dot + '+', Comment.Preproc), + (r'\n', Text, 'root'), + ], + + 'filter-block': [ + (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator), + (r'(#\{)(' + _dot + '*?)(\})', + bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), + (r'\n', Text, 'root'), + ], + } + +class JadeLexer(ExtendedRegexLexer): + """ + For Jade markup. + Jade is a variant of Scaml + See: http://scalate.fusesource.org/documentation/scaml-reference.html + """ + + name = 'Jade' + aliases = ['jade', 'JADE'] + filenames = ['*.jade'] + mimetypes = ['text/x-jade'] + + flags = re.IGNORECASE + _dot = r'.' + + tokens = { + 'root': [ + (r'[ \t]*\n', Text), + (r'[ \t]*', _indentation), + ], + + 'css': [ + (r'\.[a-z0-9_:-]+', Name.Class, 'tag'), + (r'\#[a-z0-9_:-]+', Name.Function, 'tag'), + ], + + 'eval-or-plain': [ + (r'[&!]?==', Punctuation, 'plain'), + (r'([&!]?[=~])(' + _dot + '*\n)', bygroups(Punctuation, using(ScalaLexer)), 'root'), + (r'', Text, 'plain'), + ], + + 'content': [ + include('css'), + (r'!!!' + _dot + '*\n', Name.Namespace, '#pop'), + (r'(/)(\[' + _dot + '*?\])(' + _dot + '*\n)', + bygroups(Comment, Comment.Special, Comment), + '#pop'), + (r'/' + _dot + '*\n', _starts_block(Comment, 'html-comment-block'), + '#pop'), + (r'-#' + _dot + '*\n', _starts_block(Comment.Preproc, + 'scaml-comment-block'), '#pop'), + (r'(-@\s*)(import)?(' + _dot + '*\n)', + bygroups(Punctuation, Keyword, using(ScalaLexer)), + '#pop'), + (r'(-)(' + _dot + '*\n)', + bygroups(Punctuation, using(ScalaLexer)), + '#pop'), + (r':' + _dot + '*\n', _starts_block(Name.Decorator, 'filter-block'), + '#pop'), + (r'[a-z0-9_:-]+', Name.Tag, 'tag'), + (r'|', Text, 'eval-or-plain'), + ], + + 'tag': [ + include('css'), + (r'\{(,\n|' + _dot + ')*?\}', using(ScalaLexer)), + (r'\[' + _dot + '*?\]', using(ScalaLexer)), + (r'\(', Text, 'html-attributes'), + (r'/[ \t]*\n', Punctuation, '#pop:2'), + (r'[<>]{1,2}(?=[ \t=])', Punctuation), + include('eval-or-plain'), + ], + + 'plain': [ + (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text), + (r'(#\{)(' + _dot + '*?)(\})', + bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), + (r'\n', Text, 'root'), + ], + + 'html-attributes': [ + (r'\s+', Text), + (r'[a-z0-9_:-]+[ \t]*=', Name.Attribute, 'html-attribute-value'), + (r'[a-z0-9_:-]+', Name.Attribute), + (r'\)', Text, '#pop'), + ], + + 'html-attribute-value': [ + (r'[ \t]+', Text), + (r'[a-z0-9_]+', Name.Variable, '#pop'), + (r'@[a-z0-9_]+', Name.Variable.Instance, '#pop'), + (r'\$[a-z0-9_]+', Name.Variable.Global, '#pop'), + (r"'(\\\\|\\'|[^'\n])*'", String, '#pop'), + (r'"(\\\\|\\"|[^"\n])*"', String, '#pop'), + ], + + 'html-comment-block': [ + (_dot + '+', Comment), + (r'\n', Text, 'root'), + ], + + 'scaml-comment-block': [ + (_dot + '+', Comment.Preproc), + (r'\n', Text, 'root'), + ], + + 'filter-block': [ + (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator), + (r'(#\{)(' + _dot + '*?)(\})', + bygroups(String.Interpol, using(ScalaLexer), String.Interpol)), + (r'\n', Text, 'root'), + ], + } |