From 10be9bec8a7969a40d4fa3483b8317e0131b1715 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 15 Oct 2014 21:32:31 +0200 Subject: all lexers: fix unescaped { and } so that the "regex" module can compile our regexes --- doc/docs/lexerdevelopment.rst | 2 +- pygments/lexers/business.py | 4 ++-- pygments/lexers/c_cpp.py | 4 ++-- pygments/lexers/configs.py | 4 ++-- pygments/lexers/console.py | 4 ++-- pygments/lexers/css.py | 16 +++++++------- pygments/lexers/d.py | 20 +++++++++--------- pygments/lexers/data.py | 8 +++---- pygments/lexers/diff.py | 4 ++-- pygments/lexers/dotnet.py | 2 +- pygments/lexers/dsls.py | 4 ++-- pygments/lexers/erlang.py | 16 +++++++------- pygments/lexers/fantom.py | 6 +++--- pygments/lexers/graphics.py | 4 ++-- pygments/lexers/installers.py | 2 +- pygments/lexers/int_fiction.py | 24 ++++++++++----------- pygments/lexers/javascript.py | 22 ++++++++++--------- pygments/lexers/jvm.py | 10 ++++----- pygments/lexers/lisp.py | 10 ++++----- pygments/lexers/markup.py | 7 +++--- pygments/lexers/ml.py | 36 +++++++++++++++---------------- pygments/lexers/nit.py | 16 +++++++------- pygments/lexers/nix.py | 2 +- pygments/lexers/objective.py | 6 +++--- pygments/lexers/parsers.py | 40 +++++++++++++++++------------------ pygments/lexers/perl.py | 4 ++-- pygments/lexers/rebol.py | 48 +++++++++++++++++++++--------------------- pygments/lexers/resource.py | 12 +++++------ pygments/lexers/ruby.py | 6 +++--- pygments/lexers/shell.py | 4 ++-- pygments/lexers/tcl.py | 6 +++--- pygments/lexers/templates.py | 6 +++--- pygments/lexers/theorem.py | 4 ++-- pygments/lexers/webmisc.py | 2 +- 34 files changed, 183 insertions(+), 182 deletions(-) diff --git a/doc/docs/lexerdevelopment.rst b/doc/docs/lexerdevelopment.rst index 6ea08dba..23bcb4f7 100644 --- a/doc/docs/lexerdevelopment.rst +++ b/doc/docs/lexerdevelopment.rst @@ -323,7 +323,7 @@ There are a few more things you can do with states: (r'[^}/]+', Text), include('comments'), (r'/', Text), - (r'}', Keyword, '#pop'), + (r'\}', Keyword, '#pop'), ] } diff --git a/pygments/lexers/business.py b/pygments/lexers/business.py index e2806664..4be1fd4a 100644 --- a/pygments/lexers/business.py +++ b/pygments/lexers/business.py @@ -475,8 +475,8 @@ class OpenEdgeLexer(RegexLexer): ], 'preprocessor': [ (r'[^{}]', Comment.Preproc), - (r'{', Comment.Preproc, '#push'), - (r'}', Comment.Preproc, '#pop'), + (r'\{', Comment.Preproc, '#push'), + (r'\}', Comment.Preproc, '#pop'), ], } diff --git a/pygments/lexers/c_cpp.py b/pygments/lexers/c_cpp.py index ac9cc7b8..86927b0e 100644 --- a/pygments/lexers/c_cpp.py +++ b/pygments/lexers/c_cpp.py @@ -110,8 +110,8 @@ class CFamilyLexer(RegexLexer): include('whitespace'), include('statements'), (';', Punctuation), - ('{', Punctuation, '#push'), - ('}', Punctuation, '#pop'), + (r'\{', Punctuation, '#push'), + (r'\}', Punctuation, '#pop'), ], 'string': [ (r'"', String, '#pop'), diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index 44475357..df346609 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -452,12 +452,12 @@ class NginxConfLexer(RegexLexer): include('base'), ], 'block': [ - (r'}', Punctuation, '#pop:2'), + (r'\}', Punctuation, '#pop:2'), (r'[^\s;#]+', Keyword.Namespace, 'stmt'), include('base'), ], 'stmt': [ - (r'{', Punctuation, 'block'), + (r'\{', Punctuation, 'block'), (r';', Punctuation, '#pop'), include('base'), ], diff --git a/pygments/lexers/console.py b/pygments/lexers/console.py index 334e7195..68aa70e2 100644 --- a/pygments/lexers/console.py +++ b/pygments/lexers/console.py @@ -55,8 +55,8 @@ class PyPyLogLexer(RegexLexer): tokens = { "root": [ - (r"\[\w+\] {jit-log-.*?$", Keyword, "jit-log"), - (r"\[\w+\] {jit-backend-counts$", Keyword, "jit-backend-counts"), + (r"\[\w+\] \{jit-log-.*?$", Keyword, "jit-log"), + (r"\[\w+\] \{jit-backend-counts$", Keyword, "jit-backend-counts"), include("extra-stuff"), ], "jit-log": [ diff --git a/pygments/lexers/css.py b/pygments/lexers/css.py index 091d4696..61a08d4b 100644 --- a/pygments/lexers/css.py +++ b/pygments/lexers/css.py @@ -38,7 +38,7 @@ class CssLexer(RegexLexer): 'basics': [ (r'\s+', Text), (r'/\*(?:.|\n)*?\*/', Comment), - (r'{', Punctuation, 'content'), + (r'\{', Punctuation, 'content'), (r'\:[\w-]+', Name.Decorator), (r'\.[\w-]+', Name.Class), (r'\#[\w-]+', Name.Function), @@ -49,17 +49,17 @@ class CssLexer(RegexLexer): (r"'(\\\\|\\'|[^'])*'", String.Single) ], 'atrule': [ - (r'{', Punctuation, 'atcontent'), + (r'\{', Punctuation, 'atcontent'), (r';', Punctuation, '#pop'), include('basics'), ], 'atcontent': [ include('basics'), - (r'}', Punctuation, '#pop:2'), + (r'\}', Punctuation, '#pop:2'), ], 'content': [ (r'\s+', Text), - (r'}', Punctuation, '#pop'), + (r'\}', Punctuation, '#pop'), (r'url\(.*?\)', String.Other), (r'^@.*?$', Comment.Preproc), (words(( @@ -268,7 +268,7 @@ common_sass_tokens = { (r'\#[a-z0-9]{1,6}', Number.Hex), (r'(-?\d+)(\%|[a-z]+)?', bygroups(Number.Integer, Keyword.Type)), (r'(-?\d*\.\d+)(\%|[a-z]+)?', bygroups(Number.Float, Keyword.Type)), - (r'#{', String.Interpol, 'interpolation'), + (r'#\{', String.Interpol, 'interpolation'), (r'[~\^\*!&%<>\|+=@:,./?-]+', Operator), (r'[\[\]()]+', Punctuation), (r'"', String.Double, 'string-double'), @@ -426,14 +426,14 @@ class SassLexer(ExtendedRegexLexer): 'old-style-attr': [ (r'[^\s:="\[]+', Name.Attribute), - (r'#{', String.Interpol, 'interpolation'), + (r'#\{', String.Interpol, 'interpolation'), (r'[ \t]*=', Operator, 'value'), default('value'), ], 'new-style-attr': [ (r'[^\s:="\[]+', Name.Attribute), - (r'#{', String.Interpol, 'interpolation'), + (r'#\{', String.Interpol, 'interpolation'), (r'[ \t]*[=:]', Operator, 'value'), ], @@ -480,7 +480,7 @@ class ScssLexer(RegexLexer): 'attr': [ (r'[^\s:="\[]+', Name.Attribute), - (r'#{', String.Interpol, 'interpolation'), + (r'#\{', String.Interpol, 'interpolation'), (r'[ \t]*:', Operator, 'value'), ], diff --git a/pygments/lexers/d.py b/pygments/lexers/d.py index c3c3dc1d..3337e66a 100644 --- a/pygments/lexers/d.py +++ b/pygments/lexers/d.py @@ -104,11 +104,11 @@ class DLexer(RegexLexer): (r'q"\[', String, 'delimited_bracket'), (r'q"\(', String, 'delimited_parenthesis'), (r'q"<', String, 'delimited_angle'), - (r'q"{', String, 'delimited_curly'), + (r'q"\{', String, 'delimited_curly'), (r'q"([a-zA-Z_]\w*)\n.*?\n\1"', String), (r'q"(.).*?\1"', String), # -- TokenString - (r'q{', String, 'token_string'), + (r'q\{', String, 'token_string'), # Attributes (r'@([a-zA-Z_]\w*)?', Name.Decorator), # Tokens @@ -127,13 +127,13 @@ class DLexer(RegexLexer): (r'[+/]', Comment.Multiline), ], 'token_string': [ - (r'{', Punctuation, 'token_string_nest'), - (r'}', String, '#pop'), + (r'\{', Punctuation, 'token_string_nest'), + (r'\}', String, '#pop'), include('root'), ], 'token_string_nest': [ - (r'{', Punctuation, '#push'), - (r'}', Punctuation, '#pop'), + (r'\{', Punctuation, '#push'), + (r'\}', Punctuation, '#pop'), include('root'), ], 'delimited_bracket': [ @@ -168,13 +168,13 @@ class DLexer(RegexLexer): ], 'delimited_curly': [ (r'[^{}]+', String), - (r'{', String, 'delimited_inside_curly'), - (r'}"', String, '#pop'), + (r'\{', String, 'delimited_inside_curly'), + (r'\}"', String, '#pop'), ], 'delimited_inside_curly': [ (r'[^{}]+', String), - (r'{', String, '#push'), - (r'}', String, '#pop'), + (r'\{', String, '#push'), + (r'\}', String, '#pop'), ], } diff --git a/pygments/lexers/data.py b/pygments/lexers/data.py index 6ea331f6..22821c15 100644 --- a/pygments/lexers/data.py +++ b/pygments/lexers/data.py @@ -476,14 +476,14 @@ class JsonLexer(RegexLexer): # comma terminates the attribute but expects more (r',', Punctuation, '#pop'), # a closing bracket terminates the entire object, so pop twice - (r'}', Punctuation, ('#pop', '#pop')), + (r'\}', Punctuation, ('#pop', '#pop')), ], # a json object - { attr, attr, ... } 'objectvalue': [ include('whitespace'), (r'"(\\\\|\\"|[^"])*"', Name.Tag, 'objectattribute'), - (r'}', Punctuation, '#pop'), + (r'\}', Punctuation, '#pop'), ], # json array - [ value, value, ... } @@ -491,14 +491,14 @@ class JsonLexer(RegexLexer): include('whitespace'), include('value'), (r',', Punctuation), - (r']', Punctuation, '#pop'), + (r'\]', Punctuation, '#pop'), ], # a json value - either a simple value or a complex value (object or array) 'value': [ include('whitespace'), include('simplevalue'), - (r'{', Punctuation, 'objectvalue'), + (r'\{', Punctuation, 'objectvalue'), (r'\[', Punctuation, 'arrayvalue'), ], diff --git a/pygments/lexers/diff.py b/pygments/lexers/diff.py index fe6435c5..a910a979 100644 --- a/pygments/lexers/diff.py +++ b/pygments/lexers/diff.py @@ -68,8 +68,8 @@ class DarcsPatchLexer(RegexLexer): 'root': [ (r'<', Operator), (r'>', Operator), - (r'{', Operator), - (r'}', Operator), + (r'\{', Operator), + (r'\}', Operator), (r'(\[)((?:TAG )?)(.*)(\n)(.*)(\*\*)(\d+)(\s?)(\])', bygroups(Operator, Keyword, Name, Text, Name, Operator, Literal.Date, Text, Operator)), diff --git a/pygments/lexers/dotnet.py b/pygments/lexers/dotnet.py index b26f6843..204b4a71 100644 --- a/pygments/lexers/dotnet.py +++ b/pygments/lexers/dotnet.py @@ -570,7 +570,7 @@ class FSharpLexer(RegexLexer): '!=', '#', '&&', '&', '\(', '\)', '\*', '\+', ',', '-\.', '->', '-', '\.\.', '\.', '::', ':=', ':>', ':', ';;', ';', '<-', '<\]', '<', '>\]', '>', '\?\?', '\?', '\[<', '\[\|', '\[', '\]', - '_', '`', '{', '\|\]', '\|', '}', '~', '<@@', '<@', '=', '@>', '@@>', + '_', '`', '\{', '\|\]', '\|', '\}', '~', '<@@', '<@', '=', '@>', '@@>', ] operators = r'[!$%&*+\./:<=>?@^|~-]' diff --git a/pygments/lexers/dsls.py b/pygments/lexers/dsls.py index e059ecfd..dcd15011 100644 --- a/pygments/lexers/dsls.py +++ b/pygments/lexers/dsls.py @@ -462,7 +462,7 @@ class PanLexer(RegexLexer): 'root': [ include('basic'), (r'\(', Keyword, 'paren'), - (r'{', Keyword, 'curly'), + (r'\{', Keyword, 'curly'), include('data'), ], 'basic': [ @@ -496,7 +496,7 @@ class PanLexer(RegexLexer): (r'\d+(?= |\Z)', Number), ], 'curly': [ - (r'}', Keyword, '#pop'), + (r'\}', Keyword, '#pop'), (r':-', Keyword), (r'\w+', Name.Variable), (r'[^}:"\'`$]+', Punctuation), diff --git a/pygments/lexers/erlang.py b/pygments/lexers/erlang.py index b8ed7ff2..ccd94564 100644 --- a/pygments/lexers/erlang.py +++ b/pygments/lexers/erlang.py @@ -323,9 +323,9 @@ class ElixirLexer(RegexLexer): name_re = r'(?:\.\.\.|[a-z_]%s*[!\?]?)' % alnum modname_re = r'[A-Z]%(alnum)s*(?:\.[A-Z]%(alnum)s*)*' % {'alnum': alnum} complex_name_re = r'(?:%s|%s|%s)' % (name_re, modname_re, ops_re) - special_atom_re = r'(?:\.\.\.|<<>>|%{}|%|{})' + special_atom_re = r'(?:\.\.\.|<<>>|%\{\}|%|\{\})' - long_hex_char_re = r'(\\x{)([\da-fA-F]+)(})' + long_hex_char_re = r'(\\x\{)([\da-fA-F]+)(\})' hex_char_re = r'(\\x[\da-fA-F]{1,2})' escape_char_re = r'(\\[abdefnrstv])' @@ -387,8 +387,8 @@ class ElixirLexer(RegexLexer): include('sigils'), - (r'%{', Punctuation, 'map_key'), - (r'{', Punctuation, 'tuple'), + (r'%\{', Punctuation, 'map_key'), + (r'\{', Punctuation, 'tuple'), ], 'heredoc_double': [ (r'^\s*"""', String.Heredoc, '#pop'), @@ -417,17 +417,17 @@ class ElixirLexer(RegexLexer): (escape_char_re, String.Escape), ], 'interpol': [ - (r'#{', String.Interpol, 'interpol_string'), + (r'#\{', String.Interpol, 'interpol_string'), ], 'interpol_string': [ - (r'}', String.Interpol, "#pop"), + (r'\}', String.Interpol, "#pop"), include('root') ], 'map_key': [ include('root'), (r':', Punctuation, 'map_val'), (r'=>', Punctuation, 'map_val'), - (r'}', Punctuation, '#pop'), + (r'\}', Punctuation, '#pop'), ], 'map_val': [ include('root'), @@ -436,7 +436,7 @@ class ElixirLexer(RegexLexer): ], 'tuple': [ include('root'), - (r'}', Punctuation, '#pop'), + (r'\}', Punctuation, '#pop'), ], } tokens.update(gen_elixir_string_rules('double', '"', String.Double)) diff --git a/pygments/lexers/fantom.py b/pygments/lexers/fantom.py index fd850336..c05cb8e8 100644 --- a/pygments/lexers/fantom.py +++ b/pygments/lexers/fantom.py @@ -215,7 +215,7 @@ class FantomLexer(RegexLexer): (r':|,', Punctuation), (r'(?:(\w+)(::))?(\w+)', bygroups(Name.Namespace, Punctuation, Name.Class)), - (r'{', Punctuation, '#pop') + (r'\{', Punctuation, '#pop') ], 'using': [ (r'[ \t]+', Text), # consume whitespaces @@ -235,7 +235,7 @@ class FantomLexer(RegexLexer): ], 'facet': [ (r'\s+', Text), - (r'{', Punctuation, 'facetFields'), + (r'\{', Punctuation, 'facetFields'), default('#pop') ], 'facetFields': [ @@ -244,7 +244,7 @@ class FantomLexer(RegexLexer): include('operators'), (r'\s+', Text), (r'(\s*)(\w+)(\s*)(=)', bygroups(Text, Name, Text, Operator)), - (r'}', Punctuation, '#pop'), + (r'\}', Punctuation, '#pop'), (r'.', Text) ], } diff --git a/pygments/lexers/graphics.py b/pygments/lexers/graphics.py index bed5f182..4ed12705 100644 --- a/pygments/lexers/graphics.py +++ b/pygments/lexers/graphics.py @@ -263,8 +263,8 @@ class AsymptoteLexer(RegexLexer): include('whitespace'), include('statements'), (';', Punctuation), - ('{', Punctuation, '#push'), - ('}', Punctuation, '#pop'), + (r'\{', Punctuation, '#push'), + (r'\}', Punctuation, '#pop'), ], 'string': [ (r"'", String, '#pop'), diff --git a/pygments/lexers/installers.py b/pygments/lexers/installers.py index 54369da1..53a7abc1 100644 --- a/pygments/lexers/installers.py +++ b/pygments/lexers/installers.py @@ -309,7 +309,7 @@ class DebianControlLexer(RegexLexer): (r'\|', Operator), (r'[\s]+', Text), (r'[}\)]\s*$', Text, '#pop'), - (r'}', Text), + (r'\}', Text), (r'[^,]$', Name.Function, '#pop'), (r'([\+\.a-zA-Z0-9-])(\s*)', bygroups(Name.Function, Text)), (r'\[.*?\]', Name.Entity), diff --git a/pygments/lexers/int_fiction.py b/pygments/lexers/int_fiction.py index cbac9e39..8c3a934c 100644 --- a/pygments/lexers/int_fiction.py +++ b/pygments/lexers/int_fiction.py @@ -848,7 +848,7 @@ class Tads3Lexer(RegexLexer): tokens = { 'root': [ (u'\ufeff', Text), - (r'{', Punctuation, 'object-body'), + (r'\{', Punctuation, 'object-body'), (r';+', Punctuation), (r'(?=(argcount|break|case|catch|continue|default|definingobj|' r'delegated|do|else|for|foreach|finally|goto|if|inherited|' @@ -869,13 +869,13 @@ class Tads3Lexer(RegexLexer): ], 'object-body/no-braces': [ (r';', Punctuation, '#pop'), - (r'{', Punctuation, ('#pop', 'object-body')), + (r'\{', Punctuation, ('#pop', 'object-body')), include('object-body') ], 'object-body': [ (r';', Punctuation), - (r'{', Punctuation, '#push'), - (r'}', Punctuation, '#pop'), + (r'\{', Punctuation, '#push'), + (r'\}', Punctuation, '#pop'), (r':', Punctuation, ('classes', 'class')), (r'(%s?)(%s*)(\()' % (_name, _ws), bygroups(Name.Function, using(this, state='whitespace'), @@ -900,7 +900,7 @@ class Tads3Lexer(RegexLexer): default('#pop:2') ], 'block?/root': [ - (r'{', Punctuation, ('#pop', 'block')), + (r'\{', Punctuation, ('#pop', 'block')), include('whitespace'), (r'(?=[[\'"<(:])', Text, # It might be a VerbRule macro. ('#pop', 'object-body/no-braces', 'grammar', 'grammar-rules')), @@ -908,14 +908,14 @@ class Tads3Lexer(RegexLexer): default(('#pop', 'object-body/no-braces')) ], 'block?': [ - (r'{', Punctuation, ('#pop', 'block')), + (r'\{', Punctuation, ('#pop', 'block')), include('whitespace'), default('#pop') ], 'block/basic': [ (r'[;:]+', Punctuation), - (r'{', Punctuation, '#push'), - (r'}', Punctuation, '#pop'), + (r'\{', Punctuation, '#push'), + (r'\}', Punctuation, '#pop'), (r'default\b', Keyword.Reserved), (r'(%s)(%s*)(:)' % (_name, _ws), bygroups(Name.Label, using(this, state='whitespace'), @@ -935,8 +935,8 @@ class Tads3Lexer(RegexLexer): include('whitespace'), (r'\(', Punctuation, ('#pop', 'more', 'main')), (r'\[', Punctuation, ('#pop', 'more/list', 'main')), - (r'{', Punctuation, ('#pop', 'more/inner', 'main/inner', - 'more/parameters', 'main/parameters')), + (r'\{', Punctuation, ('#pop', 'more/inner', 'main/inner', + 'more/parameters', 'main/parameters')), (r'\*|\.{3}', Punctuation, '#pop'), (r'(?i)0x[\da-f]+', Number.Hex, '#pop'), (r'(\d+\.(?!\.)\d*|\.\d+)([eE][-+]?\d+)?|\d+[eE][-+]?\d+', @@ -1057,7 +1057,7 @@ class Tads3Lexer(RegexLexer): include('main') ], 'more/inner': [ - (r'}', Punctuation, '#pop'), + (r'\}', Punctuation, '#pop'), (r',', Punctuation, 'main/inner'), (r'(in|step)\b', Keyword, 'main/inner'), include('more') @@ -1175,7 +1175,7 @@ class Tads3Lexer(RegexLexer): ], 'propertyset': [ (r'\(', Punctuation, ('more/parameters', 'main/parameters')), - (r'{', Punctuation, ('#pop', 'object-body')), + (r'\{', Punctuation, ('#pop', 'object-body')), include('whitespace') ], 'template': [ diff --git a/pygments/lexers/javascript.py b/pygments/lexers/javascript.py index 8b5f9c76..481243ef 100644 --- a/pygments/lexers/javascript.py +++ b/pygments/lexers/javascript.py @@ -22,6 +22,7 @@ __all__ = ['JavascriptLexer', 'KalLexer', 'LiveScriptLexer', 'DartLexer', 'TypeScriptLexer', 'LassoLexer', 'ObjectiveJLexer', 'CoffeeScriptLexer', 'MaskLexer'] + JS_IDENT_START = ('(?:[$_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Lo + uni.Nl + ']|\\\\u[a-fA-F0-9]{4})') JS_IDENT_PART = ('(?:[$_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Lo + uni.Nl @@ -29,6 +30,7 @@ JS_IDENT_PART = ('(?:[$_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Lo + uni.Nl + u'\u200c\u200d]|\\\\u[a-fA-F0-9]{4})') JS_IDENT = JS_IDENT_START + '(?:' + JS_IDENT_PART + ')*' + class JavascriptLexer(RegexLexer): """ For JavaScript source code. @@ -178,13 +180,13 @@ class KalLexer(RegexLexer): # hashmarks, quotes and backslashes must be parsed one at a time ], 'interpoling_string': [ - (r'}', String.Interpol, "#pop"), + (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.Interpol, "interpoling_string"), include('strings') ], 'sqs': [ @@ -195,7 +197,7 @@ class KalLexer(RegexLexer): 'tdqs': [ (r'"""', String, '#pop'), (r'\\.|\'|"', String), # no need to escape quotes in triple-string - (r'#{', String.Interpol, "interpoling_string"), + (r'#\{', String.Interpol, "interpoling_string"), include('strings'), ], 'tsqs': [ @@ -287,13 +289,13 @@ class LiveScriptLexer(RegexLexer): # hashmarks, quotes and backslashes must be parsed one at a time ], 'interpoling_string': [ - (r'}', String.Interpol, "#pop"), + (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.Interpol, "interpoling_string"), (r'#', String), include('strings') ], @@ -305,7 +307,7 @@ class LiveScriptLexer(RegexLexer): 'tdqs': [ (r'"""', String, '#pop'), (r'\\.|\'|"', String), # no need to escape quotes in triple-string - (r'#{', String.Interpol, "interpoling_string"), + (r'#\{', String.Interpol, "interpoling_string"), (r'#', String), include('strings'), ], @@ -1000,7 +1002,7 @@ class CoffeeScriptLexer(RegexLexer): 'multilineregex': [ (r'[^/#]+', String.Regex), (r'///([gim]+\b|\B)', String.Regex, '#pop'), - (r'#{', String.Interpol, 'interpoling_string'), + (r'#\{', String.Interpol, 'interpoling_string'), (r'[/#]', String.Regex), ], 'slashstartsregex': [ @@ -1054,13 +1056,13 @@ class CoffeeScriptLexer(RegexLexer): # hashmarks, quotes and backslashes must be parsed one at a time ], 'interpoling_string': [ - (r'}', String.Interpol, "#pop"), + (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.Interpol, "interpoling_string"), (r'#', String), include('strings') ], @@ -1072,7 +1074,7 @@ class CoffeeScriptLexer(RegexLexer): 'tdqs': [ (r'"""', String, '#pop'), (r'\\.|\'|"', String), # no need to escape quotes in triple-string - (r'#{', String.Interpol, "interpoling_string"), + (r'#\{', String.Interpol, "interpoling_string"), (r'#', String), include('strings'), ], diff --git a/pygments/lexers/jvm.py b/pygments/lexers/jvm.py index 136a0fd7..898cf415 100644 --- a/pygments/lexers/jvm.py +++ b/pygments/lexers/jvm.py @@ -289,7 +289,7 @@ class ScalaLexer(RegexLexer): (u'(%s|%s|`[^`]+`)(\\s*)(\\[)' % (idrest, op), bygroups(Name.Class, Text, Operator), 'typeparam'), (r'\s+', Text), - (r'{', Operator, '#pop'), + (r'\{', Operator, '#pop'), (r'\(', Operator, '#pop'), (r'//.*?\n', Comment.Single, '#pop'), (u'%s|%s|`[^`]+`' % (idrest, op), Name.Class, '#pop'), @@ -530,7 +530,7 @@ class IokeLexer(RegexLexer): 'interpolatableText': [ (r'(\\b|\\e|\\t|\\n|\\f|\\r|\\"|\\\\|\\#|\\\Z|\\u[0-9a-fA-F]{1,4}' r'|\\[0-3]?[0-7]?[0-7])', String.Escape), - (r'#{', Punctuation, 'textInterpolationRoot') + (r'#\{', Punctuation, 'textInterpolationRoot') ], 'text': [ @@ -546,7 +546,7 @@ class IokeLexer(RegexLexer): ], 'textInterpolationRoot': [ - (r'}', Punctuation, '#pop'), + (r'\}', Punctuation, '#pop'), include('root') ], @@ -695,7 +695,7 @@ class IokeLexer(RegexLexer): Operator), # Punctuation - (r'(\`\`|\`|\'\'|\'|\.|\,|@@|@|\[|\]|\(|\)|{|})', Punctuation), + (r'(\`\`|\`|\'\'|\'|\.|\,|@@|@|\[|\]|\(|\)|\{|\})', Punctuation), # kinds (r'[A-Z][\w!:?]*', Name.Class), @@ -1268,7 +1268,7 @@ class GoloLexer(RegexLexer): (r'[\'"\\]', String) ], 'stringescape': [ - (r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|' + (r'\\([\\abfnrtv"\']|\n|N\{.*?\}|u[a-fA-F0-9]{4}|' r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape) ], 'triplestring': [ diff --git a/pygments/lexers/lisp.py b/pygments/lexers/lisp.py index a0a08efe..c9a82d8e 100644 --- a/pygments/lexers/lisp.py +++ b/pygments/lexers/lisp.py @@ -120,7 +120,7 @@ class SchemeLexer(RegexLexer): # strings, symbols and characters (r'"(\\\\|\\"|[^"])*"', String), (r"'" + valid_name, String.Symbol), - (r"#\\([()/'\"._!§$%& ?=+-]{1}|[a-zA-Z0-9]+)", String.Char), + (r"#\\([()/'\"._!§$%& ?=+-]|[a-zA-Z0-9]+)", String.Char), # constants (r'(#t|#f)', Name.Constant), @@ -1444,7 +1444,7 @@ class NewLispLexer(RegexLexer): (r'"(\\\\|\\"|[^"])*"', String), # braces - (r"{", String, "bracestring"), + (r'\{', String, "bracestring"), # [text] ... [/text] delimited strings (r'\[text\]*', String, "tagstring"), @@ -1468,9 +1468,9 @@ class NewLispLexer(RegexLexer): # braced strings... 'bracestring': [ - ("{", String, "#push"), - ("}", String, "#pop"), - ("[^{}]+", String), + (r'\{', String, "#push"), + (r'\}', String, "#pop"), + ('[^{}]+', String), ], # tagged [text]...[/text] delimited strings... diff --git a/pygments/lexers/markup.py b/pygments/lexers/markup.py index 285c1350..75236a61 100644 --- a/pygments/lexers/markup.py +++ b/pygments/lexers/markup.py @@ -22,7 +22,7 @@ from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ from pygments.util import get_bool_opt, ClassNotFound __all__ = ['BBCodeLexer', 'MoinWikiLexer', 'RstLexer', 'TexLexer', 'GroffLexer', - 'MozPreprocHashLexer', 'MozPreprocPercentLexer', + 'MozPreprocHashLexer', 'MozPreprocPercentLexer', 'MozPreprocXulLexer', 'MozPreprocJavascriptLexer', 'MozPreprocCssLexer'] @@ -81,7 +81,7 @@ class MoinWikiLexer(RegexLexer): (r'^(=+)([^=]+)(=+)(\s*#.+)?$', bygroups(Generic.Heading, using(this), Generic.Heading, String)), # Literal code blocks, with optional shebang - (r'({{{)(\n#!.+)?', bygroups(Name.Builtin, Name.Namespace), 'codeblock'), + (r'(\{\{\{)(\n#!.+)?', bygroups(Name.Builtin, Name.Namespace), 'codeblock'), (r'(\'\'\'?|\|\||`|__|~~|\^|,,|::)', Comment), # Formatting # Lists (r'^( +)([.*-])( )', bygroups(Text, Name.Builtin, Text)), @@ -98,7 +98,7 @@ class MoinWikiLexer(RegexLexer): 'codeblock': [ (r'}}}', Name.Builtin, '#pop'), # these blocks are allowed to be nested in Trac, but not MoinMoin - (r'{{{', Text, '#push'), + (r'\{\{\{', Text, '#push'), (r'[^{}]+', Comment.Preproc), # slurp boring text (r'.', Comment.Preproc), # allow loose { or } ], @@ -441,7 +441,6 @@ class MozPreprocPercentLexer(MozPreprocHashLexer): filenames = [] mimetypes = [] - tokens = { 'root': [ (r'^%', Comment.Preproc, ('expr', 'exprstart')), diff --git a/pygments/lexers/ml.py b/pygments/lexers/ml.py index 81de39b9..c2d2bb12 100644 --- a/pygments/lexers/ml.py +++ b/pygments/lexers/ml.py @@ -113,8 +113,8 @@ class SMLLexer(RegexLexer): # the `|' is resolved - is it a case/handle expression, or function # definition by cases? (This is not how the Definition works, but # it's how MLton behaves, see http://mlton.org/SMLNJDeviations) - (r'\(|\[|{', Punctuation, 'main'), - (r'\)|\]|}', Punctuation, '#pop'), + (r'\(|\[|\{', Punctuation, 'main'), + (r'\)|\]|\}', Punctuation, '#pop'), (r'\b(let|if|local)\b(?!\')', Keyword.Reserved, ('main', 'main')), (r'\b(struct|sig|while)\b(?!\')', Keyword.Reserved, 'main'), (r'\b(do|else|end|in|then)\b(?!\')', Keyword.Reserved, '#pop'), @@ -376,10 +376,10 @@ class OcamlLexer(RegexLexer): 'type', 'value', 'val', 'virtual', 'when', 'while', 'with', ) keyopts = ( - '!=', '#', '&', '&&', '\(', '\)', '\*', '\+', ',', '-', - '-\.', '->', '\.', '\.\.', ':', '::', ':=', ':>', ';', ';;', '<', - '<-', '=', '>', '>]', '>}', '\?', '\?\?', '\[', '\[<', '\[>', '\[\|', - ']', '_', '`', '{', '{<', '\|', '\|]', '}', '~' + '!=', '#', '&', '&&', r'\(', r'\)', r'\*', r'\+', ',', '-', + r'-\.', '->', r'\.', r'\.\.', ':', '::', ':=', ':>', ';', ';;', '<', + '<-', '=', '>', '>]', r'>\}', r'\?', r'\?\?', r'\[', r'\[<', r'\[>', + r'\[\|', ']', '_', '`', r'\{', r'\{<', r'\|', r'\|]', r'\}', '~' ) operators = r'[!$%&*+\./:<=>?@^|~-]' @@ -526,8 +526,8 @@ class OpaLexer(RegexLexer): # inside a string, we are back in the string state # as a consequence, we must also push a state every time we find a # '{' or else we will have errors when parsing {} for instance - (r'{', Operator, '#push'), - (r'}', Operator, '#pop'), + (r'\{', Operator, '#push'), + (r'\}', Operator, '#pop'), # html literals # this is a much more strict that the actual parser, @@ -569,7 +569,7 @@ class OpaLexer(RegexLexer): # id literal, #something, or #{expr} (r'#'+ident_re, String.Single), - (r'#(?={)', String.Single), + (r'#(?=\{)', String.Single), # identifiers # this avoids to color '2' in 'a2' as an integer @@ -608,7 +608,7 @@ class OpaLexer(RegexLexer): 'type-1': [ include('comments-and-spaces'), (r'\(', Keyword.Type, ('#pop', 'type-tuple')), - (r'~?{', Keyword.Type, ('#pop', 'type-record')), + (r'~?\{', Keyword.Type, ('#pop', 'type-record')), (ident_re+r'\(', Keyword.Type, ('#pop', 'type-tuple')), (ident_re, Keyword.Type, '#pop'), ("'"+ident_re, Keyword.Type), @@ -671,8 +671,8 @@ class OpaLexer(RegexLexer): include('comments-and-spaces'), (r'[^{}/*]+', Keyword.Type), (r'[/*]', Keyword.Type), - (r'{', Keyword.Type, '#push'), - (r'}', Keyword.Type, '#pop'), + (r'\{', Keyword.Type, '#push'), + (r'\}', Keyword.Type, '#pop'), ], # 'type-tuple': [ @@ -687,7 +687,7 @@ class OpaLexer(RegexLexer): # ], # 'type-record':[ # include('comments-and-spaces'), - # (r'}', Keyword.Type, '#pop'), + # (r'\}', Keyword.Type, '#pop'), # (r'~?(?:\w+|`[^`]*`)', Keyword.Type, 'type-record-field-expr'), # ], # 'type-record-field-expr': [ @@ -706,13 +706,13 @@ class OpaLexer(RegexLexer): 'string': [ (r'[^\\"{]+', String.Double), (r'"', String.Double, '#pop'), - (r'{', Operator, 'root'), + (r'\{', Operator, 'root'), include('escape-sequence'), ], 'single-string': [ (r'[^\\\'{]+', String.Double), (r'\'', String.Double, '#pop'), - (r'{', Operator, 'root'), + (r'\{', Operator, 'root'), include('escape-sequence'), ], @@ -747,9 +747,9 @@ class OpaLexer(RegexLexer): (r"'", String.Single, ('#pop', 'single-string')), (r'"', String.Single, ('#pop', 'string')), (r'#'+ident_re, String.Single, '#pop'), - (r'#(?={)', String.Single, ('#pop', 'root')), + (r'#(?=\{)', String.Single, ('#pop', 'root')), (r'[^"\'{`=<>]+', String.Single, '#pop'), - (r'{', Operator, ('#pop', 'root')), # this is a tail call! + (r'\{', Operator, ('#pop', 'root')), # this is a tail call! ], # we should probably deal with '\' escapes here @@ -757,7 +757,7 @@ class OpaLexer(RegexLexer): (r'