|
|
@@ -7,42 +7,38 @@
|
|
|
"use strict";
|
|
|
|
|
|
CodeMirror.defineMode('host', function () {
|
|
|
+ function tokenBase(stream) {
|
|
|
+ if (stream.eatSpace()) return null;
|
|
|
|
|
|
- return {
|
|
|
- token: function(stream) {
|
|
|
- var tw_pos = stream.string.search(/[\t ]+?$/);
|
|
|
-
|
|
|
- //if (!stream.sol() || tw_pos === 0) {
|
|
|
- // stream.skipToEnd();
|
|
|
- //return ("error " + (TOKEN_NAMES[stream.string.charAt(0)] || '')).replace(/ $/, '');
|
|
|
- //}
|
|
|
- //console.log(stream.string);
|
|
|
-
|
|
|
- var c = stream.peek();
|
|
|
- var token_name;
|
|
|
- if (c == '#') {
|
|
|
- token_name = 'comment';
|
|
|
- //} else if (!stream.string.match(/^\s*[\d\.]+\s+\w/i)) {
|
|
|
- } else if (!stream.string.match(/^\s*([\d\.]+|[\da-f:\.%lo]+)\s+\w/i)) {
|
|
|
- token_name = 'error';
|
|
|
- } else {
|
|
|
- token_name = stream.skipToEnd();
|
|
|
- }
|
|
|
-
|
|
|
- //var ip = stream.string.match(/^[\d\.]+\s/);
|
|
|
- //if (ip) {
|
|
|
- // token_name = 'positive';
|
|
|
- // stream.pos = ip[0].length - 1;
|
|
|
- //}
|
|
|
-
|
|
|
- //if (tw_pos === -1) {
|
|
|
- // stream.skipToEnd();
|
|
|
- //} else {
|
|
|
- // stream.pos = tw_pos;
|
|
|
- //}
|
|
|
+ var sol = stream.sol();
|
|
|
+ var ch = stream.next();
|
|
|
+
|
|
|
+ if (ch === '#') {
|
|
|
stream.skipToEnd();
|
|
|
+ return 'comment';
|
|
|
+ }
|
|
|
+ if (!stream.string.match(/^\s*([\d\.]+|[\da-f:\.%lo]+)\s+\w/i)) {
|
|
|
+ return 'error';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (sol && ch.match(/[\w\.:%]/)) {
|
|
|
+ stream.eatWhile(/[\w\.:%]/);
|
|
|
+ return 'ip';
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- return token_name;
|
|
|
+ function tokenize(stream, state) {
|
|
|
+ return (state.tokens[0] || tokenBase)(stream, state);
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ startState: function () {
|
|
|
+ return {tokens: []};
|
|
|
+ },
|
|
|
+ token: function (stream, state) {
|
|
|
+ return tokenize(stream, state);
|
|
|
},
|
|
|
lineComment: '#'
|
|
|
};
|