--- a/ThirdParty/Pygments/pygments/lexers/web.py Sun Feb 17 19:05:40 2013 +0100 +++ b/ThirdParty/Pygments/pygments/lexers/web.py Sun Feb 17 19:07:15 2013 +0100 @@ -5,7 +5,7 @@ Lexers for web-related languages and markup. - :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ @@ -17,16 +17,17 @@ from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Other, Punctuation, Literal from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, \ - html_doctype_matches + html_doctype_matches, unirange from pygments.lexers.agile import RubyLexer from pygments.lexers.compiled import ScalaLexer -__all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'JSONLexer', 'CssLexer', +__all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'JsonLexer', 'CssLexer', 'PhpLexer', 'ActionScriptLexer', 'XsltLexer', 'ActionScript3Lexer', 'MxmlLexer', 'HaxeLexer', 'HamlLexer', 'SassLexer', 'ScssLexer', - 'ObjectiveJLexer', 'CoffeeScriptLexer', 'DuelLexer', 'ScamlLexer', - 'JadeLexer', 'XQueryLexer', 'DtdLexer', 'DartLexer'] + 'ObjectiveJLexer', 'CoffeeScriptLexer', 'LiveScriptLexer', + 'DuelLexer', 'ScamlLexer', 'JadeLexer', 'XQueryLexer', + 'DtdLexer', 'DartLexer', 'LassoLexer', 'QmlLexer', 'TypeScriptLexer'] class JavascriptLexer(RegexLexer): @@ -89,7 +90,7 @@ } -class JSONLexer(RegexLexer): +class JsonLexer(RegexLexer): """ For JSON data structures. @@ -101,6 +102,16 @@ filenames = ['*.json'] mimetypes = [ 'application/json', ] + # integer part of a number + int_part = r'-?(0|[1-9]\d*)' + + # fractional part of a number + frac_part = r'\.\d+' + + # exponential part of a number + exp_part = r'[eE](\+|-)?\d+' + + flags = re.DOTALL tokens = { 'whitespace': [ @@ -108,9 +119,12 @@ ], # represents a simple terminal value - 'simplevalue':[ + 'simplevalue': [ (r'(true|false|null)\b', Keyword.Constant), - (r'-?[0-9]+', Number.Integer), + (('%(int_part)s(%(frac_part)s%(exp_part)s|' + '%(exp_part)s|%(frac_part)s)') % vars(), + Number.Float), + (int_part, Number.Integer), (r'"(\\\\|\\"|[^"])*"', String.Double), ], @@ -156,6 +170,8 @@ } +JSONLexer = JsonLexer # for backwards compatibility with Pygments 1.5 + class ActionScriptLexer(RegexLexer): """ @@ -456,7 +472,7 @@ (r'[\[\]();]+', Punctuation), (r'"(\\\\|\\"|[^"])*"', String.Double), (r"'(\\\\|\\'|[^'])*'", String.Single), - (r'[a-zA-Z_][a-zA-Z0-9_]+', Name) + (r'[a-zA-Z_][a-zA-Z0-9_]*', Name) ] } @@ -775,7 +791,7 @@ name = 'PHP' aliases = ['php', 'php3', 'php4', 'php5'] - filenames = ['*.php', '*.php[345]'] + filenames = ['*.php', '*.php[345]', '*.inc'] mimetypes = ['text/x-php'] flags = re.IGNORECASE | re.DOTALL | re.MULTILINE @@ -815,7 +831,7 @@ 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)\b', Keyword), + r'catch|throw|this|use|namespace|trait)\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), @@ -953,7 +969,8 @@ 'attlist': [ include('common'), - (r'CDATA|IDREFS|IDREF|ID|NMTOKENS|NMTOKEN|ENTITIES|ENTITY|NOTATION', Keyword.Constant), + (r'CDATA|IDREFS|IDREF|ID|NMTOKENS|NMTOKEN|ENTITIES|ENTITY|NOTATION', + Keyword.Constant), (r'#REQUIRED|#IMPLIED|#FIXED', Keyword.Constant), (r'xml:space|xml:lang', Keyword.Reserved), (r'[^>\s\|()?+*,]+', Name.Attribute), @@ -985,7 +1002,7 @@ Generic lexer for XML (eXtensible Markup Language). """ - flags = re.MULTILINE | re.DOTALL + flags = re.MULTILINE | re.DOTALL | re.UNICODE name = 'XML' aliases = ['xml'] @@ -1001,8 +1018,8 @@ ('<!--', Comment, 'comment'), (r'<\?.*?\?>', Comment.Preproc), ('<![^>]*>', Comment.Preproc), - (r'<\s*[a-zA-Z0-9:._-]+', Name.Tag, 'tag'), - (r'<\s*/\s*[a-zA-Z0-9:._-]+\s*>', Name.Tag), + (r'<\s*[\w:.-]+', Name.Tag, 'tag'), + (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag), ], 'comment': [ ('[^-]+', Comment), @@ -1011,7 +1028,7 @@ ], 'tag': [ (r'\s+', Text), - (r'[a-zA-Z0-9_.:-]+\s*=', Name.Attribute, 'attr'), + (r'[\w.:-]+\s*=', Name.Attribute, 'attr'), (r'/?\s*>', Name.Tag, '#pop'), ], 'attr': [ @@ -1036,7 +1053,7 @@ name = 'XSLT' aliases = ['xslt'] - filenames = ['*.xsl', '*.xslt'] + filenames = ['*.xsl', '*.xslt', '*.xpl'] # xpl is XProc mimetypes = ['application/xsl+xml', 'application/xslt+xml'] EXTRA_KEYWORDS = set([ @@ -1068,6 +1085,8 @@ """ For MXML markup. Nested AS3 in <script> tags is highlighted by the appropriate lexer. + + *New in Pygments 1.1.* """ flags = re.MULTILINE | re.DOTALL name = 'MXML' @@ -1109,6 +1128,8 @@ class HaxeLexer(RegexLexer): """ For haXe source code (http://haxe.org/). + + *New in Pygments 1.3.* """ name = 'haXe' @@ -1742,7 +1763,7 @@ (r'(@include)( [\w-]+)', bygroups(Keyword, Name.Decorator), 'value'), (r'@extend', Keyword, 'selector'), (r'@[a-z0-9_-]+', Keyword, 'selector'), - (r'(\$[\w-]\w*)([ \t]*:)', bygroups(Name.Variable, Operator), 'value'), + (r'(\$[\w-]*\w)([ \t]*:)', bygroups(Name.Variable, Operator), 'value'), (r'(?=[^;{}][;}])', Name.Attribute, 'attr'), (r'(?=[^;{}:]+:[^a-z])', Name.Attribute, 'attr'), (r'', Text, 'selector'), @@ -1784,14 +1805,14 @@ tokens = { 'commentsandwhitespace': [ (r'\s+', Text), - (r'###.*?###', Comment.Multiline), - (r'#.*?\n', Comment.Single), + (r'###[^#].*?###', Comment.Multiline), + (r'#(?!##[^#]).*?\n', Comment.Single), ], 'multilineregex': [ - include('commentsandwhitespace'), + (r'[^/#]+', String.Regex), (r'///([gim]+\b|\B)', String.Regex, '#pop'), - (r'/', String.Regex), - (r'[^/#]+', String.Regex) + (r'#{', String.Interpol, 'interpoling_string'), + (r'[/#]', String.Regex), ], 'slashstartsregex': [ include('commentsandwhitespace'), @@ -1804,28 +1825,32 @@ # this next expr leads to infinite loops root -> slashstartsregex #(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), include('commentsandwhitespace'), - (r'\+\+|--|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|=|' - r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|[-<>+*`%&\|\^/])=?', + (r'\+\+|~|&&|\band\b|\bor\b|\bis\b|\bisnt\b|\bnot\b|\?|:|' + r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|' + r'=(?!>)|-(?!>)|[<>+*`%&\|\^/])=?', Operator, 'slashstartsregex'), - (r'\([^()]*\)\s*->', Name.Function), + (r'(?:\([^()]+\))?\s*[=-]>', Name.Function), (r'[{(\[;,]', Punctuation, 'slashstartsregex'), (r'[})\].]', Punctuation), - (r'(for|in|of|while|break|return|continue|switch|when|then|if|else|' + (r'(?<![\.\$])(for|own|in|of|while|until|' + r'loop|break|return|continue|' + r'switch|when|then|if|unless|else|' r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' r'extends|this|class|by)\b', Keyword, 'slashstartsregex'), - (r'(true|false|yes|no|on|off|null|NaN|Infinity|undefined)\b', + (r'(?<![\.\$])(true|false|yes|no|on|off|null|' + 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)\b', Name.Builtin), - (r'[$a-zA-Z_][a-zA-Z0-9_\.:]*\s*[:=]\s', Name.Variable, + (r'[$a-zA-Z_][a-zA-Z0-9_\.:\$]*\s*[:=]\s', Name.Variable, 'slashstartsregex'), - (r'@[$a-zA-Z_][a-zA-Z0-9_\.:]*\s*[:=]\s', Name.Variable.Instance, + (r'@[$a-zA-Z_][a-zA-Z0-9_\.:\$]*\s*[:=]\s', Name.Variable.Instance, 'slashstartsregex'), (r'@', Name.Other, 'slashstartsregex'), - (r'@?[$a-zA-Z_][a-zA-Z0-9_]*', Name.Other, 'slashstartsregex'), + (r'@?[$a-zA-Z_][a-zA-Z0-9_\$]*', Name.Other, 'slashstartsregex'), (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), @@ -1867,6 +1892,118 @@ ], } + +class LiveScriptLexer(RegexLexer): + """ + For `LiveScript`_ source code. + + .. _LiveScript: http://gkz.github.com/LiveScript/ + + New in Pygments 1.6. + """ + + name = 'LiveScript' + aliases = ['live-script', 'livescript'] + filenames = ['*.ls'] + mimetypes = ['text/livescript'] + + flags = re.DOTALL + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Text), + (r'/\*.*?\*/', Comment.Multiline), + (r'#.*?\n', Comment.Single), + ], + 'multilineregex': [ + include('commentsandwhitespace'), + (r'//([gim]+\b|\B)', String.Regex, '#pop'), + (r'/', String.Regex), + (r'[^/#]+', String.Regex) + ], + 'slashstartsregex': [ + include('commentsandwhitespace'), + (r'//', String.Regex, ('#pop', 'multilineregex')), + (r'/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/' + r'([gim]+\b|\B)', String.Regex, '#pop'), + (r'', Text, '#pop'), + ], + 'root': [ + # this next expr leads to infinite loops root -> slashstartsregex + #(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), + include('commentsandwhitespace'), + (r'(?:\([^()]+\))?[ ]*[~-]{1,2}>|' + r'(?:\(?[^()\n]+\)?)?[ ]*<[~-]{1,2}', Name.Function), + (r'\+\+|&&|(?<![\.\$])\b(?:and|x?or|is|isnt|not)\b|\?|:|=|' + r'\|\||\\(?=\n)|(<<|>>>?|==?|!=?|' + r'~(?!\~?>)|-(?!\-?>)|<(?!\[)|(?<!\])>|' + r'[+*`%&\|\^/])=?', + Operator, 'slashstartsregex'), + (r'[{(\[;,]', Punctuation, 'slashstartsregex'), + (r'[})\].]', Punctuation), + (r'(?<![\.\$])(for|own|in|of|while|until|loop|break|' + r'return|continue|switch|when|then|if|unless|else|' + r'throw|try|catch|finally|new|delete|typeof|instanceof|super|' + r'extends|this|class|by|const|var|to|til)\b', Keyword, + 'slashstartsregex'), + (r'(?<![\.\$])(true|false|yes|no|on|off|' + r'null|NaN|Infinity|undefined|void)\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)\b', + Name.Builtin), + (r'[$a-zA-Z_][a-zA-Z0-9_\.\-:\$]*\s*[:=]\s', Name.Variable, + 'slashstartsregex'), + (r'@[$a-zA-Z_][a-zA-Z0-9_\.\-:\$]*\s*[:=]\s', Name.Variable.Instance, + 'slashstartsregex'), + (r'@', Name.Other, 'slashstartsregex'), + (r'@?[$a-zA-Z_][a-zA-Z0-9_\-]*', Name.Other, 'slashstartsregex'), + (r'[0-9]+\.[0-9]+([eE][0-9]+)?[fd]?(?:[a-zA-Z_]+)?', Number.Float), + (r'[0-9]+(~[0-9a-z]+)?(?:[a-zA-Z_]+)?', Number.Integer), + ('"""', String, 'tdqs'), + ("'''", String, 'tsqs'), + ('"', String, 'dqs'), + ("'", String, 'sqs'), + (r'\\[\w$-]+', String), + (r'<\[.*\]>', String), + ], + 'strings': [ + (r'[^#\\\'"]+', String), + # note that all coffee script 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"), + (r'#', 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"), + (r'#', String), + include('strings'), + ], + 'tsqs': [ + (r"'''", String, '#pop'), + (r'#|\\.|\'|"', String), # no need to escape quotes in triple-strings + include('strings') + ], + } + + class DuelLexer(RegexLexer): """ Lexer for Duel Views Engine (formerly JBST) markup with JavaScript code blocks. @@ -2129,8 +2266,8 @@ *New in Pygments 1.4.* """ name = 'XQuery' - aliases = ['xquery', 'xqy'] - filenames = ['*.xqy', '*.xquery'] + aliases = ['xquery', 'xqy', 'xq', 'xql', 'xqm'] + filenames = ['*.xqy', '*.xquery', '*.xq', '*.xql', '*.xqm'] mimetypes = ['text/xquery', 'application/xquery'] xquery_parse_state = [] @@ -2531,8 +2668,8 @@ 'xml_comment': [ (r'(-->)', popstate_xmlcomment_callback), (r'[^-]{1,2}', Literal), - (r'\t|\r|\n|[\u0020-\U0000D7FF]|[\U0000E000-\U0000FFFD]|' - r'[\U00010000-\U0010FFFF]', Literal), + (r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + + unirange(0x10000, 0x10ffff), Literal), ], 'processing_instruction': [ (r'\s+', Text, 'processing_instruction_content'), @@ -2541,13 +2678,13 @@ ], 'processing_instruction_content': [ (r'\?>', String.Doc, '#pop'), - (r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' - r'[\U00010000-\U0010FFFF]', Literal), + (r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + + unirange(0x10000, 0x10ffff), Literal), ], 'cdata_section': [ (r']]>', String.Doc, '#pop'), - (r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' - r'[\U00010000-\U0010FFFF]', Literal), + (r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + + unirange(0x10000, 0x10ffff), Literal), ], 'start_tag': [ include('whitespace'), @@ -2615,8 +2752,8 @@ ], 'pragmacontents': [ (r'#\)', Punctuation, 'operator'), - (r'\t|\r|\n|[\u0020-\U0000D7FF]|[\U0000E000-\U0000FFFD]|' - r'[\U00010000-\U0010FFFF]', Literal), + (r'\t|\r|\n|[\u0020-\uD7FF]|[\uE000-\uFFFD]|' + + unirange(0x10000, 0x10ffff), Literal), (r'(\s+)', Text), ], 'occurrenceindicator': [ @@ -2651,12 +2788,14 @@ (r'(\.\d+)[eE][\+\-]?\d+', Number.Double, 'operator'), (r'(\.\d+|\d+\.\d*)', Number, 'operator'), (r'(\d+)', Number.Integer, 'operator'), - (r'(\.\.|\.|\)|\*)', Punctuation, 'operator'), + (r'(\.\.|\.|\))', Punctuation, 'operator'), (r'(declare)(\s+)(construction)', bygroups(Keyword, Text, Keyword), 'operator'), (r'(declare)(\s+)(default)(\s+)(order)', bygroups(Keyword, Text, Keyword, Text, Keyword), 'operator'), (ncname + ':\*', Name, 'operator'), + ('\*:'+ncname, Name.Tag, 'operator'), + ('\*', Name.Tag, 'operator'), (stringdouble, String.Double, 'operator'), (stringsingle, String.Single, 'operator'), @@ -2767,16 +2906,17 @@ (r'(catch)(\s*)(\()(\$)', bygroups(Keyword, Text, Punctuation, Name.Variable), 'varname'), - (r'(@' + qname + ')', pushstate_operator_attribute_callback), - (r'(@\*)', pushstate_operator_attribute_callback), - (r'(@' + ncname + ')', pushstate_operator_attribute_callback), + (r'(@'+qname+')', Name.Attribute), + (r'(@'+ncname+')', Name.Attribute), + (r'@\*:'+ncname, Name.Attribute), + (r'(@)', Name.Attribute), (r'//|/|\+|-|;|,|\(|\)', Punctuation), # STANDALONE QNAMES - (qname + r'(?=\s*{)', Name.Variable, 'qname_braren'), - (qname + r'(?=\s*\()', Name.Function, 'qname_braren'), - (qname, Name.Variable, 'operator'), + (qname + r'(?=\s*{)', Name.Tag, 'qname_braren'), + (qname + r'(?=\s*\([^:])', Name.Function, 'qname_braren'), + (qname, Name.Tag, 'operator'), ] } @@ -2797,27 +2937,25 @@ tokens = { 'root': [ + include('string_literal'), (r'#!(.*?)$', Comment.Preproc), - (r'(#)(import|library|source)', bygroups(Text, Keyword)), + (r'\b(import|export)\b', Keyword, 'import_decl'), + (r'\b(library|source|part of|part)\b', Keyword), (r'[^\S\n]+', Text), (r'//.*?\n', Comment.Single), (r'/\*.*?\*/', Comment.Multiline), - (r'(class|interface)(\s+)', + (r'\b(class)\b(\s+)', bygroups(Keyword.Declaration, Text), 'class'), - (r'(assert|break|case|catch|continue|default|do|else|finally|for|' + (r'\b(assert|break|case|catch|continue|default|do|else|finally|for|' r'if|in|is|new|return|super|switch|this|throw|try|while)\b', Keyword), - (r'(abstract|const|extends|factory|final|get|implements|' + (r'\b(abstract|const|extends|factory|final|get|implements|' r'native|operator|set|static|typedef|var)\b', Keyword.Declaration), - (r'(bool|double|Dynamic|int|num|Object|String|void)', Keyword.Type), - (r'(false|null|true)', Keyword.Constant), - (r'@"(\\\\|\\"|[^"])*"', String.Double), # raw string - (r"@'(\\\\|\\'|[^'])*'", String.Single), # raw string - (r'"', String.Double, 'string_double'), - (r"'", String.Single, 'string_single'), + (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'[a-zA-Z_$][a-zA-Z0-9_]*:', Name.Label), (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name), - (r'[~!%^&*+=|?:<>/-]', Operator), (r'[(){}\[\],.;]', Punctuation), (r'0[xX][0-9a-fA-F]+', Number.Hex), # DIGIT+ (‘.’ DIGIT*)? EXPONENT? @@ -2829,20 +2967,457 @@ 'class': [ (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name.Class, '#pop') ], + 'import_decl': [ + include('string_literal'), + (r'\s+', Text), + (r'\b(as|show|hide)\b', Keyword), + (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name), + (r'\,', Punctuation), + (r'\;', Punctuation, '#pop') + ], + 'string_literal': [ + # Raw strings. + (r'r"""([\s|\S]*?)"""', String.Double), + (r"r'''([\s|\S]*?)'''", String.Single), + (r'r"(.*?)"', String.Double), + (r"r'(.*?)'", String.Single), + # Normal Strings. + (r'"""', String.Double, 'string_double_multiline'), + (r"'''", String.Single, 'string_single_multiline'), + (r'"', String.Double, 'string_double'), + (r"'", String.Single, 'string_single') + ], + 'string_common': [ + (r"\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]*\}|[a-z\'\"$\\])", + String.Escape), + (r'(\$)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(String.Interpol, Name)), + (r'(\$\{)(.*?)(\})', + bygroups(String.Interpol, using(this), String.Interpol)) + ], 'string_double': [ (r'"', String.Double, '#pop'), - (r'[^"$]+', String.Double), - (r'(\$)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(String.Interpol, Name)), - (r'(\$\{)(.*?)(\})', - bygroups(String.Interpol, using(this), String.Interpol)), + (r'[^\"$\\\n]+', String.Double), + include('string_common'), (r'\$+', String.Double) ], + 'string_double_multiline': [ + (r'"""', String.Double, '#pop'), + (r'[^\"$\\]+', String.Double), + include('string_common'), + (r'(\$|\")+', String.Double) + ], 'string_single': [ (r"'", String.Single, '#pop'), - (r"[^'$]+", String.Single), - (r'(\$)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(String.Interpol, Name)), - (r'(\$\{)(.*?)(\})', - bygroups(String.Interpol, using(this), String.Interpol)), + (r"[^\'$\\\n]+", String.Single), + include('string_common'), (r'\$+', String.Single) + ], + 'string_single_multiline': [ + (r"'''", String.Single, '#pop'), + (r'[^\'$\\]+', String.Single), + include('string_common'), + (r'(\$|\')+', String.Single) + ] + } + + +class TypeScriptLexer(RegexLexer): + """ + For `TypeScript <http://www.python.org>`_ source code. + + *New in Pygments 1.6.* + """ + + name = 'TypeScript' + aliases = ['ts'] + filenames = ['*.ts'] + mimetypes = ['text/x-typescript'] + + flags = re.DOTALL + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Text), + (r'<!--', Comment), + (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'', 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|' + r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' + r'this)\b', Keyword, 'slashstartsregex'), + (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), + (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' + r'extends|final|float|goto|implements|import|int|interface|long|native|' + r'package|private|protected|public|short|static|super|synchronized|throws|' + r'transient|volatile)\b', Keyword.Reserved), + (r'(true|false|null|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'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' + r'window)\b', Name.Builtin), + # Match stuff like: module name {...} + (r'\b(module)(\s*)(\s*[a-zA-Z0-9_?.$][\w?.$]*)(\s*)', + bygroups(Keyword.Reserved, Text, Name.Other, Text), 'slashstartsregex'), + # Match variable type keywords + (r'\b(string|bool|number)\b', Keyword.Type), + # Match stuff like: constructor + (r'\b(constructor|declare|interface|as|AS)\b', Keyword.Reserved), + # Match stuff like: super(argument, list) + (r'(super)(\s*)(\([a-zA-Z0-9,_?.$\s]+\s*\))', + bygroups(Keyword.Reserved, Text), 'slashstartsregex'), + # Match stuff like: function() {...} + (r'([a-zA-Z_?.$][\w?.$]*)\(\) \{', Name.Other, 'slashstartsregex'), + # Match stuff like: (function: return type) + (r'([a-zA-Z0-9_?.$][\w?.$]*)(\s*:\s*)([a-zA-Z0-9_?.$][\w?.$]*)', + bygroups(Name.Other, Text, Keyword.Type)), + (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), ] } + + +class LassoLexer(RegexLexer): + """ + For `Lasso <http://www.lassosoft.com/>`_ source code, covering both Lasso 9 + syntax and LassoScript for Lasso 8.6 and earlier. For Lasso embedded in + HTML, use the `LassoHtmlLexer`. + + Additional options accepted: + + `builtinshighlighting` + If given and ``True``, highlight builtin tags, types, traits, and + methods (default: ``True``). + `requiredelimiters` + If given and ``True``, only highlight code between delimiters as Lasso + (default: ``False``). + + *New in Pygments 1.6.* + """ + + name = 'Lasso' + aliases = ['lasso', 'lassoscript'] + filenames = ['*.lasso', '*.lasso[89]'] + alias_filenames = ['*.incl', '*.inc', '*.las'] + mimetypes = ['text/x-lasso'] + flags = re.IGNORECASE | re.DOTALL | re.MULTILINE + + tokens = { + 'root': [ + (r'^#!.+lasso9\b', Comment.Preproc, 'lasso'), + (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), + (r'\[noprocess\]', Comment.Preproc, ('delimiters', 'noprocess')), + (r'\[', Comment.Preproc, ('delimiters', 'squarebrackets')), + (r'<\?(LassoScript|lasso|=)', Comment.Preproc, + ('delimiters', 'anglebrackets')), + (r'<', Other, 'delimiters'), + (r'\s+', Other), + (r'', Other, ('delimiters', 'lassofile')), + ], + 'delimiters': [ + (r'\[no_square_brackets\]', Comment.Preproc, 'nosquarebrackets'), + (r'\[noprocess\]', Comment.Preproc, 'noprocess'), + (r'\[', Comment.Preproc, 'squarebrackets'), + (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), + (r'<', Other), + (r'[^[<]+', Other), + ], + 'nosquarebrackets': [ + (r'<\?(LassoScript|lasso|=)', Comment.Preproc, 'anglebrackets'), + (r'<', Other), + (r'[^<]+', Other), + ], + 'noprocess': [ + (r'\[/noprocess\]', Comment.Preproc, '#pop'), + (r'\[', Other), + (r'[^[]', Other), + ], + 'squarebrackets': [ + (r'\]', Comment.Preproc, '#pop'), + include('lasso'), + ], + 'anglebrackets': [ + (r'\?>', Comment.Preproc, '#pop'), + include('lasso'), + ], + 'lassofile': [ + (r'\]', Comment.Preproc, '#pop'), + (r'\?>', Comment.Preproc, '#pop'), + include('lasso'), + ], + 'whitespacecomments': [ + (r'\s+', Text), + (r'//.*?\n', Comment.Single), + (r'/\*\*!.*?\*/', String.Doc), + (r'/\*.*?\*/', Comment.Multiline), + ], + 'lasso': [ + # whitespace/comments + include('whitespacecomments'), + + # literals + (r'\d*\.\d+(e[+-]?\d+)?', Number.Float), + (r'0x[\da-f]+', Number.Hex), + (r'\d+', Number.Integer), + (r'([+-]?)(infinity|NaN)\b', bygroups(Operator, Number)), + (r"'", String.Single, 'singlestring'), + (r'"', String.Double, 'doublestring'), + (r'`[^`]*`', String.Backtick), + + # names + (r'\$[a-z_][\w.]*', Name.Variable), + (r'#[a-z_][\w.]*|#\d+', Name.Variable.Instance), + (r"(\.)('[a-z_][\w.]*')", + bygroups(Name.Builtin.Pseudo, Name.Variable.Class)), + (r"(self)(->)('[a-z_][\w.]*')", + bygroups(Name.Builtin.Pseudo, Operator, Name.Variable.Class)), + (r'(\.\.?)([a-z_][\w.]*)', + bygroups(Name.Builtin.Pseudo, Name.Other)), + (r'(self|inherited|global|void)\b', Name.Builtin.Pseudo), + (r'-[a-z_][\w.]*', Name.Attribute), + (r'(::\s*)([a-z_][\w.]*)', bygroups(Punctuation, Name.Label)), + (r'(error_(code|msg)_\w+|Error_AddError|Error_ColumnRestriction|' + r'Error_DatabaseConnectionUnavailable|Error_DatabaseTimeout|' + r'Error_DeleteError|Error_FieldRestriction|Error_FileNotFound|' + r'Error_InvalidDatabase|Error_InvalidPassword|' + r'Error_InvalidUsername|Error_ModuleNotFound|' + r'Error_NoError|Error_NoPermission|Error_OutOfMemory|' + r'Error_ReqColumnMissing|Error_ReqFieldMissing|' + r'Error_RequiredColumnMissing|Error_RequiredFieldMissing|' + r'Error_UpdateError)\b', Name.Exception), + + # definitions + (r'(define)(\s+)([a-z_][\w.]*)(\s*)(=>)(\s*)(type|trait|thread)\b', + bygroups(Keyword.Declaration, Text, Name.Class, Text, Operator, + Text, Keyword)), + (r'(define)(\s+)([a-z_][\w.]*)(->)([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), + 'signature'), + (r'(public|protected|private)(\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)\b', Keyword.Declaration), + (r'(array|date|decimal|duration|integer|map|pair|string|tag|xml|' + r'null)\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'), + (r'(/?)(Namespace_Using)\b', + bygroups(Punctuation, Keyword.Namespace)), + (r'(/?)(Cache|Database_Names|Database_SchemaNames|' + r'Database_TableNames|Define_Tag|Define_Type|Email_Batch|' + r'Encode_Set|HTML_Comment|Handle|Handle_Error|Header|If|Inline|' + r'Iterate|LJAX_Target|Link|Link_CurrentAction|Link_CurrentGroup|' + r'Link_CurrentRecord|Link_Detail|Link_FirstGroup|' + r'Link_FirstRecord|Link_LastGroup|Link_LastRecord|Link_NextGroup|' + r'Link_NextRecord|Link_PrevGroup|Link_PrevRecord|Log|Loop|' + r'NoProcess|Output_None|Portal|Private|Protect|Records|Referer|' + r'Referrer|Repeating|ResultSet|Rows|Search_Args|Search_Arguments|' + r'Select|Sort_Args|Sort_Arguments|Thread_Atomic|Value_List|While|' + r'Abort|Case|Else|If_Empty|If_False|If_Null|If_True|Loop_Abort|' + r'Loop_Continue|Loop_Count|Params|Params_Up|Return|Return_Value|' + 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', + bygroups(Punctuation, Keyword)), + + # other + (r'(([a-z_][\w.]*=?|[-+*/%<>]|==)(?=\s*\([^)]*\)\s*=>))', + Name.Function, 'signature'), + (r'(and|or|not)\b', Operator.Word), + (r'([a-z_][\w.]*)(\s*)(::\s*)([a-z_][\w.]*)(\s*)(=)', + bygroups(Name, Text, Punctuation, Name.Label, Text, Operator)), + (r'((?<!->)[a-z_][\w.]*)(\s*)(=(?!=))', + bygroups(Name, Text, Operator)), + (r'(/?)([\w.]+)', bygroups(Punctuation, Name.Other)), + (r'(=)(bw|ew|cn|lte?|gte?|n?eq|ft|n?rx)\b', + bygroups(Operator, Operator.Word)), + (r':=|[-+*/%=<>&|!?\\]+', Operator), + (r'[{}():;,@^]', Punctuation), + ], + 'singlestring': [ + (r"'", String.Single, '#pop'), + (r"[^'\\]+", String.Single), + include('escape'), + (r"\\+", String.Single), + ], + 'doublestring': [ + (r'"', String.Double, '#pop'), + (r'[^"\\]+', String.Double), + include('escape'), + (r'\\+', String.Double), + ], + 'escape': [ + (r'\\(U[\da-f]{8}|u[\da-f]{4}|x[\da-f]{1,2}|[0-7]{1,3}|:[^:]+:|' + r'[abefnrtv?\"\'\\]|$)', String.Escape), + ], + 'signature': [ + (r'=>', Operator, '#pop'), + (r'\)', Punctuation, '#pop'), + (r'[(,]', Punctuation, 'parameter'), + include('lasso'), + ], + 'parameter': [ + (r'\)', Punctuation, '#pop'), + (r'-?[a-z_][\w.]*', Name.Attribute, '#pop'), + (r'\.\.\.', Name.Builtin.Pseudo), + 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',', Punctuation), + include('whitespacecomments'), + ], + 'requiresignature': [ + (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'\.\.\.', Name.Builtin.Pseudo), + (r'[(,]', Punctuation), + include('whitespacecomments'), + ], + } + + def __init__(self, **options): + self.builtinshighlighting = get_bool_opt( + options, 'builtinshighlighting', True) + self.requiredelimiters = get_bool_opt( + options, 'requiredelimiters', False) + + self._builtins = set() + if self.builtinshighlighting: + from pygments.lexers._lassobuiltins import BUILTINS + for key, value in BUILTINS.items(): + self._builtins.update(value) + RegexLexer.__init__(self, **options) + + def get_tokens_unprocessed(self, text): + stack = ['root'] + if self.requiredelimiters: + stack.append('delimiters') + for index, token, value in \ + RegexLexer.get_tokens_unprocessed(self, text, stack): + if token is Name.Other: + if value.lower() in self._builtins: + yield index, Name.Builtin, value + continue + yield index, token, value + + def analyse_text(text): + rv = 0.0 + if 'bin/lasso9' in text: + rv += 0.8 + if re.search(r'<\?(=|lasso)', text, re.I): + rv += 0.4 + if re.search(r'local\(', text, re.I): + rv += 0.4 + if re.search(r'\[\n|\?>', text): + rv += 0.4 + return rv + + +class QmlLexer(RegexLexer): + """ + For QML files. See http://doc.qt.digia.com/4.7/qdeclarativeintroduction.html. + + *New in Pygments 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'] + filenames = ['*.qml',] + mimetypes = [ 'application/x-qml',] + + + # pasted from JavascriptLexer, with some additions + flags = re.DOTALL + tokens = { + 'commentsandwhitespace': [ + (r'\s+', Text), + (r'<!--', Comment), + (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'', Text, '#pop') + ], + 'badregex': [ + (r'\n', Text, '#pop') + ], + 'root' : [ + (r'^(?=\s|/|<!--)', Text, 'slashstartsregex'), + include('commentsandwhitespace'), + (r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|' + r'(<<|>>>?|==?|!=?|[-<>+*%&\|\^/])=?', Operator, 'slashstartsregex'), + (r'[{(\[;,]', Punctuation, 'slashstartsregex'), + (r'[})\].]', Punctuation), + + # QML insertions + (r'\bid\s*:\s*[A-Za-z][_A-Za-z.0-9]*',Keyword.Declaration, + 'slashstartsregex'), + (r'\b[A-Za-z][_A-Za-z.0-9]*\s*:',Keyword, 'slashstartsregex'), + + # the rest from JavascriptLexer + (r'(for|in|while|do|break|return|continue|switch|case|default|if|else|' + r'throw|try|catch|finally|new|delete|typeof|instanceof|void|' + r'this)\b', Keyword, 'slashstartsregex'), + (r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'), + (r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|' + r'extends|final|float|goto|implements|import|int|interface|long|native|' + r'package|private|protected|public|short|static|super|synchronized|throws|' + r'transient|volatile)\b', Keyword.Reserved), + (r'(true|false|null|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'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' + 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), + ] + }