From 79bf469639bcd53defbd53f5e857d955a5b9b19b Mon Sep 17 00:00:00 2001 From: jmzambon Date: Fri, 26 Aug 2022 18:54:27 +0200 Subject: [PATCH 1/8] Fix syntax highlighting of INI language doesn't parse comments present on same line #2161 --- pygments/lexers/configs.py | 2 +- tests/examplefiles/ini/test.ini | 4 ++-- tests/examplefiles/ini/test.ini.output | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index 1209e4e70f..c45849815a 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -46,7 +46,7 @@ class IniLexer(RegexLexer): (r'\s+', Whitespace), (r'[;#].*', Comment.Single), (r'\[.*?\]$', Keyword), - (r'(.*?)([ \t]*)(=)([ \t]*)([^\t\n]*)', + (r'(.*?)([  \t]*)(=)([  \t]*)([^;#\n]*)', bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String)), # standalone option, supported by some INI parsers (r'(.+?)$', Name.Attribute), diff --git a/tests/examplefiles/ini/test.ini b/tests/examplefiles/ini/test.ini index a447803de7..f7056407e1 100644 --- a/tests/examplefiles/ini/test.ini +++ b/tests/examplefiles/ini/test.ini @@ -1,7 +1,7 @@ [section] -foo = bar -continued = foo +foo = bar ; inline comment +continued = foo # inline comment baz conttwo = foo diff --git a/tests/examplefiles/ini/test.ini.output b/tests/examplefiles/ini/test.ini.output index 4e7e3a59fb..9dd1d513fa 100644 --- a/tests/examplefiles/ini/test.ini.output +++ b/tests/examplefiles/ini/test.ini.output @@ -5,14 +5,16 @@ ' ' Text.Whitespace '=' Operator ' ' Text.Whitespace -'bar' Literal.String +'bar ' Literal.String +'; inline comment' Comment.Single '\n' Text.Whitespace 'continued' Name.Attribute ' ' Text.Whitespace '=' Operator ' ' Text.Whitespace -'foo' Literal.String +'foo ' Literal.String +'# inline comment' Comment.Single '\n ' Text.Whitespace 'baz' Name.Attribute '\n' Text.Whitespace From 01f3e4e99fa951f69da4d4de931a2c9784b921e1 Mon Sep 17 00:00:00 2001 From: jmzambon Date: Fri, 26 Aug 2022 18:54:27 +0200 Subject: [PATCH 2/8] Fix syntax highlighting of INI language doesn't parse comments present on same line #2161 Add also support for line continuation in values and comments. --- pygments/lexers/configs.py | 9 +++++++-- tests/examplefiles/ini/test.ini | 12 +++++++++--- tests/examplefiles/ini/test.ini.output | 6 ++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index 1209e4e70f..963503e2a4 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -46,11 +46,16 @@ class IniLexer(RegexLexer): (r'\s+', Whitespace), (r'[;#].*', Comment.Single), (r'\[.*?\]$', Keyword), - (r'(.*?)([ \t]*)(=)([ \t]*)([^\t\n]*)', + (r'(.*?)([  \t]*)(=)([  \t]*)([^;#\n]*[  \t]\\\n)', + bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String), "value"), + (r'(.*?)([  \t]*)(=)([  \t]*)([^;#\n]*)', bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String)), - # standalone option, supported by some INI parsers + # # standalone option, supported by some INI parsers (r'(.+?)$', Name.Attribute), ], + 'value': [ # line continuation + (r'[^;#=]+(? Date: Sat, 27 Aug 2022 21:01:40 +0200 Subject: [PATCH 3/8] Update test.ini.output. --- tests/examplefiles/ini/test.ini.output | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/examplefiles/ini/test.ini.output b/tests/examplefiles/ini/test.ini.output index 9dd1d513fa..a6ef58ce9f 100644 --- a/tests/examplefiles/ini/test.ini.output +++ b/tests/examplefiles/ini/test.ini.output @@ -1,4 +1,4 @@ -'[section]' Keyword +'[section1]' Keyword '\n\n' Text.Whitespace 'foo' Name.Attribute @@ -14,7 +14,9 @@ '=' Operator ' ' Text.Whitespace 'foo ' Literal.String -'# inline comment' Comment.Single +'# inline comment with \\' Comment.Single +'\n ' Text.Whitespace +'# line continuation' Comment.Single '\n ' Text.Whitespace 'baz' Name.Attribute '\n' Text.Whitespace @@ -30,4 +32,22 @@ '\n' Text.Whitespace '# comment' Comment.Single +'\n\n' Text.Whitespace + +'[section2]' Keyword +'\n\n' Text.Whitespace + +'my_array' Name.Attribute +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +"Asia, Africa, 'North America', South America, \\\n" Literal.String + +' Antarctica, Europe, Australia\n' Literal.String + +'foo' Name.Attribute +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'bar' Literal.String '\n' Text.Whitespace From b54962b81e8b8ece7c5e49677d64dc7f27daa809 Mon Sep 17 00:00:00 2001 From: jmzambon Date: Sun, 28 Aug 2022 10:22:19 +0200 Subject: [PATCH 4/8] Fix small bug with line continuation. --- pygments/lexers/configs.py | 3 ++- tests/examplefiles/ini/test.ini | 2 ++ tests/examplefiles/ini/test.ini.output | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index e2d05bdc44..ab9f5ff9ba 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -54,7 +54,8 @@ class IniLexer(RegexLexer): (r'(.+?)$', Name.Attribute), ], 'value': [ # line continuation - (r'[^;#=]+(? Date: Tue, 30 Aug 2022 21:45:43 +0200 Subject: [PATCH 5/8] Ensure spaces outside strings are all whitespaces. --- pygments/lexers/configs.py | 11 +++++++---- tests/examplefiles/ini/test.ini.output | 13 ++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index ab9f5ff9ba..04b09cf4e7 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -46,15 +46,18 @@ class IniLexer(RegexLexer): (r'\s+', Whitespace), (r'[;#].*', Comment.Single), (r'\[.*?\]$', Keyword), - (r'(.*?)([  \t]*)(=)([  \t]*)([^;#\n]*[  \t]\\\n)', - bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String), "value"), - (r'(.*?)([  \t]*)(=)([  \t]*)([^;#\n]*)', + (r'(.*?)([  \t]*)(=)([  \t]*)([^;#\n]*)(\\)(\s+)', + bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String, Text, Whitespace), + "value"), + (r'(.*?)([  \t]*)(=)([  \t]*)([^ ;#\n]*(?: [^ ;#\n]+)*)', bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String)), # standalone option, supported by some INI parsers (r'(.+?)$', Name.Attribute), ], 'value': [ # line continuation - (r'.*\\[ \t]*\n', String), + (r'\s+', Whitespace), + (r'(\s*)(.*)(\\)([ \t]*)', + bygroups(Whitespace, String, Text, Whitespace)), (r'.*$', String, "#pop"), ], } diff --git a/tests/examplefiles/ini/test.ini.output b/tests/examplefiles/ini/test.ini.output index 0b79e410e0..27a91956fc 100644 --- a/tests/examplefiles/ini/test.ini.output +++ b/tests/examplefiles/ini/test.ini.output @@ -5,7 +5,8 @@ ' ' Text.Whitespace '=' Operator ' ' Text.Whitespace -'bar ' Literal.String +'bar' Literal.String +' ' Text.Whitespace '; inline comment' Comment.Single '\n' Text.Whitespace @@ -13,7 +14,8 @@ ' ' Text.Whitespace '=' Operator ' ' Text.Whitespace -'foo ' Literal.String +'foo' Literal.String +' ' Text.Whitespace '# inline comment with \\' Comment.Single '\n ' Text.Whitespace '# line continuation' Comment.Single @@ -41,9 +43,10 @@ ' ' Text.Whitespace '=' Operator ' ' Text.Whitespace -"Asia, Africa, 'North America', South America, \\\n" Literal.String - -' Antarctica, Europe, Australia' Literal.String +"Asia, Africa, 'North America', South America, " Literal.String +'\\' Text +'\n ' Text.Whitespace +'Antarctica, Europe, Australia' Literal.String '\n\n' Text.Whitespace 'implicit_boolean' Name.Attribute From cb4543d22b6edc2b9510c14bdebf460350e0624d Mon Sep 17 00:00:00 2001 From: jmzambon Date: Tue, 30 Aug 2022 22:24:50 +0200 Subject: [PATCH 6/8] Add support for colon separator. --- pygments/lexers/configs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index 04b09cf4e7..96a40e6f55 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -45,11 +45,11 @@ class IniLexer(RegexLexer): 'root': [ (r'\s+', Whitespace), (r'[;#].*', Comment.Single), - (r'\[.*?\]$', Keyword), - (r'(.*?)([  \t]*)(=)([  \t]*)([^;#\n]*)(\\)(\s+)', + (r'(\[.*?\])([ \t]*)$', bygroups(Keyword, Whitespace)), + (r'(.*?)([  \t]*)([=:])([  \t]*)([^;#\n]*)(\\)(\s+)', bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String, Text, Whitespace), "value"), - (r'(.*?)([  \t]*)(=)([  \t]*)([^ ;#\n]*(?: [^ ;#\n]+)*)', + (r'(.*?)([  \t]*)([=:])([  \t]*)([^ ;#\n]*(?: +[^ ;#\n]+)*)', bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String)), # standalone option, supported by some INI parsers (r'(.+?)$', Name.Attribute), From 18600773d5546cfcb5ef28bf93363142947d7a33 Mon Sep 17 00:00:00 2001 From: jmzambon Date: Wed, 14 Sep 2022 19:01:17 +0200 Subject: [PATCH 7/8] Update pygments/lexers/configs.py Remove non-breaking space that make no sense. Co-authored-by: Jean Abou-Samra --- pygments/lexers/configs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index 96a40e6f55..4aed513c77 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -46,7 +46,7 @@ class IniLexer(RegexLexer): (r'\s+', Whitespace), (r'[;#].*', Comment.Single), (r'(\[.*?\])([ \t]*)$', bygroups(Keyword, Whitespace)), - (r'(.*?)([  \t]*)([=:])([  \t]*)([^;#\n]*)(\\)(\s+)', + (r'(.*?)([  \t]*)([=:])([ \t]*)([^;#\n]*)(\\)(\s+)', bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String, Text, Whitespace), "value"), (r'(.*?)([  \t]*)([=:])([  \t]*)([^ ;#\n]*(?: +[^ ;#\n]+)*)', From 52fcb2fd2add53bf59d0c16b0d56e8a0df1f20da Mon Sep 17 00:00:00 2001 From: jmzambon Date: Wed, 14 Sep 2022 19:02:14 +0200 Subject: [PATCH 8/8] Update pygments/lexers/configs.py Remove non-breaking space that make no sense. Co-authored-by: Jean Abou-Samra --- pygments/lexers/configs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index 4aed513c77..4e0e7f1282 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -49,7 +49,7 @@ class IniLexer(RegexLexer): (r'(.*?)([  \t]*)([=:])([ \t]*)([^;#\n]*)(\\)(\s+)', bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String, Text, Whitespace), "value"), - (r'(.*?)([  \t]*)([=:])([  \t]*)([^ ;#\n]*(?: +[^ ;#\n]+)*)', + (r'(.*?)([ \t]*)([=:])([  \t]*)([^ ;#\n]*(?: +[^ ;#\n]+)*)', bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String)), # standalone option, supported by some INI parsers (r'(.+?)$', Name.Attribute),