LaravelTest
252 строки · 6.5 Кб
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("oz", function (conf) {15
16function wordRegexp(words) {17return new RegExp("^((" + words.join(")|(") + "))\\b");18}19
20var singleOperators = /[\^@!\|<>#~\.\*\-\+\\/,=]/;21var doubleOperators = /(<-)|(:=)|(=<)|(>=)|(<=)|(<:)|(>:)|(=:)|(\\=)|(\\=:)|(!!)|(==)|(::)/;22var tripleOperators = /(:::)|(\.\.\.)|(=<:)|(>=:)/;23
24var middle = ["in", "then", "else", "of", "elseof", "elsecase", "elseif", "catch",25"finally", "with", "require", "prepare", "import", "export", "define", "do"];26var end = ["end"];27
28var atoms = wordRegexp(["true", "false", "nil", "unit"]);29var commonKeywords = wordRegexp(["andthen", "at", "attr", "declare", "feat", "from", "lex",30"mod", "div", "mode", "orelse", "parser", "prod", "prop", "scanner", "self", "syn", "token"]);31var openingKeywords = wordRegexp(["local", "proc", "fun", "case", "class", "if", "cond", "or", "dis",32"choice", "not", "thread", "try", "raise", "lock", "for", "suchthat", "meth", "functor"]);33var middleKeywords = wordRegexp(middle);34var endKeywords = wordRegexp(end);35
36// Tokenizers37function tokenBase(stream, state) {38if (stream.eatSpace()) {39return null;40}41
42// Brackets43if(stream.match(/[{}]/)) {44return "bracket";45}46
47// Special [] keyword48if (stream.match('[]')) {49return "keyword"50}51
52// Operators53if (stream.match(tripleOperators) || stream.match(doubleOperators)) {54return "operator";55}56
57// Atoms58if(stream.match(atoms)) {59return 'atom';60}61
62// Opening keywords63var matched = stream.match(openingKeywords);64if (matched) {65if (!state.doInCurrentLine)66state.currentIndent++;67else68state.doInCurrentLine = false;69
70// Special matching for signatures71if(matched[0] == "proc" || matched[0] == "fun")72state.tokenize = tokenFunProc;73else if(matched[0] == "class")74state.tokenize = tokenClass;75else if(matched[0] == "meth")76state.tokenize = tokenMeth;77
78return 'keyword';79}80
81// Middle and other keywords82if (stream.match(middleKeywords) || stream.match(commonKeywords)) {83return "keyword"84}85
86// End keywords87if (stream.match(endKeywords)) {88state.currentIndent--;89return 'keyword';90}91
92// Eat the next char for next comparisons93var ch = stream.next();94
95// Strings96if (ch == '"' || ch == "'") {97state.tokenize = tokenString(ch);98return state.tokenize(stream, state);99}100
101// Numbers102if (/[~\d]/.test(ch)) {103if (ch == "~") {104if(! /^[0-9]/.test(stream.peek()))105return null;106else if (( stream.next() == "0" && stream.match(/^[xX][0-9a-fA-F]+/)) || stream.match(/^[0-9]*(\.[0-9]+)?([eE][~+]?[0-9]+)?/))107return "number";108}109
110if ((ch == "0" && stream.match(/^[xX][0-9a-fA-F]+/)) || stream.match(/^[0-9]*(\.[0-9]+)?([eE][~+]?[0-9]+)?/))111return "number";112
113return null;114}115
116// Comments117if (ch == "%") {118stream.skipToEnd();119return 'comment';120}121else if (ch == "/") {122if (stream.eat("*")) {123state.tokenize = tokenComment;124return tokenComment(stream, state);125}126}127
128// Single operators129if(singleOperators.test(ch)) {130return "operator";131}132
133// If nothing match, we skip the entire alphanumeric block134stream.eatWhile(/\w/);135
136return "variable";137}138
139function tokenClass(stream, state) {140if (stream.eatSpace()) {141return null;142}143stream.match(/([A-Z][A-Za-z0-9_]*)|(`.+`)/);144state.tokenize = tokenBase;145return "variable-3"146}147
148function tokenMeth(stream, state) {149if (stream.eatSpace()) {150return null;151}152stream.match(/([a-zA-Z][A-Za-z0-9_]*)|(`.+`)/);153state.tokenize = tokenBase;154return "def"155}156
157function tokenFunProc(stream, state) {158if (stream.eatSpace()) {159return null;160}161
162if(!state.hasPassedFirstStage && stream.eat("{")) {163state.hasPassedFirstStage = true;164return "bracket";165}166else if(state.hasPassedFirstStage) {167stream.match(/([A-Z][A-Za-z0-9_]*)|(`.+`)|\$/);168state.hasPassedFirstStage = false;169state.tokenize = tokenBase;170return "def"171}172else {173state.tokenize = tokenBase;174return null;175}176}177
178function tokenComment(stream, state) {179var maybeEnd = false, ch;180while (ch = stream.next()) {181if (ch == "/" && maybeEnd) {182state.tokenize = tokenBase;183break;184}185maybeEnd = (ch == "*");186}187return "comment";188}189
190function tokenString(quote) {191return function (stream, state) {192var escaped = false, next, end = false;193while ((next = stream.next()) != null) {194if (next == quote && !escaped) {195end = true;196break;197}198escaped = !escaped && next == "\\";199}200if (end || !escaped)201state.tokenize = tokenBase;202return "string";203};204}205
206function buildElectricInputRegEx() {207// Reindentation should occur on [] or on a match of any of208// the block closing keywords, at the end of a line.209var allClosings = middle.concat(end);210return new RegExp("[\\[\\]]|(" + allClosings.join("|") + ")$");211}212
213return {214
215startState: function () {216return {217tokenize: tokenBase,218currentIndent: 0,219doInCurrentLine: false,220hasPassedFirstStage: false221};222},223
224token: function (stream, state) {225if (stream.sol())226state.doInCurrentLine = 0;227
228return state.tokenize(stream, state);229},230
231indent: function (state, textAfter) {232var trueText = textAfter.replace(/^\s+|\s+$/g, '');233
234if (trueText.match(endKeywords) || trueText.match(middleKeywords) || trueText.match(/(\[])/))235return conf.indentUnit * (state.currentIndent - 1);236
237if (state.currentIndent < 0)238return 0;239
240return state.currentIndent * conf.indentUnit;241},242fold: "indent",243electricInput: buildElectricInputRegEx(),244lineComment: "%",245blockCommentStart: "/*",246blockCommentEnd: "*/"247};248});249
250CodeMirror.defineMIME("text/x-oz", "oz");251
252});253