codemirror-rails 2.21.1 → 2.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/README.md +8 -0
  2. data/lib/codemirror/rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/codemirror.js +160 -86
  4. data/vendor/assets/javascripts/codemirror/modes/clike.js +2 -2
  5. data/vendor/assets/javascripts/codemirror/modes/clojure.js +1 -1
  6. data/vendor/assets/javascripts/codemirror/modes/ecl.js +203 -0
  7. data/vendor/assets/javascripts/codemirror/modes/gfm.js +1 -1
  8. data/vendor/assets/javascripts/codemirror/modes/go.js +20 -22
  9. data/vendor/assets/javascripts/codemirror/modes/less.js +5 -2
  10. data/vendor/assets/javascripts/codemirror/modes/markdown.js +58 -24
  11. data/vendor/assets/javascripts/codemirror/modes/pascal.js +2 -46
  12. data/vendor/assets/javascripts/codemirror/modes/perl.js +1 -1
  13. data/vendor/assets/javascripts/codemirror/modes/php.js +53 -24
  14. data/vendor/assets/javascripts/codemirror/modes/properties.js +57 -0
  15. data/vendor/assets/javascripts/codemirror/modes/rpm-spec.css +5 -0
  16. data/vendor/assets/javascripts/codemirror/modes/rpm-spec.js +1 -1
  17. data/vendor/assets/javascripts/codemirror/modes/ruby.js +1 -1
  18. data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +16 -16
  19. data/vendor/assets/javascripts/codemirror/modes/verilog.js +194 -194
  20. data/vendor/assets/javascripts/codemirror/modes/xml.js +15 -8
  21. data/vendor/assets/javascripts/codemirror/utils/dialog.js +63 -0
  22. data/vendor/assets/javascripts/codemirror/utils/foldcode.js +186 -0
  23. data/vendor/assets/javascripts/codemirror/utils/formatting.js +294 -0
  24. data/vendor/assets/javascripts/codemirror/utils/javascript-hint.js +132 -0
  25. data/vendor/assets/javascripts/codemirror/utils/match-highlighter.js +44 -0
  26. data/vendor/assets/javascripts/codemirror/{overlay.js → utils/overlay.js} +0 -0
  27. data/vendor/assets/javascripts/codemirror/utils/runmode.js +49 -0
  28. data/vendor/assets/javascripts/codemirror/utils/search.js +114 -0
  29. data/vendor/assets/javascripts/codemirror/utils/searchcursor.js +117 -0
  30. data/vendor/assets/javascripts/codemirror/utils/simple-hint.js +66 -0
  31. data/vendor/assets/stylesheets/codemirror.css +3 -0
  32. data/vendor/assets/stylesheets/codemirror/modes/properties.css +3 -0
  33. data/vendor/assets/stylesheets/codemirror/themes/rubyblue.css +1 -1
  34. data/vendor/assets/stylesheets/codemirror/utils/dialog.css +23 -0
  35. data/vendor/assets/stylesheets/codemirror/utils/simple-hint.css +16 -0
  36. metadata +20 -6
  37. data/vendor/assets/javascripts/codemirror/runmode.js +0 -27
