GPQAPP
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode('mllike', function(_config, parserConfig) {15var words = {16'as': 'keyword',17'do': 'keyword',18'else': 'keyword',19'end': 'keyword',20'exception': 'keyword',21'fun': 'keyword',22'functor': 'keyword',23'if': 'keyword',24'in': 'keyword',25'include': 'keyword',26'let': 'keyword',27'of': 'keyword',28'open': 'keyword',29'rec': 'keyword',30'struct': 'keyword',31'then': 'keyword',32'type': 'keyword',33'val': 'keyword',34'while': 'keyword',35'with': 'keyword'36};37
38var extraWords = parserConfig.extraWords || {};39for (var prop in extraWords) {40if (extraWords.hasOwnProperty(prop)) {41words[prop] = parserConfig.extraWords[prop];42}43}44var hintWords = [];45for (var k in words) { hintWords.push(k); }46CodeMirror.registerHelper("hintWords", "mllike", hintWords);47
48function tokenBase(stream, state) {49var ch = stream.next();50
51if (ch === '"') {52state.tokenize = tokenString;53return state.tokenize(stream, state);54}55if (ch === '{') {56if (stream.eat('|')) {57state.longString = true;58state.tokenize = tokenLongString;59return state.tokenize(stream, state);60}61}62if (ch === '(') {63if (stream.match(/^\*(?!\))/)) {64state.commentLevel++;65state.tokenize = tokenComment;66return state.tokenize(stream, state);67}68}69if (ch === '~' || ch === '?') {70stream.eatWhile(/\w/);71return 'variable-2';72}73if (ch === '`') {74stream.eatWhile(/\w/);75return 'quote';76}77if (ch === '/' && parserConfig.slashComments && stream.eat('/')) {78stream.skipToEnd();79return 'comment';80}81if (/\d/.test(ch)) {82if (ch === '0' && stream.eat(/[bB]/)) {83stream.eatWhile(/[01]/);84} if (ch === '0' && stream.eat(/[xX]/)) {85stream.eatWhile(/[0-9a-fA-F]/)86} if (ch === '0' && stream.eat(/[oO]/)) {87stream.eatWhile(/[0-7]/);88} else {89stream.eatWhile(/[\d_]/);90if (stream.eat('.')) {91stream.eatWhile(/[\d]/);92}93if (stream.eat(/[eE]/)) {94stream.eatWhile(/[\d\-+]/);95}96}97return 'number';98}99if ( /[+\-*&%=<>!?|@\.~:]/.test(ch)) {100return 'operator';101}102if (/[\w\xa1-\uffff]/.test(ch)) {103stream.eatWhile(/[\w\xa1-\uffff]/);104var cur = stream.current();105return words.hasOwnProperty(cur) ? words[cur] : 'variable';106}107return null108}109
110function tokenString(stream, state) {111var next, end = false, escaped = false;112while ((next = stream.next()) != null) {113if (next === '"' && !escaped) {114end = true;115break;116}117escaped = !escaped && next === '\\';118}119if (end && !escaped) {120state.tokenize = tokenBase;121}122return 'string';123};124
125function tokenComment(stream, state) {126var prev, next;127while(state.commentLevel > 0 && (next = stream.next()) != null) {128if (prev === '(' && next === '*') state.commentLevel++;129if (prev === '*' && next === ')') state.commentLevel--;130prev = next;131}132if (state.commentLevel <= 0) {133state.tokenize = tokenBase;134}135return 'comment';136}137
138function tokenLongString(stream, state) {139var prev, next;140while (state.longString && (next = stream.next()) != null) {141if (prev === '|' && next === '}') state.longString = false;142prev = next;143}144if (!state.longString) {145state.tokenize = tokenBase;146}147return 'string';148}149
150return {151startState: function() {return {tokenize: tokenBase, commentLevel: 0, longString: false};},152token: function(stream, state) {153if (stream.eatSpace()) return null;154return state.tokenize(stream, state);155},156
157blockCommentStart: "(*",158blockCommentEnd: "*)",159lineComment: parserConfig.slashComments ? "//" : null160};161});162
163CodeMirror.defineMIME('text/x-ocaml', {164name: 'mllike',165extraWords: {166'and': 'keyword',167'assert': 'keyword',168'begin': 'keyword',169'class': 'keyword',170'constraint': 'keyword',171'done': 'keyword',172'downto': 'keyword',173'external': 'keyword',174'function': 'keyword',175'initializer': 'keyword',176'lazy': 'keyword',177'match': 'keyword',178'method': 'keyword',179'module': 'keyword',180'mutable': 'keyword',181'new': 'keyword',182'nonrec': 'keyword',183'object': 'keyword',184'private': 'keyword',185'sig': 'keyword',186'to': 'keyword',187'try': 'keyword',188'value': 'keyword',189'virtual': 'keyword',190'when': 'keyword',191
192// builtins193'raise': 'builtin',194'failwith': 'builtin',195'true': 'builtin',196'false': 'builtin',197
198// Pervasives builtins199'asr': 'builtin',200'land': 'builtin',201'lor': 'builtin',202'lsl': 'builtin',203'lsr': 'builtin',204'lxor': 'builtin',205'mod': 'builtin',206'or': 'builtin',207
208// More Pervasives209'raise_notrace': 'builtin',210'trace': 'builtin',211'exit': 'builtin',212'print_string': 'builtin',213'print_endline': 'builtin',214
215'int': 'type',216'float': 'type',217'bool': 'type',218'char': 'type',219'string': 'type',220'unit': 'type',221
222// Modules223'List': 'builtin'224}225});226
227CodeMirror.defineMIME('text/x-fsharp', {228name: 'mllike',229extraWords: {230'abstract': 'keyword',231'assert': 'keyword',232'base': 'keyword',233'begin': 'keyword',234'class': 'keyword',235'default': 'keyword',236'delegate': 'keyword',237'do!': 'keyword',238'done': 'keyword',239'downcast': 'keyword',240'downto': 'keyword',241'elif': 'keyword',242'extern': 'keyword',243'finally': 'keyword',244'for': 'keyword',245'function': 'keyword',246'global': 'keyword',247'inherit': 'keyword',248'inline': 'keyword',249'interface': 'keyword',250'internal': 'keyword',251'lazy': 'keyword',252'let!': 'keyword',253'match': 'keyword',254'member': 'keyword',255'module': 'keyword',256'mutable': 'keyword',257'namespace': 'keyword',258'new': 'keyword',259'null': 'keyword',260'override': 'keyword',261'private': 'keyword',262'public': 'keyword',263'return!': 'keyword',264'return': 'keyword',265'select': 'keyword',266'static': 'keyword',267'to': 'keyword',268'try': 'keyword',269'upcast': 'keyword',270'use!': 'keyword',271'use': 'keyword',272'void': 'keyword',273'when': 'keyword',274'yield!': 'keyword',275'yield': 'keyword',276
277// Reserved words278'atomic': 'keyword',279'break': 'keyword',280'checked': 'keyword',281'component': 'keyword',282'const': 'keyword',283'constraint': 'keyword',284'constructor': 'keyword',285'continue': 'keyword',286'eager': 'keyword',287'event': 'keyword',288'external': 'keyword',289'fixed': 'keyword',290'method': 'keyword',291'mixin': 'keyword',292'object': 'keyword',293'parallel': 'keyword',294'process': 'keyword',295'protected': 'keyword',296'pure': 'keyword',297'sealed': 'keyword',298'tailcall': 'keyword',299'trait': 'keyword',300'virtual': 'keyword',301'volatile': 'keyword',302
303// builtins304'List': 'builtin',305'Seq': 'builtin',306'Map': 'builtin',307'Set': 'builtin',308'Option': 'builtin',309'int': 'builtin',310'string': 'builtin',311'not': 'builtin',312'true': 'builtin',313'false': 'builtin',314
315'raise': 'builtin',316'failwith': 'builtin'317},318slashComments: true319});320
321
322CodeMirror.defineMIME('text/x-sml', {323name: 'mllike',324extraWords: {325'abstype': 'keyword',326'and': 'keyword',327'andalso': 'keyword',328'case': 'keyword',329'datatype': 'keyword',330'fn': 'keyword',331'handle': 'keyword',332'infix': 'keyword',333'infixr': 'keyword',334'local': 'keyword',335'nonfix': 'keyword',336'op': 'keyword',337'orelse': 'keyword',338'raise': 'keyword',339'withtype': 'keyword',340'eqtype': 'keyword',341'sharing': 'keyword',342'sig': 'keyword',343'signature': 'keyword',344'structure': 'keyword',345'where': 'keyword',346'true': 'keyword',347'false': 'keyword',348
349// types350'int': 'builtin',351'real': 'builtin',352'string': 'builtin',353'char': 'builtin',354'bool': 'builtin'355},356slashComments: true357});358
359});360