-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INI: Consistently mimic Win32 INI parsing (#2779)
- Loading branch information
Showing
6 changed files
with
255 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,42 @@ | ||
Prism.languages.ini= { | ||
'comment': /^[ \t]*[;#].*$/m, | ||
'selector': /^[ \t]*\[.*?\]/m, | ||
'constant': /^[ \t]*[^\s=]+?(?=[ \t]*=)/m, | ||
'attr-value': { | ||
pattern: /=.*/, | ||
|
||
/** | ||
* The component mimics the behavior of the Win32 API parser. | ||
* | ||
* @see {@link https://github.com/PrismJS/prism/issues/2775#issuecomment-787477723} | ||
*/ | ||
|
||
'comment': { | ||
pattern: /(^[ \f\t\v]*)[#;][^\n\r]*/m, | ||
lookbehind: true | ||
}, | ||
'header': { | ||
pattern: /(^[ \f\t\v]*)\[[^\n\r\]]*\]?/m, | ||
lookbehind: true, | ||
inside: { | ||
'punctuation': /^[=]/ | ||
'section-name': { | ||
pattern: /(^\[[ \f\t\v]*)[^ \f\t\v\]]+(?:[ \f\t\v]+[^ \f\t\v\]]+)*/, | ||
lookbehind: true, | ||
alias: 'selector' | ||
}, | ||
'punctuation': /\[|\]/ | ||
} | ||
} | ||
}, | ||
'key': { | ||
pattern: /(^[ \f\t\v]*)[^ \f\n\r\t\v=]+(?:[ \f\t\v]+[^ \f\n\r\t\v=]+)*(?=[ \f\t\v]*=)/m, | ||
lookbehind: true, | ||
alias: 'attr-name' | ||
}, | ||
'value': { | ||
pattern: /(=[ \f\t\v]*)[^ \f\n\r\t\v]+(?:[ \f\t\v]+[^ \f\n\r\t\v]+)*/, | ||
lookbehind: true, | ||
alias: 'attr-value', | ||
inside: { | ||
'inner-value': { | ||
pattern: /^("|').+(?=\1$)/, | ||
lookbehind: true | ||
} | ||
} | ||
}, | ||
'punctuation': /=/ | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,50 @@ | ||
; | ||
; foobar | ||
# foobar | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", ";"], | ||
["comment", "; foobar"], | ||
["comment", "# foobar"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. | ||
# | ||
; | ||
# | ||
; | ||
# | ||
# | ||
# | ||
#; | ||
#[foo] | ||
#foo=bar | ||
#foobar | ||
; | ||
; | ||
; | ||
;# | ||
;[foo] | ||
;foo=bar | ||
;foobar | ||
foo#bar | ||
foobar# | ||
foo;bar | ||
foobar; | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "#"], | ||
["comment", ";"], | ||
["comment", "#"], | ||
["comment", ";"], | ||
["comment", "#"], | ||
["comment", "#\t"], | ||
["comment", "# "], | ||
["comment", "#;"], | ||
["comment", "#[foo]"], | ||
["comment", "#foo=bar"], | ||
["comment", "#foobar"], | ||
["comment", ";"], | ||
["comment", ";\t"], | ||
["comment", "; "], | ||
["comment", ";#"], | ||
["comment", ";[foo]"], | ||
["comment", ";foo=bar"], | ||
["comment", ";foobar"], | ||
"\nfoo#bar\nfoobar#\nfoo;bar\nfoobar;" | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
[foo1] | ||
[ "foo2" ] | ||
[ foo3 ] | ||
[" foo4 "] | ||
["foo5 bar5"] | ||
["foo6"] | ||
[foo7 | ||
[foo8 bar8] | ||
[foo9[bar9] | ||
[foo10] | ||
[foo11]bar11] | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["header", [ | ||
["punctuation", "["], | ||
["section-name", "foo1"], | ||
["punctuation", "]"] | ||
]], | ||
|
||
["header", [ | ||
["punctuation", "["], | ||
["section-name", "\"foo2\""], | ||
["punctuation", "]"] | ||
]], | ||
|
||
["header", [ | ||
["punctuation", "["], | ||
["section-name", "foo3"], | ||
["punctuation", "]"] | ||
]], | ||
|
||
["header", [ | ||
["punctuation", "["], | ||
["section-name", "\" foo4 \""], | ||
["punctuation", "]"] | ||
]], | ||
|
||
["header", [ | ||
["punctuation", "["], | ||
["section-name", "\"foo5 bar5\""], | ||
["punctuation", "]"] | ||
]], | ||
|
||
["header", [ | ||
["punctuation", "["], | ||
["section-name", "\"foo6\""], | ||
["punctuation", "]"] | ||
]], | ||
|
||
["header", [ | ||
["punctuation", "["], | ||
["section-name", "foo7"] | ||
]], | ||
|
||
["header", [ | ||
["punctuation", "["], | ||
["section-name", "foo8 bar8"], | ||
["punctuation", "]"] | ||
]], | ||
|
||
["header", [ | ||
["punctuation", "["], | ||
["section-name", "foo9[bar9"], | ||
["punctuation", "]"] | ||
]], | ||
|
||
["header", [ | ||
["punctuation", "["], | ||
["section-name", "foo10"], | ||
["punctuation", "]"] | ||
]], | ||
|
||
["header", [ | ||
["punctuation", "["], | ||
["section-name", "foo11"], | ||
["punctuation", "]"] | ||
]], | ||
|
||
"bar11]" | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for headers (and section names). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,69 @@ | ||
foo=Bar Baz | ||
foobar=42 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["constant", "foo"], | ||
["attr-value", [ | ||
["punctuation", "="], | ||
"Bar Baz" | ||
]], | ||
["constant", "foobar"], | ||
["attr-value", [ | ||
["punctuation", "="], | ||
"42" | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for key/value pairs. | ||
bar1 = | ||
"bar2" = | ||
'bar3' = | ||
bar4 = | ||
" bar5 "= | ||
"bar6"= | ||
' bar7 '= | ||
'bar8'= | ||
= baz9 | ||
= "baz10" | ||
= 'baz11' | ||
= baz12 | ||
=" baz13 " | ||
="b14"a14"z14" | ||
="baz15" | ||
="baz16 | ||
=' baz17 ' | ||
='baz18' | ||
=b19"a19"z19 | ||
=b20"az20 | ||
=ba21"z21 | ||
=baz22 | ||
=baz23" | ||
bar24 | ||
bar25 baz25=qux25 | ||
bar26= | ||
bar27==baz27 | ||
bar28=baz28 | ||
bar29=baz29 qux29 | ||
bar30=baz30=qux30 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["key", "bar1"], ["punctuation", "="], | ||
["key", "\"bar2\""], ["punctuation", "="], | ||
["key", "'bar3'"], ["punctuation", "="], | ||
["key", "bar4"], ["punctuation", "="], | ||
["key", "\" bar5 \""], ["punctuation", "="], | ||
["key", "\"bar6\""], ["punctuation", "="], | ||
["key", "' bar7 '"], ["punctuation", "="], | ||
["key", "'bar8'"], ["punctuation", "="], | ||
["punctuation", "="], ["value", ["baz9"]], | ||
["punctuation", "="], ["value", ["\"", ["inner-value", "baz10"], "\""]], | ||
["punctuation", "="], ["value", ["'", ["inner-value", "baz11"], "'"]], | ||
["punctuation", "="], ["value", ["baz12"]], | ||
["punctuation", "="], ["value", ["\"", ["inner-value", " baz13 "], "\""]], | ||
["punctuation", "="], ["value", ["\"", ["inner-value", "b14\"a14\"z14"], "\""]], | ||
["punctuation", "="], ["value", ["\"", ["inner-value", "baz15"], "\""]], | ||
["punctuation", "="], ["value", ["\"baz16"]], | ||
["punctuation", "="], ["value", ["'", ["inner-value", " baz17 "], "'"]], | ||
["punctuation", "="], ["value", ["'", ["inner-value", "baz18"], "'"]], | ||
["punctuation", "="], ["value", ["b19\"a19\"z19"]], | ||
["punctuation", "="], ["value", ["b20\"az20"]], | ||
["punctuation", "="], ["value", ["ba21\"z21"]], | ||
["punctuation", "="], ["value", ["baz22"]], | ||
["punctuation", "="], ["value", ["baz23\""]], | ||
"\nbar24\n", | ||
["key", "bar25 baz25"], ["punctuation", "="], ["value", ["qux25"]], | ||
["key", "bar26"], ["punctuation", "="], | ||
["key", "bar27"], ["punctuation", "="], ["value", ["=baz27"]], | ||
["key", "bar28"], ["punctuation", "="], ["value", ["baz28"]], | ||
["key", "bar29"], ["punctuation", "="], ["value", ["baz29 qux29"]], | ||
["key", "bar30"], ["punctuation", "="], ["value", ["baz30=qux30"]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for key-value pairs. |
24 changes: 11 additions & 13 deletions
24
tests/languages/ini/selector_feature.test → tests/languages/ini/punctuation_feature.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
[owner] | ||
[foobar] | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["selector", "[owner]"], | ||
["selector", "[foobar]"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for section titles. | ||
= | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["punctuation", "="] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for punctuation marks. |