2016-07-23 05:29:20 +00:00
|
|
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
2019-10-15 08:40:42 +00:00
|
|
|
// Distributed under an MIT license: https://codemirror.net/LICENSE
|
2016-07-23 05:29:20 +00:00
|
|
|
|
|
|
|
(function(mod) {
|
|
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
|
|
mod(require("../../lib/codemirror"));
|
|
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
|
|
define(["../../lib/codemirror"], mod);
|
|
|
|
else // Plain browser env
|
|
|
|
mod(CodeMirror);
|
|
|
|
})(function(CodeMirror) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
CodeMirror.defineMode('mllike', function(_config, parserConfig) {
|
|
|
|
var words = {
|
2019-10-15 08:40:42 +00:00
|
|
|
'as': 'keyword',
|
|
|
|
'do': 'keyword',
|
|
|
|
'else': 'keyword',
|
|
|
|
'end': 'keyword',
|
|
|
|
'exception': 'keyword',
|
|
|
|
'fun': 'keyword',
|
|
|
|
'functor': 'keyword',
|
|
|
|
'if': 'keyword',
|
2016-07-23 05:29:20 +00:00
|
|
|
'in': 'keyword',
|
2019-10-15 08:40:42 +00:00
|
|
|
'include': 'keyword',
|
|
|
|
'let': 'keyword',
|
2016-07-23 05:29:20 +00:00
|
|
|
'of': 'keyword',
|
2019-10-15 08:40:42 +00:00
|
|
|
'open': 'keyword',
|
|
|
|
'rec': 'keyword',
|
|
|
|
'struct': 'keyword',
|
2016-07-23 05:29:20 +00:00
|
|
|
'then': 'keyword',
|
|
|
|
'type': 'keyword',
|
2019-10-15 08:40:42 +00:00
|
|
|
'val': 'keyword',
|
|
|
|
'while': 'keyword',
|
|
|
|
'with': 'keyword'
|
2016-07-23 05:29:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var extraWords = parserConfig.extraWords || {};
|
|
|
|
for (var prop in extraWords) {
|
|
|
|
if (extraWords.hasOwnProperty(prop)) {
|
|
|
|
words[prop] = parserConfig.extraWords[prop];
|
|
|
|
}
|
|
|
|
}
|
2019-10-15 08:40:42 +00:00
|
|
|
var hintWords = [];
|
|
|
|
for (var k in words) { hintWords.push(k); }
|
|
|
|
CodeMirror.registerHelper("hintWords", "mllike", hintWords);
|
2016-07-23 05:29:20 +00:00
|
|
|
|
|
|
|
function tokenBase(stream, state) {
|
|
|
|
var ch = stream.next();
|
|
|
|
|
|
|
|
if (ch === '"') {
|
|
|
|
state.tokenize = tokenString;
|
|
|
|
return state.tokenize(stream, state);
|
|
|
|
}
|
2019-10-15 08:40:42 +00:00
|
|
|
if (ch === '{') {
|
|
|
|
if (stream.eat('|')) {
|
|
|
|
state.longString = true;
|
|
|
|
state.tokenize = tokenLongString;
|
|
|
|
return state.tokenize(stream, state);
|
|
|
|
}
|
|
|
|
}
|
2016-07-23 05:29:20 +00:00
|
|
|
if (ch === '(') {
|
|
|
|
if (stream.eat('*')) {
|
|
|
|
state.commentLevel++;
|
|
|
|
state.tokenize = tokenComment;
|
|
|
|
return state.tokenize(stream, state);
|
|
|
|
}
|
|
|
|
}
|
2019-10-15 08:40:42 +00:00
|
|
|
if (ch === '~' || ch === '?') {
|
2016-07-23 05:29:20 +00:00
|
|
|
stream.eatWhile(/\w/);
|
|
|
|
return 'variable-2';
|
|
|
|
}
|
|
|
|
if (ch === '`') {
|
|
|
|
stream.eatWhile(/\w/);
|
|
|
|
return 'quote';
|
|
|
|
}
|
|
|
|
if (ch === '/' && parserConfig.slashComments && stream.eat('/')) {
|
|
|
|
stream.skipToEnd();
|
|
|
|
return 'comment';
|
|
|
|
}
|
|
|
|
if (/\d/.test(ch)) {
|
2019-10-15 08:40:42 +00:00
|
|
|
if (ch === '0' && stream.eat(/[bB]/)) {
|
|
|
|
stream.eatWhile(/[01]/);
|
|
|
|
} if (ch === '0' && stream.eat(/[xX]/)) {
|
|
|
|
stream.eatWhile(/[0-9a-fA-F]/)
|
|
|
|
} if (ch === '0' && stream.eat(/[oO]/)) {
|
|
|
|
stream.eatWhile(/[0-7]/);
|
|
|
|
} else {
|
|
|
|
stream.eatWhile(/[\d_]/);
|
|
|
|
if (stream.eat('.')) {
|
|
|
|
stream.eatWhile(/[\d]/);
|
|
|
|
}
|
|
|
|
if (stream.eat(/[eE]/)) {
|
|
|
|
stream.eatWhile(/[\d\-+]/);
|
|
|
|
}
|
2016-07-23 05:29:20 +00:00
|
|
|
}
|
|
|
|
return 'number';
|
|
|
|
}
|
2019-10-15 08:40:42 +00:00
|
|
|
if ( /[+\-*&%=<>!?|@\.~:]/.test(ch)) {
|
2016-07-23 05:29:20 +00:00
|
|
|
return 'operator';
|
|
|
|
}
|
2019-10-15 08:40:42 +00:00
|
|
|
if (/[\w\xa1-\uffff]/.test(ch)) {
|
|
|
|
stream.eatWhile(/[\w\xa1-\uffff]/);
|
|
|
|
var cur = stream.current();
|
|
|
|
return words.hasOwnProperty(cur) ? words[cur] : 'variable';
|
|
|
|
}
|
|
|
|
return null
|
2016-07-23 05:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function tokenString(stream, state) {
|
|
|
|
var next, end = false, escaped = false;
|
|
|
|
while ((next = stream.next()) != null) {
|
|
|
|
if (next === '"' && !escaped) {
|
|
|
|
end = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
escaped = !escaped && next === '\\';
|
|
|
|
}
|
|
|
|
if (end && !escaped) {
|
|
|
|
state.tokenize = tokenBase;
|
|
|
|
}
|
|
|
|
return 'string';
|
|
|
|
};
|
|
|
|
|
|
|
|
function tokenComment(stream, state) {
|
|
|
|
var prev, next;
|
|
|
|
while(state.commentLevel > 0 && (next = stream.next()) != null) {
|
|
|
|
if (prev === '(' && next === '*') state.commentLevel++;
|
|
|
|
if (prev === '*' && next === ')') state.commentLevel--;
|
|
|
|
prev = next;
|
|
|
|
}
|
|
|
|
if (state.commentLevel <= 0) {
|
|
|
|
state.tokenize = tokenBase;
|
|
|
|
}
|
|
|
|
return 'comment';
|
|
|
|
}
|
|
|
|
|
2019-10-15 08:40:42 +00:00
|
|
|
function tokenLongString(stream, state) {
|
|
|
|
var prev, next;
|
|
|
|
while (state.longString && (next = stream.next()) != null) {
|
|
|
|
if (prev === '|' && next === '}') state.longString = false;
|
|
|
|
prev = next;
|
|
|
|
}
|
|
|
|
if (!state.longString) {
|
|
|
|
state.tokenize = tokenBase;
|
|
|
|
}
|
|
|
|
return 'string';
|
|
|
|
}
|
|
|
|
|
2016-07-23 05:29:20 +00:00
|
|
|
return {
|
2019-10-15 08:40:42 +00:00
|
|
|
startState: function() {return {tokenize: tokenBase, commentLevel: 0, longString: false};},
|
2016-07-23 05:29:20 +00:00
|
|
|
token: function(stream, state) {
|
|
|
|
if (stream.eatSpace()) return null;
|
|
|
|
return state.tokenize(stream, state);
|
|
|
|
},
|
|
|
|
|
|
|
|
blockCommentStart: "(*",
|
|
|
|
blockCommentEnd: "*)",
|
|
|
|
lineComment: parserConfig.slashComments ? "//" : null
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
CodeMirror.defineMIME('text/x-ocaml', {
|
|
|
|
name: 'mllike',
|
|
|
|
extraWords: {
|
2019-10-15 08:40:42 +00:00
|
|
|
'and': 'keyword',
|
|
|
|
'assert': 'keyword',
|
|
|
|
'begin': 'keyword',
|
|
|
|
'class': 'keyword',
|
|
|
|
'constraint': 'keyword',
|
|
|
|
'done': 'keyword',
|
|
|
|
'downto': 'keyword',
|
|
|
|
'external': 'keyword',
|
|
|
|
'function': 'keyword',
|
|
|
|
'initializer': 'keyword',
|
|
|
|
'lazy': 'keyword',
|
|
|
|
'match': 'keyword',
|
|
|
|
'method': 'keyword',
|
|
|
|
'module': 'keyword',
|
|
|
|
'mutable': 'keyword',
|
|
|
|
'new': 'keyword',
|
|
|
|
'nonrec': 'keyword',
|
|
|
|
'object': 'keyword',
|
|
|
|
'private': 'keyword',
|
|
|
|
'sig': 'keyword',
|
|
|
|
'to': 'keyword',
|
|
|
|
'try': 'keyword',
|
|
|
|
'value': 'keyword',
|
|
|
|
'virtual': 'keyword',
|
|
|
|
'when': 'keyword',
|
|
|
|
|
|
|
|
// builtins
|
|
|
|
'raise': 'builtin',
|
|
|
|
'failwith': 'builtin',
|
|
|
|
'true': 'builtin',
|
|
|
|
'false': 'builtin',
|
|
|
|
|
|
|
|
// Pervasives builtins
|
|
|
|
'asr': 'builtin',
|
|
|
|
'land': 'builtin',
|
|
|
|
'lor': 'builtin',
|
|
|
|
'lsl': 'builtin',
|
|
|
|
'lsr': 'builtin',
|
|
|
|
'lxor': 'builtin',
|
|
|
|
'mod': 'builtin',
|
|
|
|
'or': 'builtin',
|
|
|
|
|
|
|
|
// More Pervasives
|
|
|
|
'raise_notrace': 'builtin',
|
2016-07-23 05:29:20 +00:00
|
|
|
'trace': 'builtin',
|
|
|
|
'exit': 'builtin',
|
|
|
|
'print_string': 'builtin',
|
|
|
|
'print_endline': 'builtin',
|
2019-10-15 08:40:42 +00:00
|
|
|
|
|
|
|
'int': 'type',
|
|
|
|
'float': 'type',
|
|
|
|
'bool': 'type',
|
|
|
|
'char': 'type',
|
|
|
|
'string': 'type',
|
|
|
|
'unit': 'type',
|
|
|
|
|
|
|
|
// Modules
|
|
|
|
'List': 'builtin'
|
2016-07-23 05:29:20 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
CodeMirror.defineMIME('text/x-fsharp', {
|
|
|
|
name: 'mllike',
|
|
|
|
extraWords: {
|
|
|
|
'abstract': 'keyword',
|
|
|
|
'assert': 'keyword',
|
|
|
|
'base': 'keyword',
|
2019-10-15 08:40:42 +00:00
|
|
|
'begin': 'keyword',
|
2016-07-23 05:29:20 +00:00
|
|
|
'class': 'keyword',
|
|
|
|
'default': 'keyword',
|
|
|
|
'delegate': 'keyword',
|
2019-10-15 08:40:42 +00:00
|
|
|
'do!': 'keyword',
|
|
|
|
'done': 'keyword',
|
2016-07-23 05:29:20 +00:00
|
|
|
'downcast': 'keyword',
|
|
|
|
'downto': 'keyword',
|
|
|
|
'elif': 'keyword',
|
|
|
|
'extern': 'keyword',
|
|
|
|
'finally': 'keyword',
|
2019-10-15 08:40:42 +00:00
|
|
|
'for': 'keyword',
|
|
|
|
'function': 'keyword',
|
2016-07-23 05:29:20 +00:00
|
|
|
'global': 'keyword',
|
|
|
|
'inherit': 'keyword',
|
|
|
|
'inline': 'keyword',
|
|
|
|
'interface': 'keyword',
|
|
|
|
'internal': 'keyword',
|
|
|
|
'lazy': 'keyword',
|
|
|
|
'let!': 'keyword',
|
2019-10-15 08:40:42 +00:00
|
|
|
'match': 'keyword',
|
|
|
|
'member': 'keyword',
|
2016-07-23 05:29:20 +00:00
|
|
|
'module': 'keyword',
|
2019-10-15 08:40:42 +00:00
|
|
|
'mutable': 'keyword',
|
2016-07-23 05:29:20 +00:00
|
|
|
'namespace': 'keyword',
|
|
|
|
'new': 'keyword',
|
|
|
|
'null': 'keyword',
|
|
|
|
'override': 'keyword',
|
|
|
|
'private': 'keyword',
|
|
|
|
'public': 'keyword',
|
|
|
|
'return!': 'keyword',
|
2019-10-15 08:40:42 +00:00
|
|
|
'return': 'keyword',
|
2016-07-23 05:29:20 +00:00
|
|
|
'select': 'keyword',
|
|
|
|
'static': 'keyword',
|
2019-10-15 08:40:42 +00:00
|
|
|
'to': 'keyword',
|
|
|
|
'try': 'keyword',
|
2016-07-23 05:29:20 +00:00
|
|
|
'upcast': 'keyword',
|
|
|
|
'use!': 'keyword',
|
2019-10-15 08:40:42 +00:00
|
|
|
'use': 'keyword',
|
|
|
|
'void': 'keyword',
|
2016-07-23 05:29:20 +00:00
|
|
|
'when': 'keyword',
|
|
|
|
'yield!': 'keyword',
|
2019-10-15 08:40:42 +00:00
|
|
|
'yield': 'keyword',
|
|
|
|
|
|
|
|
// Reserved words
|
|
|
|
'atomic': 'keyword',
|
|
|
|
'break': 'keyword',
|
|
|
|
'checked': 'keyword',
|
|
|
|
'component': 'keyword',
|
|
|
|
'const': 'keyword',
|
|
|
|
'constraint': 'keyword',
|
|
|
|
'constructor': 'keyword',
|
|
|
|
'continue': 'keyword',
|
|
|
|
'eager': 'keyword',
|
|
|
|
'event': 'keyword',
|
|
|
|
'external': 'keyword',
|
|
|
|
'fixed': 'keyword',
|
|
|
|
'method': 'keyword',
|
|
|
|
'mixin': 'keyword',
|
|
|
|
'object': 'keyword',
|
|
|
|
'parallel': 'keyword',
|
|
|
|
'process': 'keyword',
|
|
|
|
'protected': 'keyword',
|
|
|
|
'pure': 'keyword',
|
|
|
|
'sealed': 'keyword',
|
|
|
|
'tailcall': 'keyword',
|
|
|
|
'trait': 'keyword',
|
|
|
|
'virtual': 'keyword',
|
|
|
|
'volatile': 'keyword',
|
2016-07-23 05:29:20 +00:00
|
|
|
|
2019-10-15 08:40:42 +00:00
|
|
|
// builtins
|
2016-07-23 05:29:20 +00:00
|
|
|
'List': 'builtin',
|
|
|
|
'Seq': 'builtin',
|
|
|
|
'Map': 'builtin',
|
|
|
|
'Set': 'builtin',
|
2019-10-15 08:40:42 +00:00
|
|
|
'Option': 'builtin',
|
2016-07-23 05:29:20 +00:00
|
|
|
'int': 'builtin',
|
|
|
|
'string': 'builtin',
|
|
|
|
'not': 'builtin',
|
|
|
|
'true': 'builtin',
|
2019-10-15 08:40:42 +00:00
|
|
|
'false': 'builtin',
|
|
|
|
|
|
|
|
'raise': 'builtin',
|
|
|
|
'failwith': 'builtin'
|
|
|
|
},
|
|
|
|
slashComments: true
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
CodeMirror.defineMIME('text/x-sml', {
|
|
|
|
name: 'mllike',
|
|
|
|
extraWords: {
|
|
|
|
'abstype': 'keyword',
|
|
|
|
'and': 'keyword',
|
|
|
|
'andalso': 'keyword',
|
|
|
|
'case': 'keyword',
|
|
|
|
'datatype': 'keyword',
|
|
|
|
'fn': 'keyword',
|
|
|
|
'handle': 'keyword',
|
|
|
|
'infix': 'keyword',
|
|
|
|
'infixr': 'keyword',
|
|
|
|
'local': 'keyword',
|
|
|
|
'nonfix': 'keyword',
|
|
|
|
'op': 'keyword',
|
|
|
|
'orelse': 'keyword',
|
|
|
|
'raise': 'keyword',
|
|
|
|
'withtype': 'keyword',
|
|
|
|
'eqtype': 'keyword',
|
|
|
|
'sharing': 'keyword',
|
|
|
|
'sig': 'keyword',
|
|
|
|
'signature': 'keyword',
|
|
|
|
'structure': 'keyword',
|
|
|
|
'where': 'keyword',
|
|
|
|
'true': 'keyword',
|
|
|
|
'false': 'keyword',
|
|
|
|
|
|
|
|
// types
|
|
|
|
'int': 'builtin',
|
|
|
|
'real': 'builtin',
|
|
|
|
'string': 'builtin',
|
|
|
|
'char': 'builtin',
|
|
|
|
'bool': 'builtin'
|
2016-07-23 05:29:20 +00:00
|
|
|
},
|
|
|
|
slashComments: true
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|