LaravelTest
166 строк · 5.4 Кб
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"), require("../clike/clike"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror", "../clike/clike"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14var keywords = ("this super static final const abstract class extends external factory " +15"implements mixin get native set typedef with enum throw rethrow " +16"assert break case continue default in return new deferred async await covariant " +17"try catch finally do else for if switch while import library export " +18"part of show hide is as extension on yield late required").split(" ");19var blockKeywords = "try catch finally do else for if switch while".split(" ");20var atoms = "true false null".split(" ");21var builtins = "void bool num int double dynamic var String Null Never".split(" ");22
23function set(words) {24var obj = {};25for (var i = 0; i < words.length; ++i) obj[words[i]] = true;26return obj;27}28
29function pushInterpolationStack(state) {30(state.interpolationStack || (state.interpolationStack = [])).push(state.tokenize);31}32
33function popInterpolationStack(state) {34return (state.interpolationStack || (state.interpolationStack = [])).pop();35}36
37function sizeInterpolationStack(state) {38return state.interpolationStack ? state.interpolationStack.length : 0;39}40
41CodeMirror.defineMIME("application/dart", {42name: "clike",43keywords: set(keywords),44blockKeywords: set(blockKeywords),45builtin: set(builtins),46atoms: set(atoms),47hooks: {48"@": function(stream) {49stream.eatWhile(/[\w\$_\.]/);50return "meta";51},52
53// custom string handling to deal with triple-quoted strings and string interpolation54"'": function(stream, state) {55return tokenString("'", stream, state, false);56},57"\"": function(stream, state) {58return tokenString("\"", stream, state, false);59},60"r": function(stream, state) {61var peek = stream.peek();62if (peek == "'" || peek == "\"") {63return tokenString(stream.next(), stream, state, true);64}65return false;66},67
68"}": function(_stream, state) {69// "}" is end of interpolation, if interpolation stack is non-empty70if (sizeInterpolationStack(state) > 0) {71state.tokenize = popInterpolationStack(state);72return null;73}74return false;75},76
77"/": function(stream, state) {78if (!stream.eat("*")) return false79state.tokenize = tokenNestedComment(1)80return state.tokenize(stream, state)81},82token: function(stream, _, style) {83if (style == "variable") {84// Assume uppercase symbols are classes using variable-285var isUpper = RegExp('^[_$]*[A-Z][a-zA-Z0-9_$]*$','g');86if (isUpper.test(stream.current())) {87return 'variable-2';88}89}90}91}92});93
94function tokenString(quote, stream, state, raw) {95var tripleQuoted = false;96if (stream.eat(quote)) {97if (stream.eat(quote)) tripleQuoted = true;98else return "string"; //empty string99}100function tokenStringHelper(stream, state) {101var escaped = false;102while (!stream.eol()) {103if (!raw && !escaped && stream.peek() == "$") {104pushInterpolationStack(state);105state.tokenize = tokenInterpolation;106return "string";107}108var next = stream.next();109if (next == quote && !escaped && (!tripleQuoted || stream.match(quote + quote))) {110state.tokenize = null;111break;112}113escaped = !raw && !escaped && next == "\\";114}115return "string";116}117state.tokenize = tokenStringHelper;118return tokenStringHelper(stream, state);119}120
121function tokenInterpolation(stream, state) {122stream.eat("$");123if (stream.eat("{")) {124// let clike handle the content of ${...},125// we take over again when "}" appears (see hooks).126state.tokenize = null;127} else {128state.tokenize = tokenInterpolationIdentifier;129}130return null;131}132
133function tokenInterpolationIdentifier(stream, state) {134stream.eatWhile(/[\w_]/);135state.tokenize = popInterpolationStack(state);136return "variable";137}138
139function tokenNestedComment(depth) {140return function (stream, state) {141var ch142while (ch = stream.next()) {143if (ch == "*" && stream.eat("/")) {144if (depth == 1) {145state.tokenize = null146break147} else {148state.tokenize = tokenNestedComment(depth - 1)149return state.tokenize(stream, state)150}151} else if (ch == "/" && stream.eat("*")) {152state.tokenize = tokenNestedComment(depth + 1)153return state.tokenize(stream, state)154}155}156return "comment"157}158}159
160CodeMirror.registerHelper("hintWords", "application/dart", keywords.concat(atoms).concat(builtins));161
162// This is needed to make loading through meta.js work.163CodeMirror.defineMode("dart", function(conf) {164return CodeMirror.getMode(conf, "application/dart");165}, "clike");166});167