LaravelTest
114 строк · 3.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"), require("../javascript/javascript"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror", "../javascript/javascript"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("pegjs", function (config) {15var jsMode = CodeMirror.getMode(config, "javascript");16
17function identifier(stream) {18return stream.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);19}20
21return {22startState: function () {23return {24inString: false,25stringType: null,26inComment: false,27inCharacterClass: false,28braced: 0,29lhs: true,30localState: null31};32},33token: function (stream, state) {34if (stream)35
36//check for state changes37if (!state.inString && !state.inComment && ((stream.peek() == '"') || (stream.peek() == "'"))) {38state.stringType = stream.peek();39stream.next(); // Skip quote40state.inString = true; // Update state41}42if (!state.inString && !state.inComment && stream.match('/*')) {43state.inComment = true;44}45
46//return state47if (state.inString) {48while (state.inString && !stream.eol()) {49if (stream.peek() === state.stringType) {50stream.next(); // Skip quote51state.inString = false; // Clear flag52} else if (stream.peek() === '\\') {53stream.next();54stream.next();55} else {56stream.match(/^.[^\\\"\']*/);57}58}59return state.lhs ? "property string" : "string"; // Token style60} else if (state.inComment) {61while (state.inComment && !stream.eol()) {62if (stream.match('*/')) {63state.inComment = false; // Clear flag64} else {65stream.match(/^.[^\*]*/);66}67}68return "comment";69} else if (state.inCharacterClass) {70while (state.inCharacterClass && !stream.eol()) {71if (!(stream.match(/^[^\]\\]+/) || stream.match(/^\\./))) {72state.inCharacterClass = false;73}74}75} else if (stream.peek() === '[') {76stream.next();77state.inCharacterClass = true;78return 'bracket';79} else if (stream.match('//')) {80stream.skipToEnd();81return "comment";82} else if (state.braced || stream.peek() === '{') {83if (state.localState === null) {84state.localState = CodeMirror.startState(jsMode);85}86var token = jsMode.token(stream, state.localState);87var text = stream.current();88if (!token) {89for (var i = 0; i < text.length; i++) {90if (text[i] === '{') {91state.braced++;92} else if (text[i] === '}') {93state.braced--;94}95};96}97return token;98} else if (identifier(stream)) {99if (stream.peek() === ':') {100return 'variable';101}102return 'variable-2';103} else if (['[', ']', '(', ')'].indexOf(stream.peek()) != -1) {104stream.next();105return 'bracket';106} else if (!stream.eatSpace()) {107stream.next();108}109return null;110}111};112}, "javascript");113
114});115