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

enh(ini) support arrays and much cleaner grammar #2335

Merged
merged 4 commits into from Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -14,6 +14,7 @@ Core Changes:

Language Improvements:

- (ini) support arrays, clean up grammar (#2335) [Josh Goebel][]
- (vbnet) add nameof operator to the keywords (#2329) [Youssef Victor][]
- (stan) updated with improved coverage of language keywords and patterns. (#1829) [Jeffrey Arnold][]

Expand Down
105 changes: 57 additions & 48 deletions src/languages/ini.js
Expand Up @@ -7,68 +7,77 @@ Website: https://github.com/toml-lang/toml
*/

function(hljs) {
var STRING = {
var NUMBERS = {
className: 'number',
relevance: 0,
variants: [
{ begin: /([\+\-]+)?[\d]+_[\d_]+/ },
{ begin: hljs.NUMBER_RE }
]
};
var COMMENTS = hljs.COMMENT();
COMMENTS.variants = [
{begin: /;/, end: /$/},
{begin: /#/, end: /$/},
];
var VARIABLES = {
className: 'variable',
variants: [
{ begin: /\$[\w\d"][\w\d_]*/ },
{ begin: /\$\{(.*?)}/ }
]
};
var LITERALS = {
className: 'literal',
begin: /\bon|off|true|false|yes|no\b/
};
var STRINGS = {
className: "string",
contains: [hljs.BACKSLASH_ESCAPE],
variants: [
{
begin: "'''", end: "'''",
relevance: 10
}, {
begin: '"""', end: '"""',
relevance: 10
}, {
begin: '"', end: '"'
}, {
begin: "'", end: "'"
}
{ begin: "'''", end: "'''", relevance: 10 },
{ begin: '"""', end: '"""', relevance: 10 },
{ begin: '"', end: '"' },
{ begin: "'", end: "'" }
]
};
var ARRAY = {
begin: /\[/, end: /\]/,
contains: [
COMMENTS,
LITERALS,
VARIABLES,
STRINGS,
NUMBERS,
'self'
],
relevance:0
};

return {
aliases: ['toml'],
case_insensitive: true,
illegal: /\S/,
contains: [
hljs.COMMENT(';', '$'),
hljs.HASH_COMMENT_MODE,
COMMENTS,
{
className: 'section',
begin: /^\s*\[+/, end: /\]+/
begin: /\[+/, end: /\]+/
},
{
begin: /^[a-z0-9\[\]_\.-]+\s*=\s*/, end: '$',
returnBegin: true,
contains: [
{
className: 'attr',
begin: /[a-z0-9\[\]_\.-]+/
},
{
begin: /=/, endsWithParent: true,
relevance: 0,
contains: [
hljs.COMMENT(';', '$'),
hljs.HASH_COMMENT_MODE,
{
className: 'literal',
begin: /\bon|off|true|false|yes|no\b/
},
{
className: 'variable',
variants: [
{begin: /\$[\w\d"][\w\d_]*/},
{begin: /\$\{(.*?)}/}
]
},
STRING,
{
className: 'number',
begin: /([\+\-]+)?[\d]+_[\d_]+/
},
hljs.NUMBER_MODE
]
}
]
begin: /^[a-z0-9\[\]_\.-]+(?=\s*=\s*)/,
className: 'attr',
starts: {
end: /$/,
contains: [
COMMENTS,
ARRAY,
LITERALS,
VARIABLES,
STRINGS,
NUMBERS
]
}
}
]
};
Expand Down
9 changes: 9 additions & 0 deletions test/markup/ini/array.expect.txt
@@ -0,0 +1,9 @@
<span class="hljs-attr">moo</span>=[<span class="hljs-string">"foo"</span>]

<span class="hljs-attr">KNOWN_PEERS</span> = [
<span class="hljs-string">"finland.some-host.com:11625"</span>,
<span class="hljs-string">"germany.some-host.com:11625"</span>,
<span class="hljs-string">"hongkong.some-host.com:11625"</span>,
<span class="hljs-number">32</span>,
<span class="hljs-literal">true</span>
]
10 changes: 10 additions & 0 deletions test/markup/ini/array.txt
@@ -0,0 +1,10 @@

moo=["foo"]

KNOWN_PEERS = [
"finland.some-host.com:11625",
"germany.some-host.com:11625",
"hongkong.some-host.com:11625",
32,
true
]