-
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.
Merge pull request #813 from Golmote/prism-puppet
Add support for Puppet configuration
- Loading branch information
Showing
17 changed files
with
732 additions
and
0 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
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,131 @@ | ||
(function (Prism) { | ||
Prism.languages.puppet = { | ||
'heredoc': [ | ||
// Matches the content of a quoted heredoc string (subject to interpolation) | ||
{ | ||
pattern: /(@\("([^"\r\n\/):]+)"(?:\/[nrts$uL]*)?\).*(?:\r?\n|\r))(?:.*(?:\r?\n|\r))*?[ \t]*\|?[ \t]*-?[ \t]*\2/, | ||
lookbehind: true, | ||
alias: 'string', | ||
inside: { | ||
// Matches the end tag | ||
'punctuation': /(?=\S).*\S(?= *$)/ | ||
// See interpolation below | ||
} | ||
}, | ||
// Matches the content of an unquoted heredoc string (no interpolation) | ||
{ | ||
pattern: /(@\(([^"\r\n\/):]+)(?:\/[nrts$uL]*)?\).*(?:\r?\n|\r))(?:.*(?:\r?\n|\r))*?[ \t]*\|?[ \t]*-?[ \t]*\2/, | ||
lookbehind: true, | ||
alias: 'string', | ||
inside: { | ||
// Matches the end tag | ||
'punctuation': /(?=\S).*\S(?= *$)/ | ||
} | ||
}, | ||
// Matches the start tag of heredoc strings | ||
{ | ||
pattern: /@\("?(?:[^"\r\n\/):]+)"?(?:\/[nrts$uL]*)?\)/, | ||
alias: 'string', | ||
inside: { | ||
'punctuation': { | ||
pattern: /(\().+?(?=\))/, | ||
lookbehind: true | ||
} | ||
} | ||
} | ||
], | ||
'multiline-comment': { | ||
pattern: /(^|[^\\])\/\*[\s\S]*?\*\//, | ||
lookbehind: true, | ||
alias: 'comment' | ||
}, | ||
'regex': { | ||
// Must be prefixed with the keyword "node" or a non-word char | ||
pattern: /((?:\bnode\s+|[^\s\w\\]\s*))\/(?:[^\/\\]|\\[\s\S])+\/(?:[imx]+\b|\B)/, | ||
lookbehind: true, | ||
inside: { | ||
// Extended regexes must have the x flag. They can contain single-line comments. | ||
'extended-regex': { | ||
pattern: /^\/(?:[^\/\\]|\\[\s\S])+\/[im]*x[im]*$/, | ||
inside: { | ||
'comment': /#.*/ | ||
} | ||
} | ||
} | ||
}, | ||
'comment': { | ||
pattern: /(^|[^\\])#.*/, | ||
lookbehind: true | ||
}, | ||
'string': { | ||
// Allow for one nested level of double quotes inside interpolation | ||
pattern: /(["'])(?:\$\{(?:[^'"}]|(["'])(?:(?!\2)[^\\]|\\[\s\S])*\2)+\}|(?!\1)[^\\]|\\[\s\S])*\1/, | ||
inside: { | ||
'double-quoted': { | ||
pattern: /^"[\s\S]*"$/, | ||
inside: { | ||
// See interpolation below | ||
} | ||
} | ||
} | ||
}, | ||
'variable': { | ||
pattern: /\$(?:::)?\w+(?:::\w+)*/, | ||
inside: { | ||
'punctuation': /::/ | ||
} | ||
}, | ||
'attr-name': /(?:\w+|\*)(?=\s*=>)/, | ||
'function': [ | ||
{ | ||
pattern: /(\.)(?!\d)\w+/, | ||
lookbehind: true | ||
}, | ||
/\b(?:contain|debug|err|fail|include|info|notice|realize|require|tag|warning)\b|\b(?!\d)\w+(?=\()/ | ||
], | ||
'number': /\b(?:0x[a-f\d]+|\d+(?:\.\d+)?(?:e-?\d+)?)\b/i, | ||
'boolean': /\b(?:true|false)\b/, | ||
// Includes words reserved for future use | ||
'keyword': /\b(?:application|attr|case|class|consumes|default|define|else|elsif|function|if|import|inherits|node|private|produces|type|undef|unless)\b/, | ||
'datatype': { | ||
pattern: /\b(?:Any|Array|Boolean|Callable|Catalogentry|Class|Collection|Data|Default|Enum|Float|Hash|Integer|NotUndef|Numeric|Optional|Pattern|Regexp|Resource|Runtime|Scalar|String|Struct|Tuple|Type|Undef|Variant)\b/, | ||
alias: 'symbol' | ||
}, | ||
'operator': /=[=~>]?|![=~]?|<(?:<\|?|[=~|-])?|>[>=]?|->?|~>|\|>?>?|[*\/%+?]|\b(?:and|in|or)\b/, | ||
'punctuation': /[\[\]{}().,;]|:+/ | ||
}; | ||
|
||
var interpolation = [ | ||
{ | ||
// Allow for one nested level of braces inside interpolation | ||
pattern: /(^|[^\\])\$\{(?:[^'"{}]|\{[^}]*\}|(["'])(?:(?!\2)[^\\]|\\[\s\S])*\2)+\}/, | ||
lookbehind: true, | ||
inside: { | ||
'short-variable': { | ||
// Negative look-ahead prevent wrong highlighting of functions | ||
pattern: /(^\$\{)(?!\w+\()(?:::)?\w+(?:::\w+)*/, | ||
lookbehind: true, | ||
alias: 'variable', | ||
inside: { | ||
'punctuation': /::/ | ||
} | ||
}, | ||
'delimiter': { | ||
pattern: /^\$/, | ||
alias: 'variable' | ||
}, | ||
rest: Prism.util.clone(Prism.languages.puppet) | ||
} | ||
}, | ||
{ | ||
pattern: /(^|[^\\])\$(?:::)?\w+(?:::\w+)*/, | ||
lookbehind: true, | ||
alias: 'variable', | ||
inside: { | ||
'punctuation': /::/ | ||
} | ||
} | ||
]; | ||
Prism.languages.puppet['heredoc'][0].inside.interpolation = interpolation; | ||
Prism.languages.puppet['string'].inside['double-quoted'].inside.interpolation = interpolation; | ||
}(Prism)); |
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 |
---|---|---|
@@ -0,0 +1,168 @@ | ||
<h1>Puppet</h1> | ||
<p>To use this language, use the class "language-puppet".</p> | ||
|
||
<h2>Comments</h2> | ||
<pre><code># | ||
# Foobar | ||
/* Foo | ||
bar */</code></pre> | ||
|
||
<h2>Strings and interpolation</h2> | ||
<pre><code>'foo \'bar\' baz' | ||
"$foo \"bar\" ${baz}" | ||
|
||
@(FOOBAR) # Unquoted heredoc string | ||
Foo bar baz | ||
FOOBAR | ||
|
||
@("BARBAZ"/$L) # Quoted heredoc string | ||
$foo bar ${baz} | ||
|-BARBAZ</code></pre> | ||
|
||
<h2>Regular expressions</h2> | ||
<pre><code>if $host =~ /^www(\d+)\./ {} | ||
$foo = /foo | ||
bar # Extended regexes can include comments | ||
baz/x</code></pre> | ||
|
||
<h2>Variables</h2> | ||
<pre><code>$foo | ||
$::foobar | ||
$foo::bar::baz</code></pre> | ||
|
||
<h2>Functions</h2> | ||
<pre><code>require apache | ||
template('apache/vhost-default.conf.erb') | ||
[1,20,3].filter |$value| { $value < 10 }</code></pre> | ||
|
||
<h2>All-in-one example</h2> | ||
<pre><code>file {'ntp.conf': | ||
path => '/etc/ntp.conf', | ||
ensure => file, | ||
content => template('ntp/ntp.conf'), | ||
owner => 'root', | ||
mode => '0644', | ||
} | ||
package {'ntp': | ||
ensure => installed, | ||
before => File['ntp.conf'], | ||
} | ||
service {'ntpd': | ||
ensure => running, | ||
subscribe => File['ntp.conf'], | ||
} | ||
Package['ntp'] -> File['ntp.conf'] ~> Service['ntpd'] | ||
|
||
$package_list = ['ntp', 'apache2', 'vim-nox', 'wget'] | ||
$myhash = { key => { subkey => 'b' }} | ||
|
||
include ntp | ||
require ntp | ||
class {'ntp':} | ||
|
||
define apache::vhost ($port, $docroot, $servername = $title, $vhost_name = '*') { | ||
include apache | ||
include apache::params | ||
$vhost_dir = $apache::params::vhost_dir | ||
file { "${vhost_dir}/${servername}.conf": | ||
content => template('apache/vhost-default.conf.erb'), | ||
owner => 'www', | ||
group => 'www', | ||
mode => '644', | ||
require => Package['httpd'], | ||
notify => Service['httpd'], | ||
} | ||
} | ||
|
||
apache::vhost {'homepages': | ||
port => 8081, | ||
docroot => '/var/www-testhost', | ||
} | ||
Apache::Vhost['homepages'] | ||
|
||
node 'www1.example.com' { | ||
include common | ||
include apache | ||
include squid | ||
} | ||
node /^www\d+$/ { | ||
include common | ||
} | ||
|
||
# comment | ||
/* comment */ | ||
|
||
if $is_virtual { | ||
warning( 'Tried to include class ntp on virtual machine; this node may be misclassified.' ) | ||
} | ||
elsif $operatingsystem == 'Darwin' { | ||
warning( 'This NTP module does not yet work on our Mac laptops.' ) | ||
else { | ||
include ntp | ||
} | ||
|
||
if $hostname =~ /^www(\d+)\./ { | ||
notify { "Welcome web server $1": } | ||
} | ||
|
||
case $operatingsystem { | ||
'Solaris': { include role::solaris } | ||
'RedHat', 'CentOS': { include role::redhat } | ||
/^(Debian|Ubuntu)$/:{ include role::debian } | ||
default: { include role::generic } | ||
} | ||
$rootgroup = $osfamily ? { | ||
'Solaris' => 'wheel', | ||
/(Darwin|FreeBSD)/ => 'wheel', | ||
default => 'root', | ||
} | ||
|
||
User <| groups == 'admin' |> | ||
Concat::Fragment <<| tag == "bacula-storage-dir-${bacula_director}" |>> | ||
|
||
Exec <| title == 'update_migrations' |> { | ||
environment => 'RUBYLIB=/usr/lib/ruby/site_ruby/1.8/', | ||
} | ||
|
||
@user {'deploy': | ||
uid => 2004, | ||
comment => 'Deployment User', | ||
group => www-data, | ||
groups => ["enterprise"], | ||
tag => [deploy, web], | ||
} | ||
|
||
@@nagios_service { "check_zfs${hostname}": | ||
use => 'generic-service', | ||
host_name => "$fqdn", | ||
check_command => 'check_nrpe_1arg!check_zfs', | ||
service_description => "check_zfs${hostname}", | ||
target => '/etc/nagios3/conf.d/nagios_service.cfg', | ||
notify => Service[$nagios::params::nagios_service], | ||
}</code></pre> | ||
|
||
<h2>Known failures</h2> | ||
<p>There are certain edge cases where Prism will fail. | ||
There are always such cases in every regex-based syntax highlighter. | ||
However, Prism dares to be open and honest about them. | ||
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} | ||
baz => 42 | ||
})} <- broken"</code></pre> |
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,19 @@ | ||
foo { | ||
bar => bar, | ||
* => {} | ||
} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
"foo ", ["punctuation", "{"], | ||
["attr-name", "bar"], ["operator", "=>"], | ||
" bar", ["punctuation", ","], | ||
["attr-name", "*"], ["operator", "=>"], | ||
["punctuation", "{"], ["punctuation", "}"], | ||
["punctuation", "}"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for attributes. |
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,13 @@ | ||
true | ||
false | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["boolean", "true"], | ||
["boolean", "false"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for booleans. |
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,16 @@ | ||
# | ||
# Foobar | ||
/* Foo | ||
bar */ | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "#"], | ||
["comment", "# Foobar"], | ||
["multiline-comment", "/* Foo\r\nbar */"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
Oops, something went wrong.