ThirdParty/Pygments/pygments/lexers/webmisc.py

changeset 4697
c2e9bf425554
parent 4172
4f20dba37ab6
child 5713
6762afd9f963
diff -r bf4d19a7cade -r c2e9bf425554 ThirdParty/Pygments/pygments/lexers/webmisc.py
--- a/ThirdParty/Pygments/pygments/lexers/webmisc.py	Sun Jan 24 16:15:58 2016 +0100
+++ b/ThirdParty/Pygments/pygments/lexers/webmisc.py	Sun Jan 24 19:28:37 2016 +0100
@@ -5,7 +5,7 @@
 
     Lexers for misc. web stuff.
 
-    :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
+    :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
     :license: BSD, see LICENSE for details.
 """
 
@@ -191,6 +191,14 @@
         lexer.xquery_parse_state.append('operator')
         ctx.pos = match.end()
 
+    def pushstate_operator_map_callback(lexer, match, ctx):
+        yield match.start(), Keyword, match.group(1)
+        yield match.start(), Text, match.group(2)
+        yield match.start(), Punctuation, match.group(3)
+        ctx.stack = ['root']
+        lexer.xquery_parse_state.append('operator')
+        ctx.pos = match.end()
+
     def pushstate_operator_root_validate(lexer, match, ctx):
         yield match.start(), Keyword, match.group(1)
         yield match.start(), Text, match.group(2)
@@ -333,15 +341,16 @@
             (r'(\{)', pushstate_root_callback),
             (r'then|else|external|at|div|except', Keyword, 'root'),
             (r'order by', Keyword, 'root'),
+            (r'group by', Keyword, 'root'),
             (r'is|mod|order\s+by|stable\s+order\s+by', Keyword, 'root'),
             (r'and|or', Operator.Word, 'root'),
             (r'(eq|ge|gt|le|lt|ne|idiv|intersect|in)(?=\b)',
              Operator.Word, 'root'),
-            (r'return|satisfies|to|union|where|preserve\s+strip',
+            (r'return|satisfies|to|union|where|count|preserve\s+strip',
              Keyword, 'root'),
-            (r'(>=|>>|>|<=|<<|<|-|\*|!=|\+|\|\||\||:=|=)',
+            (r'(>=|>>|>|<=|<<|<|-|\*|!=|\+|\|\||\||:=|=|!)',
              operator_root_callback),
-            (r'(::|;|\[|//|/|,)',
+            (r'(::|:|;|\[|//|/|,)',
              punctuation_root_callback),
             (r'(castable|cast)(\s+)(as)\b',
              bygroups(Keyword, Text, Keyword), 'singletype'),
@@ -349,18 +358,32 @@
              bygroups(Keyword, Text, Keyword), 'itemtype'),
             (r'(treat)(\s+)(as)\b',
              bygroups(Keyword, Text, Keyword), 'itemtype'),
+            (r'(case)(\s+)(' + stringdouble + ')', bygroups(Keyword, Text, String.Double), 'itemtype'),
+            (r'(case)(\s+)(' + stringsingle + ')', bygroups(Keyword, Text, String.Single), 'itemtype'),
             (r'(case|as)\b', Keyword, 'itemtype'),
             (r'(\))(\s*)(as)',
              bygroups(Punctuation, Text, Keyword), 'itemtype'),
             (r'\$', Name.Variable, 'varname'),
-            (r'(for|let)(\s+)(\$)',
+            (r'(for|let|previous|next)(\s+)(\$)',
              bygroups(Keyword, Text, Name.Variable), 'varname'),
+            (r'(for)(\s+)(tumbling|sliding)(\s+)(window)(\s+)(\$)',
+             bygroups(Keyword, Text, Keyword, Text, Keyword, Text, Name.Variable), 'varname'),
             # (r'\)|\?|\]', Punctuation, '#push'),
             (r'\)|\?|\]', Punctuation),
             (r'(empty)(\s+)(greatest|least)', bygroups(Keyword, Text, Keyword)),
             (r'ascending|descending|default', Keyword, '#push'),
+            (r'(allowing)(\s+)(empty)', bygroups(Keyword, Text, Keyword)),
             (r'external', Keyword),
+            (r'(start|when|end)', Keyword, 'root'),
+            (r'(only)(\s+)(end)', bygroups(Keyword, Text, Keyword), 'root'),
             (r'collation', Keyword, 'uritooperator'),
+
+            # eXist specific XQUF
+            (r'(into|following|preceding|with)', Keyword, 'root'),
+
+            # support for current context on rhs of Simple Map Operator
+            (r'\.', Operator),
+
             # finally catch all string literals and stay in operator state
             (stringdouble, String.Double),
             (stringsingle, String.Single),
@@ -394,11 +417,24 @@
             (r'preserve|no-preserve', Keyword),
             (r',', Punctuation),
         ],
+        'annotationname':[
+            (r'\(:', Comment, 'comment'),
+            (qname, Name.Decorator),
+            (r'(\()(' + stringdouble + ')', bygroups(Punctuation, String.Double)),
+            (r'(\()(' + stringsingle + ')', bygroups(Punctuation, String.Single)),
+            (r'(\,)(\s+)(' + stringdouble + ')', bygroups(Punctuation, Text, String.Double)),
+            (r'(\,)(\s+)(' + stringsingle + ')', bygroups(Punctuation, Text, String.Single)),
+            (r'\)', Punctuation),
+            (r'(\s+)(\%)', bygroups(Text, Name.Decorator), 'annotationname'),
+            (r'(\s+)(variable)(\s+)(\$)', bygroups(Text, Keyword.Declaration, Text, Name.Variable), 'varname'),
+            (r'(\s+)(function)(\s+)', bygroups(Text, Keyword.Declaration, Text), 'root')
+        ],
         'varname': [
             (r'\(:', Comment, 'comment'),
-            (qname, Name.Variable, 'operator'),
+            (r'(' + qname + ')(\()?', bygroups(Name, Punctuation), 'operator'),
         ],
         'singletype': [
+            include('whitespace'),
             (r'\(:', Comment, 'comment'),
             (ncname + r'(:\*)', Name.Variable, 'operator'),
             (qname, Name.Variable, 'operator'),
@@ -406,7 +442,7 @@
         'itemtype': [
             include('whitespace'),
             (r'\(:', Comment, 'comment'),
-            (r'\$', Punctuation, 'varname'),
+            (r'\$', Name.Variable, 'varname'),
             (r'(void)(\s*)(\()(\s*)(\))',
              bygroups(Keyword, Text, Punctuation, Text, Punctuation), 'operator'),
             (r'(element|attribute|schema-element|schema-attribute|comment|text|'
@@ -419,14 +455,14 @@
             (r'(item)(\s*)(\()(\s*)(\))(?=[*+?])',
              bygroups(Keyword, Text, Punctuation, Text, Punctuation),
              'occurrenceindicator'),
-            (r'\(\#', Punctuation, 'pragma'),
+            (r'(\(\#)(\s*)', bygroups(Punctuation, Text), 'pragma'),
             (r';', Punctuation, '#pop'),
             (r'then|else', Keyword, '#pop'),
             (r'(at)(\s+)(' + stringdouble + ')',
              bygroups(Keyword, Text, String.Double), 'namespacedecl'),
             (r'(at)(\s+)(' + stringsingle + ')',
              bygroups(Keyword, Text, String.Single), 'namespacedecl'),
-            (r'except|intersect|in|is|return|satisfies|to|union|where',
+            (r'except|intersect|in|is|return|satisfies|to|union|where|count',
              Keyword, 'root'),
             (r'and|div|eq|ge|gt|le|lt|ne|idiv|mod|or', Operator.Word, 'root'),
             (r':=|=|,|>=|>>|>|\[|\(|<=|<<|<|-|!=|\|\||\|', Operator, 'root'),
@@ -437,9 +473,12 @@
              bygroups(Keyword, Text, Keyword), 'singletype'),
             (r'(treat)(\s+)(as)', bygroups(Keyword, Text, Keyword)),
             (r'(instance)(\s+)(of)', bygroups(Keyword, Text, Keyword)),
+            (r'(case)(\s+)(' + stringdouble + ')', bygroups(Keyword, Text, String.Double), 'itemtype'),
+            (r'(case)(\s+)(' + stringsingle + ')', bygroups(Keyword, Text, String.Single), 'itemtype'),
             (r'case|as', Keyword, 'itemtype'),
             (r'(\))(\s*)(as)', bygroups(Operator, Text, Keyword), 'itemtype'),
             (ncname + r':\*', Keyword.Type, 'operator'),
+            (r'(function|map|array)(\()', bygroups(Keyword.Type, Punctuation)),
             (qname, Keyword.Type, 'occurrenceindicator'),
         ],
         'kindtest': [
@@ -530,6 +569,7 @@
             (qname, Name.Tag),
         ],
         'xmlspace_decl': [
+            include('whitespace'),
             (r'\(:', Comment, 'comment'),
             (r'preserve|strip', Keyword, '#pop'),
         ],
@@ -589,39 +629,46 @@
             (r'(\d+)', Number.Integer, 'operator'),
             (r'(\.\.|\.|\))', Punctuation, 'operator'),
             (r'(declare)(\s+)(construction)',
-             bygroups(Keyword, Text, Keyword), 'operator'),
+             bygroups(Keyword.Declaration, Text, Keyword.Declaration), 'operator'),
             (r'(declare)(\s+)(default)(\s+)(order)',
-             bygroups(Keyword, Text, Keyword, Text, Keyword), 'operator'),
+             bygroups(Keyword.Declaration, Text, Keyword.Declaration, Text, Keyword.Declaration), 'operator'),
+            (r'(declare)(\s+)(context)(\s+)(item)',
+             bygroups(Keyword.Declaration, Text, Keyword.Declaration, Text, Keyword.Declaration), 'operator'),
             (ncname + ':\*', Name, 'operator'),
             ('\*:'+ncname, Name.Tag, 'operator'),
             ('\*', Name.Tag, 'operator'),
             (stringdouble, String.Double, 'operator'),
             (stringsingle, String.Single, 'operator'),
 
-            (r'(\})', popstate_callback),
+            (r'(\}|\])', popstate_callback),
 
             # NAMESPACE DECL
             (r'(declare)(\s+)(default)(\s+)(collation)',
-             bygroups(Keyword, Text, Keyword, Text, Keyword)),
+             bygroups(Keyword.Declaration, Text, Keyword.Declaration, Text, Keyword.Declaration)),
             (r'(module|declare)(\s+)(namespace)',
-             bygroups(Keyword, Text, Keyword), 'namespacedecl'),
+             bygroups(Keyword.Declaration, Text, Keyword.Declaration), 'namespacedecl'),
             (r'(declare)(\s+)(base-uri)',
-             bygroups(Keyword, Text, Keyword), 'namespacedecl'),
+             bygroups(Keyword.Declaration, Text, Keyword.Declaration), 'namespacedecl'),
 
             # NAMESPACE KEYWORD
             (r'(declare)(\s+)(default)(\s+)(element|function)',
-             bygroups(Keyword, Text, Keyword, Text, Keyword), 'namespacekeyword'),
+             bygroups(Keyword.Declaration, Text, Keyword.Declaration, Text, Keyword.Declaration), 'namespacekeyword'),
             (r'(import)(\s+)(schema|module)',
              bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'namespacekeyword'),
             (r'(declare)(\s+)(copy-namespaces)',
-             bygroups(Keyword, Text, Keyword), 'namespacekeyword'),
+             bygroups(Keyword.Declaration, Text, Keyword.Declaration), 'namespacekeyword'),
 
             # VARNAMEs
             (r'(for|let|some|every)(\s+)(\$)',
              bygroups(Keyword, Text, Name.Variable), 'varname'),
+            (r'(for)(\s+)(tumbling|sliding)(\s+)(window)(\s+)(\$)',
+             bygroups(Keyword, Text, Keyword, Text, Keyword, Text, Name.Variable), 'varname'),
             (r'\$', Name.Variable, 'varname'),
             (r'(declare)(\s+)(variable)(\s+)(\$)',
-             bygroups(Keyword, Text, Keyword, Text, Name.Variable), 'varname'),
+             bygroups(Keyword.Declaration, Text, Keyword.Declaration, Text, Name.Variable), 'varname'),
+
+            # ANNOTATED GLOBAL VARIABLES AND FUNCTIONS
+            (r'(declare)(\s+)(\%)', bygroups(Keyword.Declaration, Text, Name.Decorator), 'annotationname'),
 
             # ITEMTYPE
             (r'(\))(\s+)(as)', bygroups(Operator, Text, Keyword), 'itemtype'),
@@ -643,13 +690,14 @@
             (r'(<)', pushstate_operator_starttag_callback),
 
             (r'(declare)(\s+)(boundary-space)',
-             bygroups(Keyword, Text, Keyword), 'xmlspace_decl'),
+             bygroups(Keyword.Declaration, Text, Keyword.Declaration), 'xmlspace_decl'),
 
             (r'(validate)(\s+)(lax|strict)',
              pushstate_operator_root_validate_withmode),
             (r'(validate)(\s*)(\{)', pushstate_operator_root_validate),
             (r'(typeswitch)(\s*)(\()', bygroups(Keyword, Text, Punctuation)),
-            (r'(element|attribute)(\s*)(\{)',
+            (r'(switch)(\s*)(\()', bygroups(Keyword, Text, Punctuation)),
+            (r'(element|attribute|namespace)(\s*)(\{)',
              pushstate_operator_root_construct_callback),
 
             (r'(document|text|processing-instruction|comment)(\s*)(\{)',
@@ -661,30 +709,33 @@
             (r'(element)(\s+)(?=' + qname + r')',
              bygroups(Keyword, Text), 'element_qname'),
             # PROCESSING_INSTRUCTION
-            (r'(processing-instruction)(\s+)(' + ncname + r')(\s*)(\{)',
+            (r'(processing-instruction|namespace)(\s+)(' + ncname + r')(\s*)(\{)',
              bygroups(Keyword, Text, Name.Variable, Text, Punctuation),
              'operator'),
 
             (r'(declare|define)(\s+)(function)',
-             bygroups(Keyword, Text, Keyword)),
+             bygroups(Keyword.Declaration, Text, Keyword.Declaration)),
 
-            (r'(\{)', pushstate_operator_root_callback),
+            (r'(\{|\[)', pushstate_operator_root_callback),
 
             (r'(unordered|ordered)(\s*)(\{)',
              pushstate_operator_order_callback),
 
+            (r'(map|array)(\s*)(\{)',
+             pushstate_operator_map_callback),
+
             (r'(declare)(\s+)(ordering)',
-             bygroups(Keyword, Text, Keyword), 'declareordering'),
+             bygroups(Keyword.Declaration, Text, Keyword.Declaration), 'declareordering'),
 
             (r'(xquery)(\s+)(version)',
              bygroups(Keyword.Pseudo, Text, Keyword.Pseudo), 'xqueryversion'),
 
-            (r'(\(#)', Punctuation, 'pragma'),
+            (r'(\(#)(\s*)', bygroups(Punctuation, Text), 'pragma'),
 
             # sometimes return can occur in root state
             (r'return', Keyword),
 
-            (r'(declare)(\s+)(option)', bygroups(Keyword, Text, Keyword),
+            (r'(declare)(\s+)(option)', bygroups(Keyword.Declaration, Text, Keyword.Declaration),
              'option'),
 
             # URI LITERALS - single and double quoted
@@ -700,21 +751,28 @@
 
             (r'then|else', Keyword),
 
-            # ML specific
+            # eXist specific XQUF
+            (r'(update)(\s*)(insert|delete|replace|value|rename)', bygroups(Keyword, Text, Keyword)),
+            (r'(into|following|preceding|with)', Keyword),
+
+            # Marklogic specific
             (r'(try)(\s*)', bygroups(Keyword, Text), 'root'),
             (r'(catch)(\s*)(\()(\$)',
              bygroups(Keyword, Text, Punctuation, Name.Variable), 'varname'),
 
-            (r'(@'+qname+')', Name.Attribute),
-            (r'(@'+ncname+')', Name.Attribute),
-            (r'@\*:'+ncname, Name.Attribute),
-            (r'(@)', Name.Attribute),
+
+            (r'(@'+qname+')', Name.Attribute, 'operator'),
+            (r'(@'+ncname+')', Name.Attribute, 'operator'),
+            (r'@\*:'+ncname, Name.Attribute, 'operator'),
+            (r'@\*', Name.Attribute, 'operator'),
+            (r'(@)', Name.Attribute, 'operator'),
 
             (r'//|/|\+|-|;|,|\(|\)', Punctuation),
 
             # STANDALONE QNAMES
             (qname + r'(?=\s*\{)', Name.Tag, 'qname_braren'),
             (qname + r'(?=\s*\([^:])', Name.Function, 'qname_braren'),
+            (r'(' + qname + ')(#)([0-9]+)', bygroups(Name.Function, Keyword.Type, Number.Integer)),
             (qname, Name.Tag, 'operator'),
         ]
     }
@@ -731,9 +789,9 @@
     # JavascriptLexer above.
 
     name = 'QML'
-    aliases = ['qml']
-    filenames = ['*.qml']
-    mimetypes = ['application/x-qml']
+    aliases = ['qml', 'qbs']
+    filenames = ['*.qml', '*.qbs']
+    mimetypes = ['application/x-qml', 'application/x-qt.qbs+qml']
 
     # pasted from JavascriptLexer, with some additions
     flags = re.DOTALL | re.MULTILINE
@@ -798,10 +856,11 @@
     Syntax rules of Cirru can be found at:
     http://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
+    * using ``()`` for expressions, but restricted in a same line
+    * using ``""`` for strings, with ``\`` for escaping chars
+    * using ``$`` as folding operator
+    * using ``,`` as unfolding operator
+    * using indentations for nested blocks
 
     .. versionadded:: 2.0
     """
@@ -822,16 +881,16 @@
             (r'.', String.Escape, '#pop'),
         ],
         'function': [
+            (r'\,', Operator, '#pop'),
             (r'[^\s"()]+', Name.Function, '#pop'),
             (r'\)', Operator, '#pop'),
             (r'(?=\n)', Text, '#pop'),
             (r'\(', Operator, '#push'),
             (r'"', String, ('#pop', 'string')),
             (r'[ ]+', Text.Whitespace),
-            (r'\,', Operator, '#pop'),
         ],
         'line': [
-            (r'\$', Operator, 'function'),
+            (r'(?<!\w)\$(?!\w)', Operator, 'function'),
             (r'\(', Operator, 'function'),
             (r'\)', Operator),
             (r'\n', Text, '#pop'),

eric ide

mercurial