MCPcopy Create free account
hub / github.com/TruthHun/BookStack / tokenize

Function tokenize

static/editor.md/lib/codemirror/mode/puppet/puppet.js:68–198  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

66
67 // Main function
68 function tokenize(stream, state) {
69 // Matches one whole word
70 var word = stream.match(/[\w]+/, false);
71 // Matches attributes (i.e. ensure => present ; 'ensure' would be matched)
72 var attribute = stream.match(/(\s+)?\w+\s+=>.*/, false);
73 // Matches non-builtin resource declarations
74 // (i.e. "apache::vhost {" or "mycustomclasss {" would be matched)
75 var resource = stream.match(/(\s+)?[\w:_]+(\s+)?{/, false);
76 // Matches virtual and exported resources (i.e. @@user { ; and the like)
77 var special_resource = stream.match(/(\s+)?[@]{1,2}[\w:_]+(\s+)?{/, false);
78
79 // Finally advance the stream
80 var ch = stream.next();
81
82 // Have we found a variable?
83 if (ch === '$') {
84 if (stream.match(variable_regex)) {
85 // If so, and its in a string, assign it a different color
86 return state.continueString ? 'variable-2' : 'variable';
87 }
88 // Otherwise return an invalid variable
89 return "error";
90 }
91 // Should we still be looking for the end of a string?
92 if (state.continueString) {
93 // If so, go through the loop again
94 stream.backUp(1);
95 return tokenString(stream, state);
96 }
97 // Are we in a definition (class, node, define)?
98 if (state.inDefinition) {
99 // If so, return def (i.e. for 'class myclass {' ; 'myclass' would be matched)
100 if (stream.match(/(\s+)?[\w:_]+(\s+)?/)) {
101 return 'def';
102 }
103 // Match the rest it the next time around
104 stream.match(/\s+{/);
105 state.inDefinition = false;
106 }
107 // Are we in an 'include' statement?
108 if (state.inInclude) {
109 // Match and return the included class
110 stream.match(/(\s+)?\S+(\s+)?/);
111 state.inInclude = false;
112 return 'def';
113 }
114 // Do we just have a function on our hands?
115 // In 'ensure_resource("myclass")', 'ensure_resource' is matched
116 if (stream.match(/(\s+)?\w+\(/)) {
117 stream.backUp(1);
118 return 'def';
119 }
120 // Have we matched the prior attribute regex?
121 if (attribute) {
122 stream.match(/(\s+)?\w+/);
123 return 'tag';
124 }
125 // Do we have Puppet specific words?

Callers 1

puppet.jsFile · 0.70

Calls 1

tokenStringFunction · 0.70

Tested by

no test coverage detected