Edit File by line
/home/barbar84/www/wp-conte.../plugins/wp-file-.../lib/codemirr.../mode/puppet
File: puppet.js
// CodeMirror, copyright (c) by Marijn Haverbeke and others
[0] Fix | Delete
// Distributed under an MIT license: http://codemirror.net/LICENSE
[1] Fix | Delete
[2] Fix | Delete
(function(mod) {
[3] Fix | Delete
if (typeof exports == "object" && typeof module == "object") // CommonJS
[4] Fix | Delete
mod(require("../../lib/codemirror"));
[5] Fix | Delete
else if (typeof define == "function" && define.amd) // AMD
[6] Fix | Delete
define(["../../lib/codemirror"], mod);
[7] Fix | Delete
else // Plain browser env
[8] Fix | Delete
mod(CodeMirror);
[9] Fix | Delete
})(function(CodeMirror) {
[10] Fix | Delete
"use strict";
[11] Fix | Delete
[12] Fix | Delete
CodeMirror.defineMode("puppet", function () {
[13] Fix | Delete
// Stores the words from the define method
[14] Fix | Delete
var words = {};
[15] Fix | Delete
// Taken, mostly, from the Puppet official variable standards regex
[16] Fix | Delete
var variable_regex = /({)?([a-z][a-z0-9_]*)?((::[a-z][a-z0-9_]*)*::)?[a-zA-Z0-9_]+(})?/;
[17] Fix | Delete
[18] Fix | Delete
// Takes a string of words separated by spaces and adds them as
[19] Fix | Delete
// keys with the value of the first argument 'style'
[20] Fix | Delete
function define(style, string) {
[21] Fix | Delete
var split = string.split(' ');
[22] Fix | Delete
for (var i = 0; i < split.length; i++) {
[23] Fix | Delete
words[split[i]] = style;
[24] Fix | Delete
}
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
// Takes commonly known puppet types/words and classifies them to a style
[28] Fix | Delete
define('keyword', 'class define site node include import inherits');
[29] Fix | Delete
define('keyword', 'case if else in and elsif default or');
[30] Fix | Delete
define('atom', 'false true running present absent file directory undef');
[31] Fix | Delete
define('builtin', 'action augeas burst chain computer cron destination dport exec ' +
[32] Fix | Delete
'file filebucket group host icmp iniface interface jump k5login limit log_level ' +
[33] Fix | Delete
'log_prefix macauthorization mailalias maillist mcx mount nagios_command ' +
[34] Fix | Delete
'nagios_contact nagios_contactgroup nagios_host nagios_hostdependency ' +
[35] Fix | Delete
'nagios_hostescalation nagios_hostextinfo nagios_hostgroup nagios_service ' +
[36] Fix | Delete
'nagios_servicedependency nagios_serviceescalation nagios_serviceextinfo ' +
[37] Fix | Delete
'nagios_servicegroup nagios_timeperiod name notify outiface package proto reject ' +
[38] Fix | Delete
'resources router schedule scheduled_task selboolean selmodule service source ' +
[39] Fix | Delete
'sport ssh_authorized_key sshkey stage state table tidy todest toports tosource ' +
[40] Fix | Delete
'user vlan yumrepo zfs zone zpool');
[41] Fix | Delete
[42] Fix | Delete
// After finding a start of a string ('|") this function attempts to find the end;
[43] Fix | Delete
// If a variable is encountered along the way, we display it differently when it
[44] Fix | Delete
// is encapsulated in a double-quoted string.
[45] Fix | Delete
function tokenString(stream, state) {
[46] Fix | Delete
var current, prev, found_var = false;
[47] Fix | Delete
while (!stream.eol() && (current = stream.next()) != state.pending) {
[48] Fix | Delete
if (current === '$' && prev != '\\' && state.pending == '"') {
[49] Fix | Delete
found_var = true;
[50] Fix | Delete
break;
[51] Fix | Delete
}
[52] Fix | Delete
prev = current;
[53] Fix | Delete
}
[54] Fix | Delete
if (found_var) {
[55] Fix | Delete
stream.backUp(1);
[56] Fix | Delete
}
[57] Fix | Delete
if (current == state.pending) {
[58] Fix | Delete
state.continueString = false;
[59] Fix | Delete
} else {
[60] Fix | Delete
state.continueString = true;
[61] Fix | Delete
}
[62] Fix | Delete
return "string";
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
// Main function
[66] Fix | Delete
function tokenize(stream, state) {
[67] Fix | Delete
// Matches one whole word
[68] Fix | Delete
var word = stream.match(/[\w]+/, false);
[69] Fix | Delete
// Matches attributes (i.e. ensure => present ; 'ensure' would be matched)
[70] Fix | Delete
var attribute = stream.match(/(\s+)?\w+\s+=>.*/, false);
[71] Fix | Delete
// Matches non-builtin resource declarations
[72] Fix | Delete
// (i.e. "apache::vhost {" or "mycustomclasss {" would be matched)
[73] Fix | Delete
var resource = stream.match(/(\s+)?[\w:_]+(\s+)?{/, false);
[74] Fix | Delete
// Matches virtual and exported resources (i.e. @@user { ; and the like)
[75] Fix | Delete
var special_resource = stream.match(/(\s+)?[@]{1,2}[\w:_]+(\s+)?{/, false);
[76] Fix | Delete
[77] Fix | Delete
// Finally advance the stream
[78] Fix | Delete
var ch = stream.next();
[79] Fix | Delete
[80] Fix | Delete
// Have we found a variable?
[81] Fix | Delete
if (ch === '$') {
[82] Fix | Delete
if (stream.match(variable_regex)) {
[83] Fix | Delete
// If so, and its in a string, assign it a different color
[84] Fix | Delete
return state.continueString ? 'variable-2' : 'variable';
[85] Fix | Delete
}
[86] Fix | Delete
// Otherwise return an invalid variable
[87] Fix | Delete
return "error";
[88] Fix | Delete
}
[89] Fix | Delete
// Should we still be looking for the end of a string?
[90] Fix | Delete
if (state.continueString) {
[91] Fix | Delete
// If so, go through the loop again
[92] Fix | Delete
stream.backUp(1);
[93] Fix | Delete
return tokenString(stream, state);
[94] Fix | Delete
}
[95] Fix | Delete
// Are we in a definition (class, node, define)?
[96] Fix | Delete
if (state.inDefinition) {
[97] Fix | Delete
// If so, return def (i.e. for 'class myclass {' ; 'myclass' would be matched)
[98] Fix | Delete
if (stream.match(/(\s+)?[\w:_]+(\s+)?/)) {
[99] Fix | Delete
return 'def';
[100] Fix | Delete
}
[101] Fix | Delete
// Match the rest it the next time around
[102] Fix | Delete
stream.match(/\s+{/);
[103] Fix | Delete
state.inDefinition = false;
[104] Fix | Delete
}
[105] Fix | Delete
// Are we in an 'include' statement?
[106] Fix | Delete
if (state.inInclude) {
[107] Fix | Delete
// Match and return the included class
[108] Fix | Delete
stream.match(/(\s+)?\S+(\s+)?/);
[109] Fix | Delete
state.inInclude = false;
[110] Fix | Delete
return 'def';
[111] Fix | Delete
}
[112] Fix | Delete
// Do we just have a function on our hands?
[113] Fix | Delete
// In 'ensure_resource("myclass")', 'ensure_resource' is matched
[114] Fix | Delete
if (stream.match(/(\s+)?\w+\(/)) {
[115] Fix | Delete
stream.backUp(1);
[116] Fix | Delete
return 'def';
[117] Fix | Delete
}
[118] Fix | Delete
// Have we matched the prior attribute regex?
[119] Fix | Delete
if (attribute) {
[120] Fix | Delete
stream.match(/(\s+)?\w+/);
[121] Fix | Delete
return 'tag';
[122] Fix | Delete
}
[123] Fix | Delete
// Do we have Puppet specific words?
[124] Fix | Delete
if (word && words.hasOwnProperty(word)) {
[125] Fix | Delete
// Negates the initial next()
[126] Fix | Delete
stream.backUp(1);
[127] Fix | Delete
// rs move the stream
[128] Fix | Delete
stream.match(/[\w]+/);
[129] Fix | Delete
// We want to process these words differently
[130] Fix | Delete
// do to the importance they have in Puppet
[131] Fix | Delete
if (stream.match(/\s+\S+\s+{/, false)) {
[132] Fix | Delete
state.inDefinition = true;
[133] Fix | Delete
}
[134] Fix | Delete
if (word == 'include') {
[135] Fix | Delete
state.inInclude = true;
[136] Fix | Delete
}
[137] Fix | Delete
// Returns their value as state in the prior define methods
[138] Fix | Delete
return words[word];
[139] Fix | Delete
}
[140] Fix | Delete
// Is there a match on a reference?
[141] Fix | Delete
if (/(^|\s+)[A-Z][\w:_]+/.test(word)) {
[142] Fix | Delete
// Negate the next()
[143] Fix | Delete
stream.backUp(1);
[144] Fix | Delete
// Match the full reference
[145] Fix | Delete
stream.match(/(^|\s+)[A-Z][\w:_]+/);
[146] Fix | Delete
return 'def';
[147] Fix | Delete
}
[148] Fix | Delete
// Have we matched the prior resource regex?
[149] Fix | Delete
if (resource) {
[150] Fix | Delete
stream.match(/(\s+)?[\w:_]+/);
[151] Fix | Delete
return 'def';
[152] Fix | Delete
}
[153] Fix | Delete
// Have we matched the prior special_resource regex?
[154] Fix | Delete
if (special_resource) {
[155] Fix | Delete
stream.match(/(\s+)?[@]{1,2}/);
[156] Fix | Delete
return 'special';
[157] Fix | Delete
}
[158] Fix | Delete
// Match all the comments. All of them.
[159] Fix | Delete
if (ch == "#") {
[160] Fix | Delete
stream.skipToEnd();
[161] Fix | Delete
return "comment";
[162] Fix | Delete
}
[163] Fix | Delete
// Have we found a string?
[164] Fix | Delete
if (ch == "'" || ch == '"') {
[165] Fix | Delete
// Store the type (single or double)
[166] Fix | Delete
state.pending = ch;
[167] Fix | Delete
// Perform the looping function to find the end
[168] Fix | Delete
return tokenString(stream, state);
[169] Fix | Delete
}
[170] Fix | Delete
// Match all the brackets
[171] Fix | Delete
if (ch == '{' || ch == '}') {
[172] Fix | Delete
return 'bracket';
[173] Fix | Delete
}
[174] Fix | Delete
// Match characters that we are going to assume
[175] Fix | Delete
// are trying to be regex
[176] Fix | Delete
if (ch == '/') {
[177] Fix | Delete
stream.match(/.*?\//);
[178] Fix | Delete
return 'variable-3';
[179] Fix | Delete
}
[180] Fix | Delete
// Match all the numbers
[181] Fix | Delete
if (ch.match(/[0-9]/)) {
[182] Fix | Delete
stream.eatWhile(/[0-9]+/);
[183] Fix | Delete
return 'number';
[184] Fix | Delete
}
[185] Fix | Delete
// Match the '=' and '=>' operators
[186] Fix | Delete
if (ch == '=') {
[187] Fix | Delete
if (stream.peek() == '>') {
[188] Fix | Delete
stream.next();
[189] Fix | Delete
}
[190] Fix | Delete
return "operator";
[191] Fix | Delete
}
[192] Fix | Delete
// Keep advancing through all the rest
[193] Fix | Delete
stream.eatWhile(/[\w-]/);
[194] Fix | Delete
// Return a blank line for everything else
[195] Fix | Delete
return null;
[196] Fix | Delete
}
[197] Fix | Delete
// Start it all
[198] Fix | Delete
return {
[199] Fix | Delete
startState: function () {
[200] Fix | Delete
var state = {};
[201] Fix | Delete
state.inDefinition = false;
[202] Fix | Delete
state.inInclude = false;
[203] Fix | Delete
state.continueString = false;
[204] Fix | Delete
state.pending = false;
[205] Fix | Delete
return state;
[206] Fix | Delete
},
[207] Fix | Delete
token: function (stream, state) {
[208] Fix | Delete
// Strip the spaces, but regex will account for them eitherway
[209] Fix | Delete
if (stream.eatSpace()) return null;
[210] Fix | Delete
// Go through the main process
[211] Fix | Delete
return tokenize(stream, state);
[212] Fix | Delete
}
[213] Fix | Delete
};
[214] Fix | Delete
});
[215] Fix | Delete
[216] Fix | Delete
CodeMirror.defineMIME("text/x-puppet", "puppet");
[217] Fix | Delete
[218] Fix | Delete
});
[219] Fix | Delete
[220] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function