LaravelTest
148 строк · 5.2 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4/*
5This MUMPS Language script was constructed using vbscript.js as a template.
6*/
7
8(function(mod) {9if (typeof exports == "object" && typeof module == "object") // CommonJS10mod(require("../../lib/codemirror"));11else if (typeof define == "function" && define.amd) // AMD12define(["../../lib/codemirror"], mod);13else // Plain browser env14mod(CodeMirror);15})(function(CodeMirror) {16"use strict";17
18CodeMirror.defineMode("mumps", function() {19function wordRegexp(words) {20return new RegExp("^((" + words.join(")|(") + "))\\b", "i");21}22
23var singleOperators = new RegExp("^[\\+\\-\\*/&#!_?\\\\<>=\\'\\[\\]]");24var doubleOperators = new RegExp("^(('=)|(<=)|(>=)|('>)|('<)|([[)|(]])|(^$))");25var singleDelimiters = new RegExp("^[\\.,:]");26var brackets = new RegExp("[()]");27var identifiers = new RegExp("^[%A-Za-z][A-Za-z0-9]*");28var commandKeywords = ["break","close","do","else","for","goto", "halt", "hang", "if", "job","kill","lock","merge","new","open", "quit", "read", "set", "tcommit", "trollback", "tstart", "use", "view", "write", "xecute", "b","c","d","e","f","g", "h", "i", "j","k","l","m","n","o", "q", "r", "s", "tc", "tro", "ts", "u", "v", "w", "x"];29// The following list includes intrinsic functions _and_ special variables30var intrinsicFuncsWords = ["\\$ascii", "\\$char", "\\$data", "\\$ecode", "\\$estack", "\\$etrap", "\\$extract", "\\$find", "\\$fnumber", "\\$get", "\\$horolog", "\\$io", "\\$increment", "\\$job", "\\$justify", "\\$length", "\\$name", "\\$next", "\\$order", "\\$piece", "\\$qlength", "\\$qsubscript", "\\$query", "\\$quit", "\\$random", "\\$reverse", "\\$select", "\\$stack", "\\$test", "\\$text", "\\$translate", "\\$view", "\\$x", "\\$y", "\\$a", "\\$c", "\\$d", "\\$e", "\\$ec", "\\$es", "\\$et", "\\$f", "\\$fn", "\\$g", "\\$h", "\\$i", "\\$j", "\\$l", "\\$n", "\\$na", "\\$o", "\\$p", "\\$q", "\\$ql", "\\$qs", "\\$r", "\\$re", "\\$s", "\\$st", "\\$t", "\\$tr", "\\$v", "\\$z"];31var intrinsicFuncs = wordRegexp(intrinsicFuncsWords);32var command = wordRegexp(commandKeywords);33
34function tokenBase(stream, state) {35if (stream.sol()) {36state.label = true;37state.commandMode = 0;38}39
40// The <space> character has meaning in MUMPS. Ignoring consecutive41// spaces would interfere with interpreting whether the next non-space42// character belongs to the command or argument context.43
44// Examine each character and update a mode variable whose interpretation is:45// >0 => command 0 => argument <0 => command post-conditional46var ch = stream.peek();47
48if (ch == " " || ch == "\t") { // Pre-process <space>49state.label = false;50if (state.commandMode == 0)51state.commandMode = 1;52else if ((state.commandMode < 0) || (state.commandMode == 2))53state.commandMode = 0;54} else if ((ch != ".") && (state.commandMode > 0)) {55if (ch == ":")56state.commandMode = -1; // SIS - Command post-conditional57else58state.commandMode = 2;59}60
61// Do not color parameter list as line tag62if ((ch === "(") || (ch === "\u0009"))63state.label = false;64
65// MUMPS comment starts with ";"66if (ch === ";") {67stream.skipToEnd();68return "comment";69}70
71// Number Literals // SIS/RLM - MUMPS permits canonic number followed by concatenate operator72if (stream.match(/^[-+]?\d+(\.\d+)?([eE][-+]?\d+)?/))73return "number";74
75// Handle Strings76if (ch == '"') {77if (stream.skipTo('"')) {78stream.next();79return "string";80} else {81stream.skipToEnd();82return "error";83}84}85
86// Handle operators and Delimiters87if (stream.match(doubleOperators) || stream.match(singleOperators))88return "operator";89
90// Prevents leading "." in DO block from falling through to error91if (stream.match(singleDelimiters))92return null;93
94if (brackets.test(ch)) {95stream.next();96return "bracket";97}98
99if (state.commandMode > 0 && stream.match(command))100return "variable-2";101
102if (stream.match(intrinsicFuncs))103return "builtin";104
105if (stream.match(identifiers))106return "variable";107
108// Detect dollar-sign when not a documented intrinsic function109// "^" may introduce a GVN or SSVN - Color same as function110if (ch === "$" || ch === "^") {111stream.next();112return "builtin";113}114
115// MUMPS Indirection116if (ch === "@") {117stream.next();118return "string-2";119}120
121if (/[\w%]/.test(ch)) {122stream.eatWhile(/[\w%]/);123return "variable";124}125
126// Handle non-detected items127stream.next();128return "error";129}130
131return {132startState: function() {133return {134label: false,135commandMode: 0136};137},138
139token: function(stream, state) {140var style = tokenBase(stream, state);141if (state.label) return "tag";142return style;143}144};145});146
147CodeMirror.defineMIME("text/x-mumps", "mumps");148});149