@@ -7,11 +7,9 @@ CodeMirror.defineMode("pascal", function(config) {
7
7
  var keywords = words("and array begin case const div do downto else end file for forward integer " +
8
8
  "boolean char function goto if in label mod nil not of or packed procedure " +
9
9
  "program record repeat set string then to type until var while with");
10
- var blockKeywords = words("case do else for if switch while struct then of");
11
10
  var atoms = {"null": true};
12
11
 
13
12
  var isOperatorChar = /[+\-*&%=<>!?|\/]/;
14
- var curPunc;
15
13
 
16
14
  function tokenBase(stream, state) {
17
15
  var ch = stream.next();
@@ -28,7 +26,6 @@ CodeMirror.defineMode("pascal", function(config) {
28
26
  return tokenComment(stream, state);
29
27
  }
30
28
  if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
31
- curPunc = ch;
32
29
  return null
33
30
  }
34
31
  if (/\d/.test(ch)) {
@@ -47,10 +44,7 @@ CodeMirror.defineMode("pascal", function(config) {
47
44
  }
48
45
  stream.eatWhile(/[\w\$_]/);
49
46
  var cur = stream.current();
50
- if (keywords.propertyIsEnumerable(cur)) {
51
- if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
52
- return "keyword";
53
- }
47
+ if (keywords.propertyIsEnumerable(cur)) return "keyword";
54
48
  if (atoms.propertyIsEnumerable(cur)) return "atom";
55
49
  return "word";
56
50
  }
@@ -79,55 +73,17 @@ CodeMirror.defineMode("pascal", function(config) {
79
73
  return "comment";
80
74
  }
81
75
 
82
- function Context(indented, column, type, align, prev) {
83
- this.indented = indented;
84
- this.column = column;
85
- this.type = type;
86
- this.align = align;
87
- this.prev = prev;
88
- }
89
- function pushContext(state, col, type) {
90
- return state.context = new Context(state.indented, col, type, null, state.context);
91
- }
92
- function popContext(state) {
93
- var t = state.context.type;
94
- if (t == ")" || t == "]" )
95
- state.indented = state.context.indented;
96
- return state.context = state.context.prev;
97
- }
98
-
99
76
  // Interface
100
77
 
101
78
  return {
102
79
  startState: function(basecolumn) {
103
- return {
104
- tokenize: null,
105
- context: new Context((basecolumn || 0) - config.indentUnit, 0, "top", false),
106
- indented: 0,
107
- startOfLine: true
108
- };
80
+ return {tokenize: null};
109
81
  },
110
82
 
111
83
  token: function(stream, state) {
112
- var ctx = state.context;
113
- if (stream.sol()) {
114
- if (ctx.align == null) ctx.align = false;
115
- state.indented = stream.indentation();
116
- state.startOfLine = true;
117
- }
118
84
  if (stream.eatSpace()) return null;
119
- curPunc = null;
120
85
  var style = (state.tokenize || tokenBase)(stream, state);
121
86
  if (style == "comment" || style == "meta") return style;
122
- if (ctx.align == null) ctx.align = true;
123
-
124
- if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
125
- else if (curPunc == "[") pushContext(state, stream.column(), "]");
126
- else if (curPunc == "(") pushContext(state, stream.column(), ")");
127
- else if (curPunc == ctx.type) popContext(state);
128
- else if ( ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
129
- pushContext(state, stream.column(), "statement");
130
- state.startOfLine = false;
131
87
  return style;
132
88
  },
133
89
 
@@ -324,7 +324,7 @@ CodeMirror.defineMode("perl",function(config,parserConfig){
324
324
  hex :1, // - convert a string to a hexadecimal number
325
325
  'import' :1, // - patch a module's namespace into your own
326
326
  index :1, // - find a substring within a string
327
- int :1, // - get the integer portion of a number
327
+ 'int' :1, // - get the integer portion of a number
328
328
  ioctl :1, // - system-dependent device control system call
329
329
  'join' :1, // - join a list into a string using a separator
330
330
  keys :1, // - retrieve list of indices from a hash
@@ -13,11 +13,12 @@
13
13
  }
14
14
  var phpConfig = {
15
15
  name: "clike",
16
- keywords: keywords("abstract and array as break case catch cfunction class clone const continue declare " +
17
- "default do else elseif enddeclare endfor endforeach endif endswitch endwhile extends " +
18
- "final for foreach function global goto if implements interface instanceof namespace " +
19
- "new or private protected public static switch throw try use var while xor return" +
20
- "die echo empty exit eval include include_once isset list require require_once print unset"),
16
+ keywords: keywords("abstract and array as break case catch class clone const continue declare default " +
17
+ "do else elseif enddeclare endfor endforeach endif endswitch endwhile extends final " +
18
+ "for foreach function global goto if implements interface instanceof namespace " +
19
+ "new or private protected public static switch throw trait try use var while xor " +
20
+ "die echo empty exit eval include include_once isset list require require_once return " +
21
+ "print unset __halt_compiler self static parent"),
21
22
  blockKeywords: keywords("catch do else elseif for foreach if switch try while"),
22
23
  atoms: keywords("true false null TRUE FALSE NULL"),
23
24
  multiLineStrings: true,
@@ -35,8 +36,15 @@
35
36
  return false;
36
37
  },
37
38
  "#": function(stream, state) {
38
- stream.skipToEnd();
39
+ while (!stream.eol() && !stream.match("?>", false)) stream.next();
39
40
  return "comment";
41
+ },
42
+ "/": function(stream, state) {
43
+ if (stream.eat("/")) {
44
+ while (!stream.eol() && !stream.match("?>", false)) stream.next();
45
+ return "comment";
46
+ }
47
+ return false;
40
48
  }
41
49
  }
42
50
  };
@@ -48,38 +56,57 @@
48
56
  var phpMode = CodeMirror.getMode(config, phpConfig);
49
57
 
50
58
  function dispatch(stream, state) { // TODO open PHP inside text/css
59
+ var isPHP = state.mode == "php";
60
+ if (stream.sol() && state.pending != '"') state.pending = null;
51
61
  if (state.curMode == htmlMode) {
52
- var style = htmlMode.token(stream, state.curState);
53
- if (style == "meta" && /^<\?/.test(stream.current())) {
62
+ if (stream.match(/^<\?\w*/)) {
54
63
  state.curMode = phpMode;
55
64
  state.curState = state.php;
56
- state.curClose = /^\?>/;
57
- state.mode = 'php';
65
+ state.curClose = "?>";
66
+ state.mode = "php";
67
+ return "meta";
58
68
  }
59
- else if (style == "tag" && stream.current() == ">" && state.curState.context) {
69
+ if (state.pending == '"') {
70
+ while (!stream.eol() && stream.next() != '"') {}
71
+ var style = "string";
72
+ } else if (state.pending && stream.pos < state.pending.end) {
73
+ stream.pos = state.pending.end;
74
+ var style = state.pending.style;
75
+ } else {
76
+ var style = htmlMode.token(stream, state.curState);
77
+ }
78
+ state.pending = null;
79
+ var cur = stream.current(), openPHP = cur.search(/<\?/);
80
+ if (openPHP != -1) {
81
+ if (style == "string" && /\"$/.test(cur) && !/\?>/.test(cur)) state.pending = '"';
82
+ else state.pending = {end: stream.pos, style: style};
83
+ stream.backUp(cur.length - openPHP);
84
+ } else if (style == "tag" && stream.current() == ">" && state.curState.context) {
60
85
  if (/^script$/i.test(state.curState.context.tagName)) {
61
86
  state.curMode = jsMode;
62
87
  state.curState = jsMode.startState(htmlMode.indent(state.curState, ""));
63
88
  state.curClose = /^<\/\s*script\s*>/i;
64
- state.mode = 'javascript';
89
+ state.mode = "javascript";
65
90
  }
66
91
  else if (/^style$/i.test(state.curState.context.tagName)) {
67
92
  state.curMode = cssMode;
68
93
  state.curState = cssMode.startState(htmlMode.indent(state.curState, ""));
69
- state.curClose = /^<\/\s*style\s*>/i;
70
- state.mode = 'css';
94
+ state.curClose = /^<\/\s*style\s*>/i;
95
+ state.mode = "css";
71
96
  }
72
97
  }
73
98
  return style;
74
- }
75
- else if (stream.match(state.curClose, false)) {
99
+ } else if ((!isPHP || state.php.tokenize == null) &&
100
+ stream.match(state.curClose, isPHP)) {
76
101
  state.curMode = htmlMode;
77
102
  state.curState = state.html;
78
103
  state.curClose = null;
79
- state.mode = 'html';
80
- return dispatch(stream, state);
104
+ state.mode = "html";
105
+ if (isPHP) return "meta";
106
+ else return dispatch(stream, state);
107
+ } else {
108
+ return state.curMode.token(stream, state.curState);
81
109
  }
82
- else return state.curMode.token(stream, state.curState);
83
110
  }
84
111
 
85
112
  return {
@@ -87,10 +114,11 @@
87
114
  var html = htmlMode.startState();
88
115
  return {html: html,
89
116
  php: phpMode.startState(),
90
- curMode: parserConfig.startOpen ? phpMode : htmlMode,
91
- curState: parserConfig.startOpen ? phpMode.startState() : html,
92
- curClose: parserConfig.startOpen ? /^\?>/ : null,
93
- mode: parserConfig.startOpen ? 'php' : 'html'}
117
+ curMode: parserConfig.startOpen ? phpMode : htmlMode,
118
+ curState: parserConfig.startOpen ? phpMode.startState() : html,
119
+ curClose: parserConfig.startOpen ? /^\?>/ : null,
120
+ mode: parserConfig.startOpen ? "php" : "html",
121
+ pending: null}
94
122
  },
95
123
 
96
124
  copyState: function(state) {
@@ -100,7 +128,8 @@
100
128
  else if (state.curState == php) cur = phpNew;
101
129
  else cur = CodeMirror.copyState(state.curMode, state.curState);
102
130
  return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur,
103
- curClose: state.curClose, mode: state.mode};
131
+ curClose: state.curClose, mode: state.mode,
132
+ pending: state.pending};
104
133
  },
105
134
 
106
135
  token: dispatch,
@@ -0,0 +1,57 @@
1
+ CodeMirror.defineMode("properties", function() {
2
+ return {
3
+ token: function(stream, state) {
4
+ var sol = stream.sol();
5
+ var eol = stream.eol();
6
+
7
+ if (sol) {
8
+ if (state.nextMultiline) {
9
+ state.inMultiline = true;
10
+ state.nextMultiline = false;
11
+ } else {
12
+ state.position = "key";
13
+ }
14
+ }
15
+
16
+ if (eol && ! state.nextMultiline) {
17
+ state.inMultiline = false;
18
+ state.position = "key";
19
+ }
20
+
21
+ if (sol) {
22
+ while(stream.eatSpace());
23
+ }
24
+
25
+ var ch = stream.next();
26
+
27
+ if (sol && (ch === "#" || ch === "!")) {
28
+ state.position = "comment";
29
+ stream.skipToEnd();
30
+ return "comment";
31
+
32
+ } else if (ch === "=" || ch === ":") {
33
+ state.position = "value";
34
+ return "equals";
35
+
36
+ } else if (ch === "\\" && state.position === "value") {
37
+ if (stream.next() !== "u") { // u = Unicode sequence \u1234
38
+ // Multiline value
39
+ state.nextMultiline = true;
40
+ }
41
+ }
42
+
43
+ return state.position;
44
+ },
45
+
46
+ startState: function() {
47
+ return {
48
+ position : "key", // Current position, "key", "value" or "comment"
49
+ nextMultiline : false, // Is the next line multiline value
50
+ inMultiline : false // Is the current line a multiline value
51
+ };
52
+ }
53
+
54
+ };
55
+ });
56
+
57
+ CodeMirror.defineMIME("text/x-properties", "properties");
@@ -0,0 +1,5 @@
1
+ .cm-s-default span.cm-preamble {color: #b26818; font-weight: bold;}
2
+ .cm-s-default span.cm-macro {color: #b218b2;}
3
+ .cm-s-default span.cm-section {color: green; font-weight: bold;}
4
+ .cm-s-default span.cm-script {color: red;}
5
+ .cm-s-default span.cm-issue {color: yellow;}
@@ -14,7 +14,7 @@ CodeMirror.defineMode("spec", function(config, modeConfig) {
14
14
  return {
15
15
  controlFlow: false,
16
16
  macroParameters: false,
17
- section: false,
17
+ section: false
18
18
  };
19
19
  },
20
20
  token: function (stream, state) {
@@ -33,7 +33,7 @@ CodeMirror.defineMode("ruby", function(config, parserConfig) {
33
33
  var ch = stream.next();
34
34
  if (ch == "`" || ch == "'" || ch == '"' ||
35
35
  (ch == "/" && !stream.eol() && stream.peek() != " ")) {
36
- return chain(readQuoted(ch, "string", ch == '"'), stream, state);
36
+ return chain(readQuoted(ch, "string", ch == '"' || ch == "`"), stream, state);
37
37
  } else if (ch == "%") {
38
38
  var style, embed = false;
39
39
  if (stream.eat("s")) style = "atom";
@@ -27,45 +27,45 @@ CodeMirror.defineMode('smalltalk', function(config, modeConfig) {
27
27
 
28
28
  var next = function(stream, context, state) {
29
29
  var token = new Token(null, context, false);
30
- var char = stream.next();
30
+ var aChar = stream.next();
31
31
 
32
- if (char === '"') {
32
+ if (aChar === '"') {
33
33
  token = nextComment(stream, new Context(nextComment, context));
34
34
 
35
- } else if (char === '\'') {
35
+ } else if (aChar === '\'') {
36
36
  token = nextString(stream, new Context(nextString, context));
37
37
 
38
- } else if (char === '#') {
38
+ } else if (aChar === '#') {
39
39
  stream.eatWhile(/[^ .]/);
40
40
  token.name = 'string-2';
41
41
 
42
- } else if (char === '$') {
42
+ } else if (aChar === '$') {
43
43
  stream.eatWhile(/[^ ]/);
44
44
  token.name = 'string-2';
45
45
 
46
- } else if (char === '|' && state.expectVariable) {
46
+ } else if (aChar === '|' && state.expectVariable) {
47
47
  token.context = new Context(nextTemporaries, context);
48
48
 
49
- } else if (/[\[\]{}()]/.test(char)) {
49
+ } else if (/[\[\]{}()]/.test(aChar)) {
50
50
  token.name = 'bracket';
51
- token.eos = /[\[{(]/.test(char);
51
+ token.eos = /[\[{(]/.test(aChar);
52
52
 
53
- if (char === '[') {
53
+ if (aChar === '[') {
54
54
  state.indentation++;
55
- } else if (char === ']') {
55
+ } else if (aChar === ']') {
56
56
  state.indentation = Math.max(0, state.indentation - 1);
57
57
  }
58
58
 
59
- } else if (specialChars.test(char)) {
59
+ } else if (specialChars.test(aChar)) {
60
60
  stream.eatWhile(specialChars);
61
61
  token.name = 'operator';
62
- token.eos = char !== ';'; // ; cascaded message expression
62
+ token.eos = aChar !== ';'; // ; cascaded message expression
63
63
 
64
- } else if (/\d/.test(char)) {
64
+ } else if (/\d/.test(aChar)) {
65
65
  stream.eatWhile(/[\w\d]/);
66
66
  token.name = 'number'
67
67
 
68
- } else if (/[\w_]/.test(char)) {
68
+ } else if (/[\w_]/.test(aChar)) {
69
69
  stream.eatWhile(/[\w\d_]/);
70
70
  token.name = state.expectVariable ? (keywords.test(stream.current()) ? 'keyword' : 'variable') : null;
71
71
 
@@ -88,9 +88,9 @@ CodeMirror.defineMode('smalltalk', function(config, modeConfig) {
88
88
 
89
89
  var nextTemporaries = function(stream, context, state) {
90
90
  var token = new Token(null, context, false);
91
- var char = stream.next();
91
+ var aChar = stream.next();
92
92
 
93
- if (char === '|') {
93
+ if (aChar === '|') {
94
94
  token.context = context.parent;
95
95
  token.eos = true;
96
96
 
@@ -1,194 +1,194 @@
1
- CodeMirror.defineMode("verilog", function(config, parserConfig) {
2
- var indentUnit = config.indentUnit,
3
- keywords = parserConfig.keywords || {},
4
- blockKeywords = parserConfig.blockKeywords || {},
5
- atoms = parserConfig.atoms || {},
6
- hooks = parserConfig.hooks || {},
7
- multiLineStrings = parserConfig.multiLineStrings;
8
- var isOperatorChar = /[&|~><!\)\(*#%@+\/=?\:;}{,\.\^\-\[\]]/;
9
-
10
- var curPunc;
11
-
12
- function tokenBase(stream, state) {
13
- var ch = stream.next();
14
- if (hooks[ch]) {
15
- var result = hooks[ch](stream, state);
16
- if (result !== false) return result;
17
- }
18
- if (ch == '"') {
19
- state.tokenize = tokenString(ch);
20
- return state.tokenize(stream, state);
21
- }
22
- if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
23
- curPunc = ch;
24
- return null
25
- }
26
- if (/[\d']/.test(ch)) {
27
- stream.eatWhile(/[\w\.']/);
28
- return "number";
29
- }
30
- if (ch == "/") {
31
- if (stream.eat("*")) {
32
- state.tokenize = tokenComment;
33
- return tokenComment(stream, state);
34
- }
35
- if (stream.eat("/")) {
36
- stream.skipToEnd();
37
- return "comment";
38
- }
39
- }
40
- if (isOperatorChar.test(ch)) {
41
- stream.eatWhile(isOperatorChar);
42
- return "operator";
43
- }
44
- stream.eatWhile(/[\w\$_]/);
45
- var cur = stream.current();
46
- if (keywords.propertyIsEnumerable(cur)) {
47
- if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
48
- return "keyword";
49
- }
50
- if (atoms.propertyIsEnumerable(cur)) return "atom";
51
- return "word";
52
- }
53
-
54
- function tokenString(quote) {
55
- return function(stream, state) {
56
- var escaped = false, next, end = false;
57
- while ((next = stream.next()) != null) {
58
- if (next == quote && !escaped) {end = true; break;}
59
- escaped = !escaped && next == "\\";
60
- }
61
- if (end || !(escaped || multiLineStrings))
62
- state.tokenize = tokenBase;
63
- return "string";
64
- };
65
- }
66
-
67
- function tokenComment(stream, state) {
68
- var maybeEnd = false, ch;
69
- while (ch = stream.next()) {
70
- if (ch == "/" && maybeEnd) {
71
- state.tokenize = tokenBase;
72
- break;
73
- }
74
- maybeEnd = (ch == "*");
75
- }
76
- return "comment";
77
- }
78
-
79
- function Context(indented, column, type, align, prev) {
80
- this.indented = indented;
81
- this.column = column;
82
- this.type = type;
83
- this.align = align;
84
- this.prev = prev;
85
- }
86
- function pushContext(state, col, type) {
87
- return state.context = new Context(state.indented, col, type, null, state.context);
88
- }
89
- function popContext(state) {
90
- var t = state.context.type;
91
- if (t == ")" || t == "]" || t == "}")
92
- state.indented = state.context.indented;
93
- return state.context = state.context.prev;
94
- }
95
-
96
- // Interface
97
-
98
- return {
99
- startState: function(basecolumn) {
100
- return {
101
- tokenize: null,
102
- context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
103
- indented: 0,
104
- startOfLine: true
105
- };
106
- },
107
-
108
- token: function(stream, state) {
109
- var ctx = state.context;
110
- if (stream.sol()) {
111
- if (ctx.align == null) ctx.align = false;
112
- state.indented = stream.indentation();
113
- state.startOfLine = true;
114
- }
115
- if (stream.eatSpace()) return null;
116
- curPunc = null;
117
- var style = (state.tokenize || tokenBase)(stream, state);
118
- if (style == "comment" || style == "meta") return style;
119
- if (ctx.align == null) ctx.align = true;
120
-
121
- if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
122
- else if (curPunc == "{") pushContext(state, stream.column(), "}");
123
- else if (curPunc == "[") pushContext(state, stream.column(), "]");
124
- else if (curPunc == "(") pushContext(state, stream.column(), ")");
125
- else if (curPunc == "}") {
126
- while (ctx.type == "statement") ctx = popContext(state);
127
- if (ctx.type == "}") ctx = popContext(state);
128
- while (ctx.type == "statement") ctx = popContext(state);
129
- }
130
- else if (curPunc == ctx.type) popContext(state);
131
- else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
132
- pushContext(state, stream.column(), "statement");
133
- state.startOfLine = false;
134
- return style;
135
- },
136
-
137
- indent: function(state, textAfter) {
138
- if (state.tokenize != tokenBase && state.tokenize != null) return 0;
139
- var firstChar = textAfter && textAfter.charAt(0), ctx = state.context, closing = firstChar == ctx.type;
140
- if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
141
- else if (ctx.align) return ctx.column + (closing ? 0 : 1);
142
- else return ctx.indented + (closing ? 0 : indentUnit);
143
- },
144
-
145
- electricChars: "{}"
146
- };
147
- });
148
-
149
- (function() {
150
- function words(str) {
151
- var obj = {}, words = str.split(" ");
152
- for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
153
- return obj;
154
- }
155
-
156
- var verilogKeywords = "always and assign automatic begin buf bufif0 bufif1 case casex casez cell cmos config " +
157
- "deassign default defparam design disable edge else end endcase endconfig endfunction endgenerate endmodule " +
158
- "endprimitive endspecify endtable endtask event for force forever fork function generate genvar highz0 " +
159
- "highz1 if ifnone incdir include initial inout input instance integer join large liblist library localparam " +
160
- "macromodule medium module nand negedge nmos nor noshowcancelled not notif0 notif1 or output parameter pmos " +
161
- "posedge primitive pull0 pull1 pulldown pullup pulsestyle_onevent pulsestyle_ondetect rcmos real realtime " +
162
- "reg release repeat rnmos rpmos rtran rtranif0 rtranif1 scalared showcancelled signed small specify specparam " +
163
- "strong0 strong1 supply0 supply1 table task time tran tranif0 tranif1 tri tri0 tri1 triand trior trireg " +
164
- "unsigned use vectored wait wand weak0 weak1 while wire wor xnor xor";
165
-
166
- var verilogBlockKeywords = "begin bufif0 bufif1 case casex casez config else end endcase endconfig endfunction " +
167
- "endgenerate endmodule endprimitive endspecify endtable endtask for forever function generate if ifnone " +
168
- "macromodule module primitive repeat specify table task while";
169
-
170
- function metaHook(stream, state) {
171
- stream.eatWhile(/[\w\$_]/);
172
- return "meta";
173
- }
174
-
175
- // C#-style strings where "" escapes a quote.
176
- function tokenAtString(stream, state) {
177
- var next;
178
- while ((next = stream.next()) != null) {
179
- if (next == '"' && !stream.eat('"')) {
180
- state.tokenize = null;
181
- break;
182
- }
183
- }
184
- return "string";
185
- }
186
-
187
- CodeMirror.defineMIME("text/x-verilog", {
188
- name: "verilog",
189
- keywords: words(verilogKeywords),
190
- blockKeywords: words(verilogBlockKeywords),
191
- atoms: words("null"),
192
- hooks: {"`": metaHook, "$": metaHook}
193
- });
194
- }());
1
+ CodeMirror.defineMode("verilog", function(config, parserConfig) {
2
+ var indentUnit = config.indentUnit,
3
+ keywords = parserConfig.keywords || {},
4
+ blockKeywords = parserConfig.blockKeywords || {},
5
+ atoms = parserConfig.atoms || {},
6
+ hooks = parserConfig.hooks || {},
7
+ multiLineStrings = parserConfig.multiLineStrings;
8
+ var isOperatorChar = /[&|~><!\)\(*#%@+\/=?\:;}{,\.\^\-\[\]]/;
9
+
10
+ var curPunc;
11
+
12
+ function tokenBase(stream, state) {
13
+ var ch = stream.next();
14
+ if (hooks[ch]) {
15
+ var result = hooks[ch](stream, state);
16
+ if (result !== false) return result;
17
+ }
18
+ if (ch == '"') {
19
+ state.tokenize = tokenString(ch);
20
+ return state.tokenize(stream, state);
21
+ }
22
+ if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
23
+ curPunc = ch;
24
+ return null
25
+ }
26
+ if (/[\d']/.test(ch)) {
27
+ stream.eatWhile(/[\w\.']/);
28
+ return "number";
29
+ }
30
+ if (ch == "/") {
31
+ if (stream.eat("*")) {
32
+ state.tokenize = tokenComment;
33
+ return tokenComment(stream, state);
34
+ }
35
+ if (stream.eat("/")) {
36
+ stream.skipToEnd();
37
+ return "comment";
38
+ }
39
+ }
40
+ if (isOperatorChar.test(ch)) {
41
+ stream.eatWhile(isOperatorChar);
42
+ return "operator";
43
+ }
44
+ stream.eatWhile(/[\w\$_]/);
45
+ var cur = stream.current();
46
+ if (keywords.propertyIsEnumerable(cur)) {
47
+ if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
48
+ return "keyword";
49
+ }
50
+ if (atoms.propertyIsEnumerable(cur)) return "atom";
51
+ return "word";
52
+ }
53
+
54
+ function tokenString(quote) {
55
+ return function(stream, state) {
56
+ var escaped = false, next, end = false;
57
+ while ((next = stream.next()) != null) {
58
+ if (next == quote && !escaped) {end = true; break;}
59
+ escaped = !escaped && next == "\\";
60
+ }
61
+ if (end || !(escaped || multiLineStrings))
62
+ state.tokenize = tokenBase;
63
+ return "string";
64
+ };
65
+ }
66
+
67
+ function tokenComment(stream, state) {
68
+ var maybeEnd = false, ch;
69
+ while (ch = stream.next()) {
70
+ if (ch == "/" && maybeEnd) {
71
+ state.tokenize = tokenBase;
72
+ break;
73
+ }
74
+ maybeEnd = (ch == "*");
75
+ }
76
+ return "comment";
77
+ }
78
+
79
+ function Context(indented, column, type, align, prev) {
80
+ this.indented = indented;
81
+ this.column = column;
82
+ this.type = type;
83
+ this.align = align;
84
+ this.prev = prev;
85
+ }
86
+ function pushContext(state, col, type) {
87
+ return state.context = new Context(state.indented, col, type, null, state.context);
88
+ }
89
+ function popContext(state) {
90
+ var t = state.context.type;
91
+ if (t == ")" || t == "]" || t == "}")
92
+ state.indented = state.context.indented;
93
+ return state.context = state.context.prev;
94
+ }
95
+
96
+ // Interface
97
+
98
+ return {
99
+ startState: function(basecolumn) {
100
+ return {
101
+ tokenize: null,
102
+ context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
103
+ indented: 0,
104
+ startOfLine: true
105
+ };
106
+ },
107
+
108
+ token: function(stream, state) {
109
+ var ctx = state.context;
110
+ if (stream.sol()) {
111
+ if (ctx.align == null) ctx.align = false;
112
+ state.indented = stream.indentation();
113
+ state.startOfLine = true;
114
+ }
115
+ if (stream.eatSpace()) return null;
116
+ curPunc = null;
117
+ var style = (state.tokenize || tokenBase)(stream, state);
118
+ if (style == "comment" || style == "meta") return style;
119
+ if (ctx.align == null) ctx.align = true;
120
+
121
+ if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
122
+ else if (curPunc == "{") pushContext(state, stream.column(), "}");
123
+ else if (curPunc == "[") pushContext(state, stream.column(), "]");
124
+ else if (curPunc == "(") pushContext(state, stream.column(), ")");
125
+ else if (curPunc == "}") {
126
+ while (ctx.type == "statement") ctx = popContext(state);
127
+ if (ctx.type == "}") ctx = popContext(state);
128
+ while (ctx.type == "statement") ctx = popContext(state);
129
+ }
130
+ else if (curPunc == ctx.type) popContext(state);
131
+ else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
132
+ pushContext(state, stream.column(), "statement");
133
+ state.startOfLine = false;
134
+ return style;
135
+ },
136
+
137
+ indent: function(state, textAfter) {
138
+ if (state.tokenize != tokenBase && state.tokenize != null) return 0;
139
+ var firstChar = textAfter && textAfter.charAt(0), ctx = state.context, closing = firstChar == ctx.type;
140
+ if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
141
+ else if (ctx.align) return ctx.column + (closing ? 0 : 1);
142
+ else return ctx.indented + (closing ? 0 : indentUnit);
143
+ },
144
+
145
+ electricChars: "{}"
146
+ };
147
+ });
148
+
149
+ (function() {
150
+ function words(str) {
151
+ var obj = {}, words = str.split(" ");
152
+ for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
153
+ return obj;
154
+ }
155
+
156
+ var verilogKeywords = "always and assign automatic begin buf bufif0 bufif1 case casex casez cell cmos config " +
157
+ "deassign default defparam design disable edge else end endcase endconfig endfunction endgenerate endmodule " +
158
+ "endprimitive endspecify endtable endtask event for force forever fork function generate genvar highz0 " +
159
+ "highz1 if ifnone incdir include initial inout input instance integer join large liblist library localparam " +
160
+ "macromodule medium module nand negedge nmos nor noshowcancelled not notif0 notif1 or output parameter pmos " +
161
+ "posedge primitive pull0 pull1 pulldown pullup pulsestyle_onevent pulsestyle_ondetect rcmos real realtime " +
162
+ "reg release repeat rnmos rpmos rtran rtranif0 rtranif1 scalared showcancelled signed small specify specparam " +
163
+ "strong0 strong1 supply0 supply1 table task time tran tranif0 tranif1 tri tri0 tri1 triand trior trireg " +
164
+ "unsigned use vectored wait wand weak0 weak1 while wire wor xnor xor";
165
+
166
+ var verilogBlockKeywords = "begin bufif0 bufif1 case casex casez config else end endcase endconfig endfunction " +
167
+ "endgenerate endmodule endprimitive endspecify endtable endtask for forever function generate if ifnone " +
168
+ "macromodule module primitive repeat specify table task while";
169
+
170
+ function metaHook(stream, state) {
171
+ stream.eatWhile(/[\w\$_]/);
172
+ return "meta";
173
+ }
174
+
175
+ // C#-style strings where "" escapes a quote.
176
+ function tokenAtString(stream, state) {
177
+ var next;
178
+ while ((next = stream.next()) != null) {
179
+ if (next == '"' && !stream.eat('"')) {
180
+ state.tokenize = null;
181
+ break;
182
+ }
183
+ }
184
+ return "string";
185
+ }
186
+
187
+ CodeMirror.defineMIME("text/x-verilog", {
188
+ name: "verilog",
189
+ keywords: words(verilogKeywords),
190
+ blockKeywords: words(verilogBlockKeywords),
191
+ atoms: words("null"),
192
+ hooks: {"`": metaHook, "$": metaHook}
193
+ });
194
+ }());