diff options
Diffstat (limited to 'pygments/lexers/web.py')
-rw-r--r-- | pygments/lexers/web.py | 555 |
1 files changed, 460 insertions, 95 deletions
diff --git a/pygments/lexers/web.py b/pygments/lexers/web.py index 142fef57..f388f611 100644 --- a/pygments/lexers/web.py +++ b/pygments/lexers/web.py @@ -5,7 +5,7 @@ Lexers for web-related languages and markup. - :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ @@ -13,11 +13,11 @@ import re import copy from pygments.lexer import RegexLexer, ExtendedRegexLexer, bygroups, using, \ - include, this + include, this from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ - Number, Other, Punctuation, Literal + Number, Other, Punctuation, Literal from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, \ - html_doctype_matches, unirange + html_doctype_matches, unirange, iteritems from pygments.lexers.agile import RubyLexer from pygments.lexers.compiled import ScalaLexer @@ -27,7 +27,8 @@ __all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'JsonLexer', 'CssLexer', 'MxmlLexer', 'HaxeLexer', 'HamlLexer', 'SassLexer', 'ScssLexer', 'ObjectiveJLexer', 'CoffeeScriptLexer', 'LiveScriptLexer', 'DuelLexer', 'ScamlLexer', 'JadeLexer', 'XQueryLexer', - 'DtdLexer', 'DartLexer', 'LassoLexer', 'QmlLexer', 'TypeScriptLexer'] + 'DtdLexer', 'DartLexer', 'LassoLexer', 'QmlLexer', 'TypeScriptLexer', + 'KalLexer', 'CirruLexer', 'MaskLexer', 'ZephirLexer'] class JavascriptLexer(RegexLexer): @@ -94,7 +95,7 @@ class JsonLexer(RegexLexer): """ For JSON data structures. - *New in Pygments 1.5.* + .. versionadded:: 1.5 """ name = 'JSON' @@ -177,7 +178,7 @@ class ActionScriptLexer(RegexLexer): """ For ActionScript source code. - *New in Pygments 0.9.* + .. versionadded:: 0.9 """ name = 'ActionScript' @@ -261,7 +262,7 @@ class ActionScript3Lexer(RegexLexer): """ For ActionScript 3 source code. - *New in Pygments 0.11.* + .. versionadded:: 0.11 """ name = 'ActionScript 3' @@ -363,7 +364,7 @@ class CssLexer(RegexLexer): (r'\#[a-zA-Z0-9_-]+', Name.Function), (r'@[a-zA-Z0-9_-]+', Keyword, 'atrule'), (r'[a-zA-Z0-9_-]+', Name.Tag), - (r'[~\^\*!%&\[\]\(\)<>\|+=@:;,./?-]', Operator), + (r'[~\^\*!%&$\[\]\(\)<>\|+=@:;,./?-]', Operator), (r'"(\\\\|\\"|[^"])*"', String.Double), (r"'(\\\\|\\'|[^'])*'", String.Single) ], @@ -398,19 +399,19 @@ class CssLexer(RegexLexer): r'list-style-type|list-style-image|list-style-position|' r'list-style|margin-bottom|margin-left|margin-right|' r'margin-top|margin|marker-offset|marks|max-height|max-width|' - r'min-height|min-width|opacity|orphans|outline|outline-color|' - r'outline-style|outline-width|overflow(?:-x|-y)?|padding-bottom|' + r'min-height|min-width|opacity|orphans|outline-color|' + r'outline-style|outline-width|outline|overflow(?:-x|-y)?|padding-bottom|' r'padding-left|padding-right|padding-top|padding|page|' r'page-break-after|page-break-before|page-break-inside|' - r'pause-after|pause-before|pause|pitch|pitch-range|' + r'pause-after|pause-before|pause|pitch-range|pitch|' r'play-during|position|quotes|richness|right|size|' r'speak-header|speak-numeral|speak-punctuation|speak|' r'speech-rate|stress|table-layout|text-align|text-decoration|' r'text-indent|text-shadow|text-transform|top|unicode-bidi|' r'vertical-align|visibility|voice-family|volume|white-space|' - r'widows|width|word-spacing|z-index|bottom|left|' + r'widows|width|word-spacing|z-index|bottom|' r'above|absolute|always|armenian|aural|auto|avoid|baseline|' - r'behind|below|bidi-override|blink|block|bold|bolder|both|' + r'behind|below|bidi-override|blink|block|bolder|bold|both|' r'capitalize|center-left|center-right|center|circle|' r'cjk-ideographic|close-quote|collapse|condensed|continuous|' r'crop|crosshair|cross|cursive|dashed|decimal-leading-zero|' @@ -420,7 +421,7 @@ class CssLexer(RegexLexer): r'hidden|hide|higher|high|hiragana-iroha|hiragana|icon|' r'inherit|inline-table|inline|inset|inside|invert|italic|' r'justify|katakana-iroha|katakana|landscape|larger|large|' - r'left-side|leftwards|level|lighter|line-through|list-item|' + r'left-side|leftwards|left|level|lighter|line-through|list-item|' r'loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|' r'lower|low|medium|message-box|middle|mix|monospace|' r'n-resize|narrower|ne-resize|no-close-quote|no-open-quote|' @@ -429,11 +430,11 @@ class CssLexer(RegexLexer): r'relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|' r'rightwards|s-resize|sans-serif|scroll|se-resize|' r'semi-condensed|semi-expanded|separate|serif|show|silent|' - r'slow|slower|small-caps|small-caption|smaller|soft|solid|' + r'slower|slow|small-caps|small-caption|smaller|soft|solid|' r'spell-out|square|static|status-bar|super|sw-resize|' r'table-caption|table-cell|table-column|table-column-group|' r'table-footer-group|table-header-group|table-row|' - r'table-row-group|text|text-bottom|text-top|thick|thin|' + r'table-row-group|text-bottom|text-top|text|thick|thin|' r'transparent|ultra-condensed|ultra-expanded|underline|' r'upper-alpha|upper-latin|upper-roman|uppercase|url|' r'visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|' @@ -466,7 +467,9 @@ class CssLexer(RegexLexer): (r'\!important', Comment.Preproc), (r'/\*(?:.|\n)*?\*/', Comment), (r'\#[a-zA-Z0-9]{1,6}', Number), - (r'[\.-]?[0-9]*[\.]?[0-9]+(em|px|\%|pt|pc|in|mm|cm|ex|s)\b', Number), + (r'[\.-]?[0-9]*[\.]?[0-9]+(em|px|pt|pc|in|mm|cm|ex|s)\b', Number), + # Separate regex for percentages, as can't do word boundaries with % + (r'[\.-]?[0-9]*[\.]?[0-9]+%', Number), (r'-?[0-9]+', Number), (r'[~\^\*!%&<>\|+=@:,./?-]+', Operator), (r'[\[\]();]+', Punctuation), @@ -481,7 +484,7 @@ class ObjectiveJLexer(RegexLexer): """ For Objective-J source code with preprocessor directives. - *New in Pygments 1.3.* + .. versionadded:: 1.3 """ name = 'Objective-J' @@ -796,6 +799,13 @@ class PhpLexer(RegexLexer): filenames = ['*.php', '*.php[345]', '*.inc'] mimetypes = ['text/x-php'] + # Note that a backslash is included in the following two patterns + # PHP uses a backslash as a namespace separator + _ident_char = r'[\\_a-zA-Z0-9]|[^\x00-\x7f]' + _ident_begin = r'(?:[\\_a-zA-Z]|[^\x00-\x7f])' + _ident_end = r'(?:' + _ident_char + ')*' + _ident_inner = _ident_begin + _ident_end + flags = re.IGNORECASE | re.DOTALL | re.MULTILINE tokens = { 'root': [ @@ -805,7 +815,7 @@ class PhpLexer(RegexLexer): ], 'php': [ (r'\?>', Comment.Preproc, '#pop'), - (r'<<<(\'?)([a-zA-Z_][a-zA-Z0-9_]*)\1\n.*?\n\2\;?\n', String), + (r'<<<(\'?)(' + _ident_inner + ')\1\n.*?\n\2\;?\n', String), (r'\s+', Text), (r'#.*?\n', Comment.Single), (r'//.*?\n', Comment.Single), @@ -814,7 +824,7 @@ class PhpLexer(RegexLexer): (r'/\*\*/', Comment.Multiline), (r'/\*\*.*?\*/', String.Doc), (r'/\*.*?\*/', Comment.Multiline), - (r'(->|::)(\s*)([a-zA-Z_][a-zA-Z0-9_]*)', + (r'(->|::)(\s*)(' + _ident_inner + ')', bygroups(Operator, Text, Name.Attribute)), (r'[~!%^&*+=|:.<>/?@-]+', Operator), (r'[\[\]{}();,]+', Punctuation), @@ -822,7 +832,7 @@ class PhpLexer(RegexLexer): (r'(function)(\s*)(?=\()', bygroups(Keyword, Text)), (r'(function)(\s+)(&?)(\s*)', bygroups(Keyword, Text, Operator, Text), 'functionname'), - (r'(const)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)', + (r'(const)(\s+)(' + _ident_inner + ')', bygroups(Keyword, Text, Name.Constant)), (r'(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|' r'eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|' @@ -833,31 +843,33 @@ class PhpLexer(RegexLexer): r'endif|list|__LINE__|endswitch|new|__sleep|endwhile|not|' r'array|__wakeup|E_ALL|NULL|final|php_user_filter|interface|' r'implements|public|private|protected|abstract|clone|try|' - r'catch|throw|this|use|namespace|trait)\b', Keyword), + r'catch|throw|this|use|namespace|trait|yield|' + r'finally)\b', Keyword), (r'(true|false|null)\b', Keyword.Constant), - (r'\$\{\$+[a-zA-Z_][a-zA-Z0-9_]*\}', Name.Variable), - (r'\$+[a-zA-Z_][a-zA-Z0-9_]*', Name.Variable), - (r'[\\a-zA-Z_][\\a-zA-Z0-9_]*', Name.Other), + (r'\$\{\$+' + _ident_inner + '\}', Name.Variable), + (r'\$+' + _ident_inner, Name.Variable), + (_ident_inner, Name.Other), (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float), (r'\d+[eE][+-]?[0-9]+', Number.Float), (r'0[0-7]+', Number.Oct), (r'0[xX][a-fA-F0-9]+', Number.Hex), (r'\d+', Number.Integer), + (r'0b[01]+', Number.Binary), (r"'([^'\\]*(?:\\.[^'\\]*)*)'", String.Single), (r'`([^`\\]*(?:\\.[^`\\]*)*)`', String.Backtick), (r'"', String.Double, 'string'), ], 'classname': [ - (r'[a-zA-Z_][\\a-zA-Z0-9_]*', Name.Class, '#pop') + (_ident_inner, Name.Class, '#pop') ], 'functionname': [ - (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop') + (_ident_inner, Name.Function, '#pop') ], 'string': [ (r'"', String.Double, '#pop'), (r'[^{$"\\]+', String.Double), (r'\\([nrt\"$\\]|[0-7]{1,3}|x[0-9A-Fa-f]{1,2})', String.Escape), - (r'\$[a-zA-Z_][a-zA-Z0-9_]*(\[\S+\]|->[a-zA-Z_][a-zA-Z0-9_]*)?', + (r'\$' + _ident_inner + '(\[\S+?\]|->' + _ident_inner + ')?', String.Interpol), (r'(\{\$\{)(.*?)(\}\})', bygroups(String.Interpol, using(this, _startinline=True), @@ -886,7 +898,7 @@ class PhpLexer(RegexLexer): self._functions = set() if self.funcnamehighlighting: from pygments.lexers._phpbuiltins import MODULES - for key, value in MODULES.iteritems(): + for key, value in iteritems(MODULES): if key not in self.disabledmodules: self._functions.update(value) RegexLexer.__init__(self, **options) @@ -916,7 +928,7 @@ class DtdLexer(RegexLexer): """ A lexer for DTDs (Document Type Definitions). - *New in Pygments 1.5.* + .. versionadded:: 1.5 """ flags = re.MULTILINE | re.DOTALL @@ -1051,7 +1063,7 @@ class XsltLexer(XmlLexer): ''' A lexer for XSLT. - *New in Pygments 0.10.* + .. versionadded:: 0.10 ''' name = 'XSLT' @@ -1089,7 +1101,7 @@ class MxmlLexer(RegexLexer): For MXML markup. Nested AS3 in <script> tags is highlighted by the appropriate lexer. - *New in Pygments 1.1.* + .. versionadded:: 1.1 """ flags = re.MULTILINE | re.DOTALL name = 'MXML' @@ -1132,11 +1144,11 @@ class HaxeLexer(ExtendedRegexLexer): """ For Haxe source code (http://haxe.org/). - *New in Pygments 1.3.* + .. versionadded:: 1.3 """ name = 'Haxe' - aliases = ['hx', 'Haxe', 'haxe', 'haXe', 'hxsl'] + aliases = ['hx', 'haxe', 'hxsl'] filenames = ['*.hx', '*.hxsl'] mimetypes = ['text/haxe', 'text/x-haxe', 'text/x-hx'] @@ -2002,11 +2014,11 @@ class HamlLexer(ExtendedRegexLexer): """ For Haml markup. - *New in Pygments 1.3.* + .. versionadded:: 1.3 """ name = 'Haml' - aliases = ['haml', 'HAML'] + aliases = ['haml'] filenames = ['*.haml'] mimetypes = ['text/x-haml'] @@ -2279,11 +2291,11 @@ class SassLexer(ExtendedRegexLexer): """ For Sass stylesheets. - *New in Pygments 1.3.* + .. versionadded:: 1.3 """ name = 'Sass' - aliases = ['sass', 'SASS'] + aliases = ['sass'] filenames = ['*.sass'] mimetypes = ['text/x-sass'] @@ -2350,7 +2362,7 @@ class SassLexer(ExtendedRegexLexer): (r"\*/", Comment, '#pop'), ], } - for group, common in common_sass_tokens.iteritems(): + for group, common in iteritems(common_sass_tokens): tokens[group] = copy.copy(common) tokens['value'].append((r'\n', Text, 'root')) tokens['selector'].append((r'\n', Text, 'root')) @@ -2397,7 +2409,7 @@ class ScssLexer(RegexLexer): (r"\*/", Comment, '#pop'), ], } - for group, common in common_sass_tokens.iteritems(): + for group, common in iteritems(common_sass_tokens): tokens[group] = copy.copy(common) tokens['value'].extend([(r'\n', Text), (r'[;{}]', Punctuation, 'root')]) tokens['selector'].extend([(r'\n', Text), (r'[;{}]', Punctuation, 'root')]) @@ -2409,7 +2421,7 @@ class CoffeeScriptLexer(RegexLexer): .. _CoffeeScript: http://coffeescript.org - *New in Pygments 1.3.* + .. versionadded:: 1.3 """ name = 'CoffeeScript' @@ -2442,10 +2454,10 @@ class CoffeeScriptLexer(RegexLexer): #(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), include('commentsandwhitespace'), (r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|' - r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|' - r'=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?', + r'\|\||\\(?=\n)|' + r'(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?', Operator, 'slashstartsregex'), - (r'(?:\([^()]+\))?\s*[=-]>', Name.Function), + (r'(?:\([^()]*\))?\s*[=-]>', Name.Function), (r'[{(\[;,]', Punctuation, 'slashstartsregex'), (r'[})\].]', Punctuation), (r'(?<![\.\$])(for|own|in|of|while|until|' @@ -2509,6 +2521,123 @@ class CoffeeScriptLexer(RegexLexer): } +class KalLexer(RegexLexer): + """ + For `Kal`_ source code. + + .. _Kal: http://rzimmerman.github.io/kal + + + .. versionadded:: 2.0 + """ + + name = 'Kal' + aliases = ['kal'] + filenames = ['*.kal'] + mimetypes = ['text/kal', 'application/kal'] + + flags = re.DOTALL + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Text), + (r'###[^#].*?###', Comment.Multiline), + (r'#(?!##[^#]).*?\n', Comment.Single), + ], + 'functiondef': [ + (r'[$a-zA-Z_][a-zA-Z0-9_\$]*\s*', Name.Function, '#pop'), + include('commentsandwhitespace'), + ], + 'classdef': [ + (r'\binherits\s+from\b', Keyword), + (r'[$a-zA-Z_][a-zA-Z0-9_\$]*\s*\n', Name.Class, '#pop'), + (r'[$a-zA-Z_][a-zA-Z0-9_\$]*\s*', Name.Class), + include('commentsandwhitespace'), + ], + 'listcomprehension': [ + (r'\]', Punctuation, '#pop'), + (r'\b(property|value)\b', Keyword), + include('root'), + ], + 'waitfor': [ + (r'\n', Punctuation, '#pop'), + (r'\bfrom\b', Keyword), + include('root'), + ], + 'root': [ + include('commentsandwhitespace'), + (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' + r'([gim]+\b|\B)', String.Regex), + (r'\?|:|_(?=\n)|==?|!=|-(?!>)|[<>+*/-]=?', + Operator), + (r'\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|' + r'\bbut\b|\bbitwise\b|\bmod\b|\^|\bxor\b|\bexists\b|\bdoesnt\s+exist\b', + Operator.Word), + (r'(?:\([^()]+\))?\s*>', Name.Function), + (r'[{(]', Punctuation), + (r'\[', Punctuation, 'listcomprehension'), + (r'[})\]\.\,]', Punctuation), + (r'\b(function|method|task)\b', Keyword.Declaration, 'functiondef'), + (r'\bclass\b', Keyword.Declaration, 'classdef'), + (r'\b(safe\s+)?wait\s+for\b', Keyword, 'waitfor'), + (r'\b(me|this)(\.[$a-zA-Z_][a-zA-Z0-9_\.\$]*)?\b', Name.Variable.Instance), + (r'(?<![\.\$])(for(\s+(parallel|series))?|in|of|while|until|' + r'break|return|continue|' + r'when|if|unless|else|otherwise|except\s+when|' + r'throw|raise|fail\s+with|try|catch|finally|new|delete|' + r'typeof|instanceof|super|run\s+in\s+parallel|' + r'inherits\s+from)\b', Keyword), + (r'(?<![\.\$])(true|false|yes|no|on|off|null|nothing|none|' + r'NaN|Infinity|undefined)\b', + Keyword.Constant), + (r'(Array|Boolean|Date|Error|Function|Math|netscape|' + r'Number|Object|Packages|RegExp|String|sun|decodeURI|' + r'decodeURIComponent|encodeURI|encodeURIComponent|' + r'eval|isFinite|isNaN|parseFloat|parseInt|document|window|' + r'print)\b', + Name.Builtin), + (r'[$a-zA-Z_][a-zA-Z0-9_\.\$]*\s*(:|[\+\-\*\/]?\=)?\b', Name.Variable), + (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), + (r'0x[0-9a-fA-F]+', Number.Hex), + (r'[0-9]+', Number.Integer), + ('"""', String, 'tdqs'), + ("'''", String, 'tsqs'), + ('"', String, 'dqs'), + ("'", String, 'sqs'), + ], + 'strings': [ + (r'[^#\\\'"]+', String), + # note that all kal strings are multi-line. + # hashmarks, quotes and backslashes must be parsed one at a time + ], + 'interpoling_string' : [ + (r'}', String.Interpol, "#pop"), + include('root') + ], + 'dqs': [ + (r'"', String, '#pop'), + (r'\\.|\'', String), # double-quoted string don't need ' escapes + (r'#{', String.Interpol, "interpoling_string"), + include('strings') + ], + 'sqs': [ + (r"'", String, '#pop'), + (r'#|\\.|"', String), # single quoted strings don't need " escapses + include('strings') + ], + 'tdqs': [ + (r'"""', String, '#pop'), + (r'\\.|\'|"', String), # no need to escape quotes in triple-string + (r'#{', String.Interpol, "interpoling_string"), + include('strings'), + ], + 'tsqs': [ + (r"'''", String, '#pop'), + (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings + include('strings') + ], + } + + class LiveScriptLexer(RegexLexer): """ For `LiveScript`_ source code. @@ -2582,7 +2711,7 @@ class LiveScriptLexer(RegexLexer): ('"', String, 'dqs'), ("'", String, 'sqs'), (r'\\[\w$-]+', String), - (r'<\[.*\]>', String), + (r'<\[.*?\]>', String), ], 'strings': [ (r'[^#\\\'"]+', String), @@ -2626,11 +2755,11 @@ class DuelLexer(RegexLexer): See http://duelengine.org/. See http://jsonml.org/jbst/. - *New in Pygments 1.4.* + .. versionadded:: 1.4 """ name = 'Duel' - aliases = ['duel', 'Duel Engine', 'Duel View', 'JBST', 'jbst', 'JsonML+BST'] + aliases = ['duel', 'jbst', 'jsonml+bst'] filenames = ['*.duel','*.jbst'] mimetypes = ['text/x-duel','text/x-jbst'] @@ -2657,11 +2786,11 @@ class ScamlLexer(ExtendedRegexLexer): """ For `Scaml markup <http://scalate.fusesource.org/>`_. Scaml is Haml for Scala. - *New in Pygments 1.4.* + .. versionadded:: 1.4 """ name = 'Scaml' - aliases = ['scaml', 'SCAML'] + aliases = ['scaml'] filenames = ['*.scaml'] mimetypes = ['text/x-scaml'] @@ -2771,11 +2900,11 @@ class JadeLexer(ExtendedRegexLexer): Jade is a variant of Scaml, see: http://scalate.fusesource.org/documentation/scaml-reference.html - *New in Pygments 1.4.* + .. versionadded:: 1.4 """ name = 'Jade' - aliases = ['jade', 'JADE'] + aliases = ['jade'] filenames = ['*.jade'] mimetypes = ['text/x-jade'] @@ -2879,7 +3008,7 @@ class XQueryLexer(ExtendedRegexLexer): An XQuery lexer, parsing a stream and outputting the tokens needed to highlight xquery code. - *New in Pygments 1.4.* + .. versionadded:: 1.4 """ name = 'XQuery' aliases = ['xquery', 'xqy', 'xq', 'xql', 'xqm'] @@ -3284,7 +3413,7 @@ class XQueryLexer(ExtendedRegexLexer): 'xml_comment': [ (r'(-->)', popstate_xmlcomment_callback), (r'[^-]{1,2}', Literal), - (ur'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + + (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + unirange(0x10000, 0x10ffff), Literal), ], 'processing_instruction': [ @@ -3294,12 +3423,12 @@ class XQueryLexer(ExtendedRegexLexer): ], 'processing_instruction_content': [ (r'\?>', String.Doc, '#pop'), - (ur'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + + (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + unirange(0x10000, 0x10ffff), Literal), ], 'cdata_section': [ (r']]>', String.Doc, '#pop'), - (ur'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + + (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + unirange(0x10000, 0x10ffff), Literal), ], 'start_tag': [ @@ -3368,7 +3497,7 @@ class XQueryLexer(ExtendedRegexLexer): ], 'pragmacontents': [ (r'#\)', Punctuation, 'operator'), - (ur'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + + (u'\\t|\\r|\\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + unirange(0x10000, 0x10ffff), Literal), (r'(\s+)', Text), ], @@ -3541,7 +3670,7 @@ class DartLexer(RegexLexer): """ For `Dart <http://dartlang.org/>`_ source code. - *New in Pygments 1.5.* + .. versionadded:: 1.5 """ name = 'Dart' @@ -3569,7 +3698,7 @@ class DartLexer(RegexLexer): r'native|operator|set|static|typedef|var)\b', Keyword.Declaration), (r'\b(bool|double|Dynamic|int|num|Object|String|void)\b', Keyword.Type), (r'\b(false|null|true)\b', Keyword.Constant), - (r'[~!%^&*+=|?:<>/-]|as', Operator), + (r'[~!%^&*+=|?:<>/-]|as\b', Operator), (r'[a-zA-Z_$][a-zA-Z0-9_]*:', Name.Label), (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name), (r'[(){}\[\],.;]', Punctuation), @@ -3639,9 +3768,9 @@ class DartLexer(RegexLexer): class TypeScriptLexer(RegexLexer): """ - For `TypeScript <http://www.python.org>`_ source code. + For `TypeScript <http://typescriptlang.org/>`_ source code. - *New in Pygments 1.6.* + .. versionadded:: 1.6 """ name = 'TypeScript' @@ -3728,7 +3857,7 @@ class LassoLexer(RegexLexer): If given and ``True``, only highlight code between delimiters as Lasso (default: ``False``). - *New in Pygments 1.6.* + .. versionadded:: 1.6 """ name = 'Lasso' @@ -3746,7 +3875,7 @@ class LassoLexer(RegexLexer): (r'\[', Comment.Preproc, ('delimiters', 'squarebrackets')), (r'<\?(LassoScript|lasso|=)', Comment.Preproc, ('delimiters', 'anglebrackets')), - (r'<', Other, 'delimiters'), + (r'<(!--.*?-->)?', Other, 'delimiters'), (r'\s+', Other), (r'', Other, ('delimiters', 'lassofile')), ], @@ -3755,7 +3884,7 @@ class LassoLexer(RegexLexer): (r'\[noprocess\]', Comment.Preproc, 'noprocess'), (r'\[', Comment.Preproc, 'squarebrackets'), (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), - (r'<', Other), + (r'<(!--.*?-->)?', Other), (r'[^[<]+', Other), ], 'nosquarebrackets': [ @@ -3777,8 +3906,7 @@ class LassoLexer(RegexLexer): include('lasso'), ], 'lassofile': [ - (r'\]', Comment.Preproc, '#pop'), - (r'\?>', Comment.Preproc, '#pop'), + (r'\]|\?>', Comment.Preproc, '#pop'), include('lasso'), ], 'whitespacecomments': [ @@ -3807,13 +3935,13 @@ class LassoLexer(RegexLexer): bygroups(Name.Builtin.Pseudo, Name.Variable.Class)), (r"(self)(\s*->\s*)('[a-z_][\w.]*')", bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)), - (r'(\.\.?)([a-z_][\w.]*)', + (r'(\.\.?)([a-z_][\w.]*(=(?!=))?)', bygroups(Name.Builtin.Pseudo, Name.Other.Member)), - (r'(->\\?\s*|&\s*)([a-z_][\w.]*)', + (r'(->\\?\s*|&\s*)([a-z_][\w.]*(=(?!=))?)', bygroups(Operator, Name.Other.Member)), - (r'(self|inherited|global|void)\b', Name.Builtin.Pseudo), + (r'(self|inherited)\b', Name.Builtin.Pseudo), (r'-[a-z_][\w.]*', Name.Attribute), - (r'(::\s*)([a-z_][\w.]*)', bygroups(Punctuation, Name.Label)), + (r'::\s*[a-z_][\w.]*', Name.Label), (r'(error_(code|msg)_\w+|Error_AddError|Error_ColumnRestriction|' r'Error_DatabaseConnectionUnavailable|Error_DatabaseTimeout|' r'Error_DeleteError|Error_FieldRestriction|Error_FileNotFound|' @@ -3827,22 +3955,22 @@ class LassoLexer(RegexLexer): # definitions (r'(define)(\s+)([a-z_][\w.]*)(\s*=>\s*)(type|trait|thread)\b', bygroups(Keyword.Declaration, Text, Name.Class, Operator, Keyword)), - (r'(define)(\s+)([a-z_][\w.]*)(\s*->\s*)([a-z_][\w.]*=?|[-+*/%<>]|==)', + (r'(define)(\s+)([a-z_][\w.]*)(\s*->\s*)([a-z_][\w.]*=?|[-+*/%])', bygroups(Keyword.Declaration, Text, Name.Class, Operator, Name.Function), 'signature'), (r'(define)(\s+)([a-z_][\w.]*)', bygroups(Keyword.Declaration, Text, Name.Function), 'signature'), - (r'(public|protected|private|provide)(\s+)(([a-z_][\w.]*=?|' - r'[-+*/%<>]|==)(?=\s*\())', bygroups(Keyword, Text, Name.Function), + (r'(public|protected|private|provide)(\s+)(([a-z_][\w.]*=?|[-+*/%])' + r'(?=\s*\())', bygroups(Keyword, Text, Name.Function), 'signature'), - (r'(public|protected|private)(\s+)([a-z_][\w.]*)', + (r'(public|protected|private|provide)(\s+)([a-z_][\w.]*)', bygroups(Keyword, Text, Name.Function)), # keywords - (r'(true|false|none|minimal|full|all)\b', Keyword.Constant), - (r'(local|var|variable|data(?=\s))\b', Keyword.Declaration), + (r'(true|false|none|minimal|full|all|void)\b', Keyword.Constant), + (r'(local|var|variable|global|data(?=\s))\b', Keyword.Declaration), (r'(array|date|decimal|duration|integer|map|pair|string|tag|xml|' - r'null|list|queue|set|stack|staticarray)\b', Keyword.Type), + r'null|bytes|list|queue|set|stack|staticarray|tie)\b', Keyword.Type), (r'([a-z_][\w.]*)(\s+)(in)\b', bygroups(Name, Text, Keyword)), (r'(let|into)(\s+)([a-z_][\w.]*)', bygroups(Keyword, Text, Name)), (r'require\b', Keyword, 'requiresection'), @@ -3862,17 +3990,18 @@ class LassoLexer(RegexLexer): r'Run_Children|SOAP_DefineTag|SOAP_LastRequest|SOAP_LastResponse|' r'Tag_Name|ascending|average|by|define|descending|do|equals|' r'frozen|group|handle_failure|import|in|into|join|let|match|max|' - r'min|on|order|parent|protected|provide|public|require|skip|' - r'split_thread|sum|take|thread|to|trait|type|where|with|yield)\b', + r'min|on|order|parent|protected|provide|public|require|returnhome|' + r'skip|split_thread|sum|take|thread|to|trait|type|where|with|' + r'yield|yieldhome)\b', bygroups(Punctuation, Keyword)), # other (r',', Punctuation, 'commamember'), (r'(and|or|not)\b', Operator.Word), - (r'([a-z_][\w.]*)(\s*::\s*)?([a-z_][\w.]*)?(\s*=(?!=))', - bygroups(Name, Punctuation, Name.Label, Operator)), + (r'([a-z_][\w.]*)(\s*::\s*[a-z_][\w.]*)?(\s*=(?!=))', + bygroups(Name, Name.Label, Operator)), (r'(/?)([\w.]+)', bygroups(Punctuation, Name.Other)), - (r'(=)(bw|ew|cn|lte?|gte?|n?eq|ft|n?rx)\b', + (r'(=)(n?bw|n?ew|n?cn|lte?|gte?|n?eq|n?rx|ft)\b', bygroups(Operator, Operator.Word)), (r':=|[-+*/%=<>&|!?\\]+', Operator), (r'[{}():;,@^]', Punctuation), @@ -3881,13 +4010,13 @@ class LassoLexer(RegexLexer): (r"'", String.Single, '#pop'), (r"[^'\\]+", String.Single), include('escape'), - (r"\\+", String.Single), + (r"\\", String.Single), ], 'doublestring': [ (r'"', String.Double, '#pop'), (r'[^"\\]+', String.Double), include('escape'), - (r'\\+', String.Double), + (r'\\', String.Double), ], 'escape': [ (r'\\(U[\da-f]{8}|u[\da-f]{4}|x[\da-f]{1,2}|[0-7]{1,3}|:[^:]+:|' @@ -3906,10 +4035,10 @@ class LassoLexer(RegexLexer): include('lasso'), ], 'requiresection': [ - (r'(([a-z_][\w.]*=?|[-+*/%<>]|==)(?=\s*\())', Name, 'requiresignature'), - (r'(([a-z_][\w.]*=?|[-+*/%<>]|==)(?=(\s*::\s*[\w.]+)?\s*,))', Name), - (r'[a-z_][\w.]*=?|[-+*/%<>]|==', Name, '#pop'), - (r'(::\s*)([a-z_][\w.]*)', bygroups(Punctuation, Name.Label)), + (r'(([a-z_][\w.]*=?|[-+*/%])(?=\s*\())', Name, 'requiresignature'), + (r'(([a-z_][\w.]*=?|[-+*/%])(?=(\s*::\s*[\w.]+)?\s*,))', Name), + (r'[a-z_][\w.]*=?|[-+*/%]', Name, '#pop'), + (r'::\s*[a-z_][\w.]*', Name.Label), (r',', Punctuation), include('whitespacecomments'), ], @@ -3917,13 +4046,13 @@ class LassoLexer(RegexLexer): (r'(\)(?=(\s*::\s*[\w.]+)?\s*,))', Punctuation, '#pop'), (r'\)', Punctuation, '#pop:2'), (r'-?[a-z_][\w.]*', Name.Attribute), - (r'(::\s*)([a-z_][\w.]*)', bygroups(Punctuation, Name.Label)), + (r'::\s*[a-z_][\w.]*', Name.Label), (r'\.\.\.', Name.Builtin.Pseudo), (r'[(,]', Punctuation), include('whitespacecomments'), ], 'commamember': [ - (r'(([a-z_][\w.]*=?|[-+*/%<>]|==)' + (r'(([a-z_][\w.]*=?|[-+*/%])' r'(?=\s*(\(([^()]*\([^()]*\))*[^)]*\)\s*)?(::[\w.\s]+)?=>))', Name.Function, 'signature'), include('whitespacecomments'), @@ -3941,9 +4070,9 @@ class LassoLexer(RegexLexer): self._members = set() if self.builtinshighlighting: from pygments.lexers._lassobuiltins import BUILTINS, MEMBERS - for key, value in BUILTINS.iteritems(): + for key, value in iteritems(BUILTINS): self._builtins.update(value) - for key, value in MEMBERS.iteritems(): + for key, value in iteritems(MEMBERS): self._members.update(value) RegexLexer.__init__(self, **options) @@ -3954,7 +4083,8 @@ class LassoLexer(RegexLexer): for index, token, value in \ RegexLexer.get_tokens_unprocessed(self, text, stack): if (token is Name.Other and value.lower() in self._builtins or - token is Name.Other.Member and value.lower() in self._members): + token is Name.Other.Member and + value.lower().rstrip('=') in self._members): yield index, Name.Builtin, value continue yield index, token, value @@ -3976,14 +4106,14 @@ class QmlLexer(RegexLexer): """ For QML files. See http://doc.qt.digia.com/4.7/qdeclarativeintroduction.html. - *New in Pygments 1.6.* + .. versionadded:: 1.6 """ # QML is based on javascript, so much of this is taken from the # JavascriptLexer above. name = 'QML' - aliases = ['qml', 'Qt Meta Language', 'Qt modeling Language'] + aliases = ['qml'] filenames = ['*.qml',] mimetypes = [ 'application/x-qml',] @@ -4043,3 +4173,238 @@ class QmlLexer(RegexLexer): (r"'(\\\\|\\'|[^'])*'", String.Single), ] } + + +class CirruLexer(RegexLexer): + """ + Syntax rules of Cirru can be found at: + http://grammar.cirru.org/ + + * using ``()`` to markup blocks, but limited in the same line + * using ``""`` to markup strings, allow ``\`` to escape + * using ``$`` as a shorthand for ``()`` till indentation end or ``)`` + * using indentations for create nesting + + .. versionadded:: 2.0 + """ + + name = 'Cirru' + aliases = ['cirru'] + filenames = ['*.cirru', '*.cr'] + mimetypes = ['text/x-cirru'] + flags = re.MULTILINE + + tokens = { + 'string': [ + (r'[^"\\\n]', String), + (r'\\', String.Escape, 'escape'), + (r'"', String, '#pop'), + ], + 'escape': [ + (r'.', String.Escape, '#pop'), + ], + 'function': [ + (r'[\w-][^\s\(\)\"]*', Name.Function, '#pop'), + (r'\)', Operator, '#pop'), + (r'(?=\n)', Text, '#pop'), + (r'\(', Operator, '#push'), + (r'"', String, ('#pop', 'string')), + (r'\s+', Text.Whitespace), + (r'\,', Operator, '#pop'), + ], + 'line': [ + (r'^\B', Text.Whitespace, 'function'), + (r'\$', Operator, 'function'), + (r'\(', Operator, 'function'), + (r'\)', Operator), + (r'(?=\n)', Text, '#pop'), + (r'\n', Text, '#pop'), + (r'"', String, 'string'), + (r'\s+', Text.Whitespace), + (r'[\d\.]+', Number), + (r'[\w-][^\"\(\)\s]*', Name.Variable), + (r'--', Comment.Single) + ], + 'root': [ + (r'^\s*', Text.Whitespace, ('line', 'function')), + (r'^\s+$', Text.Whitespace), + ] + } + + +class MaskLexer(RegexLexer): + """ + For `Mask <http://github.com/atmajs/MaskJS>`__ markup. + + .. versionadded:: 2.0 + """ + name = 'Mask' + aliases = ['mask'] + filenames = ['*.mask'] + mimetypes = ['text/x-mask'] + + flags = re.MULTILINE | re.IGNORECASE | re.DOTALL + tokens = { + 'root': [ + (r'\s+', Text), + (r'//.*?\n', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline), + (r'[\{\};>]', Punctuation), + (r"'''", String, 'string-trpl-single'), + (r'"""', String, 'string-trpl-double'), + (r"'", String, 'string-single'), + (r'"', String, 'string-double'), + (r'([\w-]+)', Name.Tag, 'node'), + (r'([^\.#;{>\s]+)', Name.Class, 'node'), + (r'(#[\w_-]+)', Name.Function, 'node'), + (r'(\.[\w_-]+)', Name.Variable.Class, 'node') + ], + 'string-base': [ + (r'\\.', String.Escape), + (r'~\[', String.Interpol, 'interpolation'), + (r'.', String.Single), + ], + 'string-single':[ + (r"'", String.Single, '#pop'), + include('string-base') + ], + 'string-double':[ + (r'"', String.Single, '#pop'), + include('string-base') + ], + 'string-trpl-single':[ + (r"'''", String.Single, '#pop'), + include('string-base') + ], + 'string-trpl-double':[ + (r'"""', String.Single, '#pop'), + include('string-base') + ], + 'interpolation': [ + (r'\]', String.Interpol, '#pop'), + (r'\s*:', String.Interpol, 'expression'), + (r'\s*\w+:', Name.Other), + (r'[^\]]+', String.Interpol) + ], + 'expression': [ + (r'[^\]]+', using(JavascriptLexer), '#pop') + ], + 'node': [ + (r'\s+', Text), + (r'\.', Name.Variable.Class, 'node-class'), + (r'\#', Name.Function, 'node-id'), + (r'style[ \t]*=', Name.Attribute, 'node-attr-style-value'), + (r'[\w_:-]+[ \t]*=', Name.Attribute, 'node-attr-value'), + (r'[\w_:-]+', Name.Attribute), + (r'[>{;]', Punctuation, '#pop') + ], + 'node-class': [ + (r'[\w-]+', Name.Variable.Class), + (r'~\[', String.Interpol, 'interpolation'), + (r'', Text, '#pop') + ], + 'node-id': [ + (r'[\w-]+', Name.Function), + (r'~\[', String.Interpol, 'interpolation'), + (r'', Text, '#pop') + ], + 'node-attr-value':[ + (r'\s+', Text), + (r'[\w_]+', Name.Variable, '#pop'), + (r"'", String, 'string-single-pop2'), + (r'"', String, 'string-double-pop2'), + (r'', Text, '#pop') + ], + 'node-attr-style-value':[ + (r'\s+', Text), + (r"'", String.Single, 'css-single-end'), + (r'"', String.Single, 'css-double-end'), + include('node-attr-value') + ], + 'css-base': [ + (r'\s+', Text), + (r"[;]", Punctuation), + (r"[\w\-_]+\s*:", Name.Builtin) + ], + 'css-single-end': [ + include('css-base'), + (r"'", String.Single, '#pop:2'), + (r"[^;']+", Name.Entity) + ], + 'css-double-end': [ + include('css-base'), + (r'"', String.Single, '#pop:2'), + (r"[^;\"]+", Name.Entity) + ], + 'string-single-pop2':[ + (r"'", String.Single, '#pop:2'), + include('string-base') + ], + 'string-double-pop2':[ + (r'"', String.Single, '#pop:2'), + include('string-base') + ], + } + + +class ZephirLexer(RegexLexer): + """ + For `Zephir language <http://zephir-lang.com/>`_ source code. + + Zephir is a compiled high level language aimed + to the creation of C-extensions for PHP. + + .. versionadded:: 2.0 + """ + + name = 'Zephir' + aliases = ['zephir'] + filenames = ['*.zep'] + + zephir_keywords = [ 'fetch', 'echo', 'isset', 'empty'] + zephir_type = [ 'bit', 'bits' , 'string' ] + + flags = re.DOTALL | re.MULTILINE + + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Text), + (r'//.*?\n', Comment.Single), + (r'/\*.*?\*/', Comment.Multiline) + ], + 'slashstartsregex': [ + include('commentsandwhitespace'), + (r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' + r'([gim]+\b|\B)', String.Regex, '#pop'), + (r'', Text, '#pop') + ], + 'badregex': [ + (r'\n', Text, '#pop') + ], + 'root': [ + (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), + include('commentsandwhitespace'), + (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' + r'(<<|>>>?|==?|!=?|->|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), + (r'[{(\[;,]', Punctuation, 'slashstartsregex'), + (r'[})\].]', Punctuation), + (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|loop|require|inline|' + r'throw|try|catch|finally|new|delete|typeof|instanceof|void|namespace|use|extends|' + r'this|fetch|isset|unset|echo|fetch|likely|unlikely|empty)\b', Keyword, 'slashstartsregex'), + (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), + (r'(abstract|boolean|bool|char|class|const|double|enum|export|' + r'extends|final|float|goto|implements|import|int|string|interface|long|ulong|char|uchar|native|unsigned|' + r'private|protected|public|short|static|self|throws|reverse|' + r'transient|volatile)\b', Keyword.Reserved), + (r'(true|false|null|undefined)\b', Keyword.Constant), + (r'(Array|Boolean|Date|_REQUEST|_COOKIE|_SESSION|' + r'_GET|_POST|_SERVER|this|stdClass|range|count|iterator|' + r'window)\b', Name.Builtin), + (r'[$a-zA-Z_][a-zA-Z0-9_\\]*', Name.Other), + (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), + (r'0x[0-9a-fA-F]+', Number.Hex), + (r'[0-9]+', Number.Integer), + (r'"(\\\\|\\"|[^"])*"', String.Double), + (r"'(\\\\|\\'|[^'])*'", String.Single), + ] + } |