Skip to content

Commit

Permalink
Puppet: Make heredoc, comments, regexps and strings greedy. Update kn…
Browse files Browse the repository at this point in the history
…own failures and tests.
  • Loading branch information
Golmote committed Mar 26, 2018
1 parent d7b2b43 commit 0c139d1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
7 changes: 6 additions & 1 deletion components/prism-puppet.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{
pattern: /(@\(([^"\r\n\/):]+)(?:\/[nrts$uL]*)?\).*(?:\r?\n|\r))(?:.*(?:\r?\n|\r))*?[ \t]*\|?[ \t]*-?[ \t]*\2/,
lookbehind: true,
greedy: true,
alias: 'string',
inside: {
// Matches the end tag
Expand All @@ -37,12 +38,14 @@
'multiline-comment': {
pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
lookbehind: true,
greedy: true,
alias: 'comment'
},
'regex': {
// Must be prefixed with the keyword "node" or a non-word char
pattern: /((?:\bnode\s+|[~=\(\[\{,]\s*|[=+]>\s*|^\s*))\/(?:[^\/\\]|\\[\s\S])+\/(?:[imx]+\b|\B)/,
lookbehind: true,
greedy: true,
inside: {
// Extended regexes must have the x flag. They can contain single-line comments.
'extended-regex': {
Expand All @@ -55,11 +58,13 @@
},
'comment': {
pattern: /(^|[^\\])#.*/,
lookbehind: true
lookbehind: true,
greedy: true,
},
'string': {
// Allow for one nested level of double quotes inside interpolation
pattern: /(["'])(?:\$\{(?:[^'"}]|(["'])(?:(?!\2)[^\\]|\\[\s\S])*\2)+\}|(?!\1)[^\\]|\\[\s\S])*\1/,
greedy: true,
inside: {
'double-quoted': {
pattern: /^"[\s\S]*"$/,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-puppet.min.js

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

13 changes: 0 additions & 13 deletions examples/prism-puppet.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,6 @@ <h2>Known failures</h2>
If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
</p>

<h3>Comments, regular expressions or substrings that look like heredoc strings</h3>
<pre><code>/* @(foo) */
# @(foo)
" @(foo) "
$foo = /@(foo)/</code></pre>

<h3>Single-line comments or substrings that look like multi-line comments</h3>
<pre><code># foo /* bar */ baz
"foo /* bar */ baz"</code></pre>

<h3>Substrings that look like single-line comment</h3>
<pre><code>"foo #bar baz"</code></pre>

<h3>More than one level of nested braces inside interpolation</h3>
<pre><code>"Foobar ${foo({
bar => {baz => 42}
Expand Down
8 changes: 7 additions & 1 deletion tests/languages/puppet/comment_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
# Foobar
/* Foo
bar */
/* @(foo) */
# @(foo)
# foo /* bar */ baz

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

[
["comment", "#"],
["comment", "# Foobar"],
["multiline-comment", "/* Foo\r\nbar */"]
["multiline-comment", "/* Foo\r\nbar */"],
["multiline-comment", "/* @(foo) */"],
["comment", "# @(foo)"],
["comment", "# foo /* bar */ baz"]
]

----------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion tests/languages/puppet/regex_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ bar # baz
$foo = /foo
bar # baz
/ixm
$foo = /@(foo)/

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

Expand All @@ -20,7 +21,9 @@ bar # baz
["comment", "# baz"],
"\r\n/ixm"
]]
]]
]],
["variable", ["$foo"]], ["operator", "="],
["regex", ["/@(foo)/"]]
]

----------------------------------------------------
Expand Down
8 changes: 7 additions & 1 deletion tests/languages/puppet/string_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ baz'
"foo
$bar
baz"
" @(foo) "
"foo /* bar */ baz"
"foo #bar baz"

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

Expand All @@ -21,7 +24,10 @@ baz"
"\"foo\r\n",
["interpolation", ["$bar"]],
"\r\nbaz\""
]]]]
]]]],
["string", [["double-quoted", ["\" @(foo) \""]]]],
["string", [["double-quoted", ["\"foo /* bar */ baz\""]]]],
["string", [["double-quoted", ["\"foo #bar baz\""]]]]
]

----------------------------------------------------
Expand Down

0 comments on commit 0c139d1

Please sign in to comment.