6
if (typeof exports == "object" && typeof module == "object")
7
mod(require("../../lib/codemirror"));
8
else if (typeof define == "function" && define.amd)
9
define(["../../lib/codemirror"], mod);
12
})(function(CodeMirror) {
16
var obj = {}, words = str.split(",");
17
for (var i = 0; i < words.length; ++i) {
18
var allCaps = words[i].toUpperCase();
19
var firstCap = words[i].charAt(0).toUpperCase() + words[i].slice(1);
27
function metaHook(stream) {
28
stream.eatWhile(/[\w\$_]/);
32
CodeMirror.defineMode("vhdl", function(config, parserConfig) {
33
var indentUnit = config.indentUnit,
34
atoms = parserConfig.atoms || words("null"),
35
hooks = parserConfig.hooks || {"`": metaHook, "$": metaHook},
36
multiLineStrings = parserConfig.multiLineStrings;
38
var 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");
46
var blockKeywords = words("architecture,entity,begin,case,port,else,elsif,end,for,function,if");
48
var isOperatorChar = /[&|~><!\)\(*#%@+\/=?\:;}{,\.\^\-\[\]]/;
51
function tokenBase(stream, state) {
52
var ch = stream.next();
54
var result = hooks[ch](stream, state);
55
if (result !== false) return result;
58
state.tokenize = tokenString2(ch);
59
return state.tokenize(stream, state);
62
state.tokenize = tokenString(ch);
63
return state.tokenize(stream, state);
65
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
69
if (/[\d']/.test(ch)) {
70
stream.eatWhile(/[\w\.']/);
74
if (stream.eat("-")) {
79
if (isOperatorChar.test(ch)) {
80
stream.eatWhile(isOperatorChar);
83
stream.eatWhile(/[\w\$_]/);
84
var cur = stream.current();
85
if (keywords.propertyIsEnumerable(cur.toLowerCase())) {
86
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
89
if (atoms.propertyIsEnumerable(cur)) return "atom";
93
function tokenString(quote) {
94
return function(stream, state) {
95
var escaped = false, next, end = false;
96
while ((next = stream.next()) != null) {
97
if (next == quote && !escaped) {end = true; break;}
98
escaped = !escaped && next == "--";
100
if (end || !(escaped || multiLineStrings))
101
state.tokenize = tokenBase;
105
function tokenString2(quote) {
106
return function(stream, state) {
107
var escaped = false, next, end = false;
108
while ((next = stream.next()) != null) {
109
if (next == quote && !escaped) {end = true; break;}
110
escaped = !escaped && next == "--";
112
if (end || !(escaped || multiLineStrings))
113
state.tokenize = tokenBase;
118
function Context(indented, column, type, align, prev) {
119
this.indented = indented;
120
this.column = column;
125
function pushContext(state, col, type) {
126
return state.context = new Context(state.indented, col, type, null, state.context);
128
function popContext(state) {
129
var t = state.context.type;
130
if (t == ")" || t == "]" || t == "}")
131
state.indented = state.context.indented;
132
return state.context = state.context.prev;
137
startState: function(basecolumn) {
140
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
146
token: function(stream, state) {
147
var ctx = state.context;
149
if (ctx.align == null) ctx.align = false;
150
state.indented = stream.indentation();
151
state.startOfLine = true;
153
if (stream.eatSpace()) return null;
155
var style = (state.tokenize || tokenBase)(stream, state);
156
if (style == "comment" || style == "meta") return style;
157
if (ctx.align == null) ctx.align = true;
159
if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
160
else if (curPunc == "{") pushContext(state, stream.column(), "}");
161
else if (curPunc == "[") pushContext(state, stream.column(), "]");
162
else if (curPunc == "(") pushContext(state, stream.column(), ")");
163
else if (curPunc == "}") {
164
while (ctx.type == "statement") ctx = popContext(state);
165
if (ctx.type == "}") ctx = popContext(state);
166
while (ctx.type == "statement") ctx = popContext(state);
168
else if (curPunc == ctx.type) popContext(state);
169
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
170
pushContext(state, stream.column(), "statement");
171
state.startOfLine = false;
175
indent: function(state, textAfter) {
176
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
177
var firstChar = textAfter && textAfter.charAt(0), ctx = state.context, closing = firstChar == ctx.type;
178
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
179
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
180
else return ctx.indented + (closing ? 0 : indentUnit);
187
CodeMirror.defineMIME("text/x-vhdl", "vhdl");