Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix INI #2779

Merged
merged 3 commits into from
Mar 2, 2021
Merged

Fix INI #2779

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions components/prism-ini.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
Prism.languages.ini= {
'comment': /^[ \t]*[;#].*$/m,
'selector': /^[ \t]*\[.*?\]/m,
'constant': /^[ \t]*[^\s=]+?(?=[ \t]*=)/m,
'attr-value': {
pattern: /=.*/,
'comment': {
pattern: /(^[ \f\t\v]*)[#;][^\n\r]*/m,
lookbehind: true
},
'header': {
pattern: /(^[ \f\t\v]*)\[[^\n\r\]]*\]?/m,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
lookbehind: true,
inside: {
'punctuation': /^[=]/
'section-name': {
pattern: /(\[[ \f\t\v]*)[^ \f\n\r\t\v\]]+(?:[ \f\t\v]+[^ \f\n\r\t\v\]]+)*/,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
lookbehind: true,
alias: 'selector'
},
rest: {
'punctuation': /\[|\]/
}
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
'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)/,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
lookbehind: true
}
}
},
'punctuation': /=/
};
2 changes: 1 addition & 1 deletion components/prism-ini.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 50 additions & 15 deletions tests/languages/ini/comment_feature.test
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.
86 changes: 86 additions & 0 deletions tests/languages/ini/header_feature.test
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).
78 changes: 57 additions & 21 deletions tests/languages/ini/key_value_feature.test
Original file line number Diff line number Diff line change
@@ -1,21 +1,57 @@
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 "
="baz14"
=' baz15 '
='baz16'
=baz17
bar18
bar19 baz19=qux19
bar20=
bar21==baz21
bar22=baz22
bar23=baz23 qux23
bar24=baz24=qux24

----------------------------------------------------

[
["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", "baz14"], "\""]],
["punctuation", "="], ["value", ["'", ["inner-value", " baz15 "], "'"]],
["punctuation", "="], ["value", ["'", ["inner-value", "baz16"], "'"]],
["punctuation", "="], ["value", ["baz17"]],
"\nbar18\n",
["key", "bar19 baz19"], ["punctuation", "="], ["value", ["qux19"]],
["key", "bar20"], ["punctuation", "="],
["key", "bar21"], ["punctuation", "="], ["value", ["=baz21"]],
["key", "bar22"], ["punctuation", "="], ["value", ["baz22"]],
["key", "bar23"], ["punctuation", "="], ["value", ["baz23 qux23"]],
["key", "bar24"], ["punctuation", "="], ["value", ["baz24=qux24"]]
]

----------------------------------------------------

Checks for key-value pairs.
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.