LaravelTest
189 строк · 6.5 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4// Originally written by Alf Nielsen, re-written by Michael Zhou
5(function(mod) {6if (typeof exports == "object" && typeof module == "object") // CommonJS7mod(require("../../lib/codemirror"));8else if (typeof define == "function" && define.amd) // AMD9define(["../../lib/codemirror"], mod);10else // Plain browser env11mod(CodeMirror);12})(function(CodeMirror) {13"use strict";14
15function words(str) {16var obj = {}, words = str.split(",");17for (var i = 0; i < words.length; ++i) {18var allCaps = words[i].toUpperCase();19var firstCap = words[i].charAt(0).toUpperCase() + words[i].slice(1);20obj[words[i]] = true;21obj[allCaps] = true;22obj[firstCap] = true;23}24return obj;25}
26
27function metaHook(stream) {28stream.eatWhile(/[\w\$_]/);29return "meta";30}
31
32CodeMirror.defineMode("vhdl", function(config, parserConfig) {33var indentUnit = config.indentUnit,34atoms = parserConfig.atoms || words("null"),35hooks = parserConfig.hooks || {"`": metaHook, "$": metaHook},36multiLineStrings = parserConfig.multiLineStrings;37
38var keywords = words("abs,access,after,alias,all,and,architecture,array,assert,attribute,begin,block," +39"body,buffer,bus,case,component,configuration,constant,disconnect,downto,else,elsif,end,end block,end case," +40"end component,end for,end generate,end if,end loop,end process,end record,end units,entity,exit,file,for," +41"function,generate,generic,generic map,group,guarded,if,impure,in,inertial,inout,is,label,library,linkage," +42"literal,loop,map,mod,nand,new,next,nor,null,of,on,open,or,others,out,package,package body,port,port map," +43"postponed,procedure,process,pure,range,record,register,reject,rem,report,return,rol,ror,select,severity,signal," +44"sla,sll,sra,srl,subtype,then,to,transport,type,unaffected,units,until,use,variable,wait,when,while,with,xnor,xor");45
46var blockKeywords = words("architecture,entity,begin,case,port,else,elsif,end,for,function,if");47
48var isOperatorChar = /[&|~><!\)\(*#%@+\/=?\:;}{,\.\^\-\[\]]/;49var curPunc;50
51function tokenBase(stream, state) {52var ch = stream.next();53if (hooks[ch]) {54var result = hooks[ch](stream, state);55if (result !== false) return result;56}57if (ch == '"') {58state.tokenize = tokenString2(ch);59return state.tokenize(stream, state);60}61if (ch == "'") {62state.tokenize = tokenString(ch);63return state.tokenize(stream, state);64}65if (/[\[\]{}\(\),;\:\.]/.test(ch)) {66curPunc = ch;67return null;68}69if (/[\d']/.test(ch)) {70stream.eatWhile(/[\w\.']/);71return "number";72}73if (ch == "-") {74if (stream.eat("-")) {75stream.skipToEnd();76return "comment";77}78}79if (isOperatorChar.test(ch)) {80stream.eatWhile(isOperatorChar);81return "operator";82}83stream.eatWhile(/[\w\$_]/);84var cur = stream.current();85if (keywords.propertyIsEnumerable(cur.toLowerCase())) {86if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";87return "keyword";88}89if (atoms.propertyIsEnumerable(cur)) return "atom";90return "variable";91}92
93function tokenString(quote) {94return function(stream, state) {95var escaped = false, next, end = false;96while ((next = stream.next()) != null) {97if (next == quote && !escaped) {end = true; break;}98escaped = !escaped && next == "--";99}100if (end || !(escaped || multiLineStrings))101state.tokenize = tokenBase;102return "string";103};104}105function tokenString2(quote) {106return function(stream, state) {107var escaped = false, next, end = false;108while ((next = stream.next()) != null) {109if (next == quote && !escaped) {end = true; break;}110escaped = !escaped && next == "--";111}112if (end || !(escaped || multiLineStrings))113state.tokenize = tokenBase;114return "string-2";115};116}117
118function Context(indented, column, type, align, prev) {119this.indented = indented;120this.column = column;121this.type = type;122this.align = align;123this.prev = prev;124}125function pushContext(state, col, type) {126return state.context = new Context(state.indented, col, type, null, state.context);127}128function popContext(state) {129var t = state.context.type;130if (t == ")" || t == "]" || t == "}")131state.indented = state.context.indented;132return state.context = state.context.prev;133}134
135// Interface136return {137startState: function(basecolumn) {138return {139tokenize: null,140context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),141indented: 0,142startOfLine: true143};144},145
146token: function(stream, state) {147var ctx = state.context;148if (stream.sol()) {149if (ctx.align == null) ctx.align = false;150state.indented = stream.indentation();151state.startOfLine = true;152}153if (stream.eatSpace()) return null;154curPunc = null;155var style = (state.tokenize || tokenBase)(stream, state);156if (style == "comment" || style == "meta") return style;157if (ctx.align == null) ctx.align = true;158
159if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);160else if (curPunc == "{") pushContext(state, stream.column(), "}");161else if (curPunc == "[") pushContext(state, stream.column(), "]");162else if (curPunc == "(") pushContext(state, stream.column(), ")");163else if (curPunc == "}") {164while (ctx.type == "statement") ctx = popContext(state);165if (ctx.type == "}") ctx = popContext(state);166while (ctx.type == "statement") ctx = popContext(state);167}168else if (curPunc == ctx.type) popContext(state);169else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))170pushContext(state, stream.column(), "statement");171state.startOfLine = false;172return style;173},174
175indent: function(state, textAfter) {176if (state.tokenize != tokenBase && state.tokenize != null) return 0;177var firstChar = textAfter && textAfter.charAt(0), ctx = state.context, closing = firstChar == ctx.type;178if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);179else if (ctx.align) return ctx.column + (closing ? 0 : 1);180else return ctx.indented + (closing ? 0 : indentUnit);181},182
183electricChars: "{}"184};185});186
187CodeMirror.defineMIME("text/x-vhdl", "vhdl");188
189});190