LaravelTest
195 строк · 5.9 Кб
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("ebnf", function (config) {15var commentType = {slash: 0, parenthesis: 1};16var stateType = {comment: 0, _string: 1, characterClass: 2};17var bracesMode = null;18
19if (config.bracesMode)20bracesMode = CodeMirror.getMode(config, config.bracesMode);21
22return {23startState: function () {24return {25stringType: null,26commentType: null,27braced: 0,28lhs: true,29localState: null,30stack: [],31inDefinition: false32};33},34token: function (stream, state) {35if (!stream) return;36
37//check for state changes38if (state.stack.length === 0) {39//strings40if ((stream.peek() == '"') || (stream.peek() == "'")) {41state.stringType = stream.peek();42stream.next(); // Skip quote43state.stack.unshift(stateType._string);44} else if (stream.match('/*')) { //comments starting with /*45state.stack.unshift(stateType.comment);46state.commentType = commentType.slash;47} else if (stream.match('(*')) { //comments starting with (*48state.stack.unshift(stateType.comment);49state.commentType = commentType.parenthesis;50}51}52
53//return state54//stack has55switch (state.stack[0]) {56case stateType._string:57while (state.stack[0] === stateType._string && !stream.eol()) {58if (stream.peek() === state.stringType) {59stream.next(); // Skip quote60state.stack.shift(); // Clear flag61} else if (stream.peek() === "\\") {62stream.next();63stream.next();64} else {65stream.match(/^.[^\\\"\']*/);66}67}68return state.lhs ? "property string" : "string"; // Token style69
70case stateType.comment:71while (state.stack[0] === stateType.comment && !stream.eol()) {72if (state.commentType === commentType.slash && stream.match('*/')) {73state.stack.shift(); // Clear flag74state.commentType = null;75} else if (state.commentType === commentType.parenthesis && stream.match('*)')) {76state.stack.shift(); // Clear flag77state.commentType = null;78} else {79stream.match(/^.[^\*]*/);80}81}82return "comment";83
84case stateType.characterClass:85while (state.stack[0] === stateType.characterClass && !stream.eol()) {86if (!(stream.match(/^[^\]\\]+/) || stream.match('.'))) {87state.stack.shift();88}89}90return "operator";91}92
93var peek = stream.peek();94
95if (bracesMode !== null && (state.braced || peek === "{")) {96if (state.localState === null)97state.localState = CodeMirror.startState(bracesMode);98
99var token = bracesMode.token(stream, state.localState),100text = stream.current();101
102if (!token) {103for (var i = 0; i < text.length; i++) {104if (text[i] === "{") {105if (state.braced === 0) {106token = "matchingbracket";107}108state.braced++;109} else if (text[i] === "}") {110state.braced--;111if (state.braced === 0) {112token = "matchingbracket";113}114}115}116}117return token;118}119
120//no stack121switch (peek) {122case "[":123stream.next();124state.stack.unshift(stateType.characterClass);125return "bracket";126case ":":127case "|":128case ";":129stream.next();130return "operator";131case "%":132if (stream.match("%%")) {133return "header";134} else if (stream.match(/[%][A-Za-z]+/)) {135return "keyword";136} else if (stream.match(/[%][}]/)) {137return "matchingbracket";138}139break;140case "/":141if (stream.match(/[\/][A-Za-z]+/)) {142return "keyword";143}144case "\\":145if (stream.match(/[\][a-z]+/)) {146return "string-2";147}148case ".":149if (stream.match(".")) {150return "atom";151}152case "*":153case "-":154case "+":155case "^":156if (stream.match(peek)) {157return "atom";158}159case "$":160if (stream.match("$$")) {161return "builtin";162} else if (stream.match(/[$][0-9]+/)) {163return "variable-3";164}165case "<":166if (stream.match(/<<[a-zA-Z_]+>>/)) {167return "builtin";168}169}170
171if (stream.match('//')) {172stream.skipToEnd();173return "comment";174} else if (stream.match('return')) {175return "operator";176} else if (stream.match(/^[a-zA-Z_][a-zA-Z0-9_]*/)) {177if (stream.match(/(?=[\(.])/)) {178return "variable";179} else if (stream.match(/(?=[\s\n]*[:=])/)) {180return "def";181}182return "variable-2";183} else if (["[", "]", "(", ")"].indexOf(stream.peek()) != -1) {184stream.next();185return "bracket";186} else if (!stream.eatSpace()) {187stream.next();188}189return null;190}191};192});193
194CodeMirror.defineMIME("text/x-ebnf", "ebnf");195});196