diff --git a/pygments/lexers/configs.py b/pygments/lexers/configs.py index 1209e4e70f..4e0e7f1282 100644 --- a/pygments/lexers/configs.py +++ b/pygments/lexers/configs.py @@ -45,12 +45,21 @@ class IniLexer(RegexLexer): 'root': [ (r'\s+', Whitespace), (r'[;#].*', Comment.Single), - (r'\[.*?\]$', Keyword), - (r'(.*?)([ \t]*)(=)([ \t]*)([^\t\n]*)', + (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]+)*)', bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String)), # standalone option, supported by some INI parsers (r'(.+?)$', Name.Attribute), ], + 'value': [ # line continuation + (r'\s+', Whitespace), + (r'(\s*)(.*)(\\)([ \t]*)', + bygroups(Whitespace, String, Text, Whitespace)), + (r'.*$', String, "#pop"), + ], } def analyse_text(text): diff --git a/tests/examplefiles/ini/test.ini b/tests/examplefiles/ini/test.ini index a447803de7..c06aee44c1 100644 --- a/tests/examplefiles/ini/test.ini +++ b/tests/examplefiles/ini/test.ini @@ -1,10 +1,18 @@ -[section] +[section1] -foo = bar -continued = foo +foo = bar ; inline comment +continued = foo # inline comment with \ + # line continuation baz conttwo = foo ; comment # comment +[section2] + +my_array = Asia, Africa, 'North America', South America, \ + Antarctica, Europe, Australia + +implicit_boolean +foo = bar diff --git a/tests/examplefiles/ini/test.ini.output b/tests/examplefiles/ini/test.ini.output index 4e7e3a59fb..27a91956fc 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 @@ -6,6 +6,8 @@ '=' Operator ' ' Text.Whitespace 'bar' Literal.String +' ' Text.Whitespace +'; inline comment' Comment.Single '\n' Text.Whitespace 'continued' Name.Attribute @@ -13,6 +15,10 @@ '=' Operator ' ' Text.Whitespace 'foo' Literal.String +' ' Text.Whitespace +'# inline comment with \\' Comment.Single +'\n ' Text.Whitespace +'# line continuation' Comment.Single '\n ' Text.Whitespace 'baz' Name.Attribute '\n' Text.Whitespace @@ -28,4 +34,27 @@ '\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, " Literal.String +'\\' Text +'\n ' Text.Whitespace +'Antarctica, Europe, Australia' Literal.String +'\n\n' Text.Whitespace + +'implicit_boolean' Name.Attribute +'\n' Text.Whitespace + +'foo' Name.Attribute +' ' Text.Whitespace +'=' Operator +' ' Text.Whitespace +'bar' Literal.String '\n' Text.Whitespace