Skip to content

Commit

Permalink
enh(ini) support arrays and much cleaner grammar (#2335)
Browse files Browse the repository at this point in the history
* enh(ini) support TOML arrays and much cleaner grammar
  • Loading branch information
joshgoebel committed Dec 30, 2019
1 parent 9a7f234 commit b661885
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 48 deletions.
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
]

0 comments on commit b661885

Please sign in to comment.