Skip to content

Commit 70a77c3

Browse files
authored
Support standalone option in INI parser (#2161)
Some config formats such as HAProxy ones support standalone option.
1 parent e5cb72f commit 70a77c3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/rouge/lexers/ini.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@ class INI < RegexLexer
1414
identifier = /[\w\-.]+/
1515

1616
state :basic do
17+
rule %r/\s+/, Text::Whitespace
1718
rule %r/[;#].*?\n/, Comment
18-
rule %r/\s+/, Text
1919
rule %r/\\\n/, Str::Escape
2020
end
2121

2222
state :root do
2323
mixin :basic
2424

2525
rule %r/(#{identifier})(\s*)(=)/ do
26-
groups Name::Property, Text, Punctuation
26+
groups Name::Property, Text::Whitespace, Punctuation
2727
push :value
2828
end
2929

3030
rule %r/\[.*?\]/, Name::Namespace
31+
32+
# standalone option, supported by some INI parsers
33+
rule %r/(.+?)/, Name::Attribute
3134
end
3235

3336
state :value do

spec/visual/samples/ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ EGA40WOA.FON=EGA40WOA.FON
7070
CGA80WOA.FON=CGA80WOA.FON
7171
CGA40WOA.FON=CGA40WOA.FON
7272

73+
# HAProxy config
74+
global
75+
daemon
76+
maxconn 256
77+
78+
defaults
79+
mode http
80+
7381
## Other ##
7482
[section-name]
7583
foo-bar_ = baz

0 commit comments

Comments
 (0)