7
if (typeof exports == "object" && typeof module == "object")
8
mod(require("../../lib/codemirror"));
9
else if (typeof define == "function" && define.amd)
10
define(["../../lib/codemirror"], mod);
15
(function(CodeMirror) {
18
CodeMirror.defineMode("modelica", function(config, parserConfig) {
20
var indentUnit = config.indentUnit;
21
var keywords = parserConfig.keywords || {};
22
var builtin = parserConfig.builtin || {};
23
var atoms = parserConfig.atoms || {};
25
var isSingleOperatorChar = /[;=\(:\),{}.*<>+\-\/^\[\]]/;
26
var isDoubleOperatorChar = /(:=|<=|>=|==|<>|\.\+|\.\-|\.\*|\.\/|\.\^)/;
27
var isDigit = /[0-9]/;
28
var isNonDigit = /[_a-zA-Z]/;
30
function tokenLineComment(stream, state) {
32
state.tokenize = null;
36
function tokenBlockComment(stream, state) {
37
var maybeEnd = false, ch;
38
while (ch = stream.next()) {
39
if (maybeEnd && ch == "/") {
40
state.tokenize = null;
43
maybeEnd = (ch == "*");
48
function tokenString(stream, state) {
49
var escaped = false, ch;
50
while ((ch = stream.next()) != null) {
51
if (ch == '"' && !escaped) {
52
state.tokenize = null;
56
escaped = !escaped && ch == "\\";
62
function tokenIdent(stream, state) {
63
stream.eatWhile(isDigit);
64
while (stream.eat(isDigit) || stream.eat(isNonDigit)) { }
67
var cur = stream.current();
69
if(state.sol && (cur == "package" || cur == "model" || cur == "when" || cur == "connector")) state.level++;
70
else if(state.sol && cur == "end" && state.level > 0) state.level--;
72
state.tokenize = null;
75
if (keywords.propertyIsEnumerable(cur)) return "keyword";
76
else if (builtin.propertyIsEnumerable(cur)) return "builtin";
77
else if (atoms.propertyIsEnumerable(cur)) return "atom";
78
else return "variable";
81
function tokenQIdent(stream, state) {
82
while (stream.eat(/[^']/)) { }
84
state.tokenize = null;
93
function tokenUnsignedNumber(stream, state) {
94
stream.eatWhile(isDigit);
95
if (stream.eat('.')) {
96
stream.eatWhile(isDigit);
98
if (stream.eat('e') || stream.eat('E')) {
101
stream.eatWhile(isDigit);
104
state.tokenize = null;
111
startState: function() {
119
token: function(stream, state) {
120
if(state.tokenize != null) {
121
return state.tokenize(stream, state);
129
if(stream.eatSpace()) {
130
state.tokenize = null;
134
var ch = stream.next();
137
if(ch == '/' && stream.eat('/')) {
138
state.tokenize = tokenLineComment;
141
else if(ch == '/' && stream.eat('*')) {
142
state.tokenize = tokenBlockComment;
145
else if(isDoubleOperatorChar.test(ch+stream.peek())) {
147
state.tokenize = null;
151
else if(isSingleOperatorChar.test(ch)) {
152
state.tokenize = null;
156
else if(isNonDigit.test(ch)) {
157
state.tokenize = tokenIdent;
160
else if(ch == "'" && stream.peek() && stream.peek() != "'") {
161
state.tokenize = tokenQIdent;
165
state.tokenize = tokenString;
168
else if(isDigit.test(ch)) {
169
state.tokenize = tokenUnsignedNumber;
173
state.tokenize = null;
177
return state.tokenize(stream, state);
180
indent: function(state, textAfter) {
181
if (state.tokenize != null) return CodeMirror.Pass;
183
var level = state.level;
184
if(/(algorithm)/.test(textAfter)) level--;
185
if(/(equation)/.test(textAfter)) level--;
186
if(/(initial algorithm)/.test(textAfter)) level--;
187
if(/(initial equation)/.test(textAfter)) level--;
188
if(/(end)/.test(textAfter)) level--;
191
return indentUnit*level;
196
blockCommentStart: "/*",
197
blockCommentEnd: "*/",
202
function words(str) {
203
var obj = {}, words = str.split(" ");
204
for (var i=0; i<words.length; ++i)
205
obj[words[i]] = true;
209
var modelicaKeywords = "algorithm and annotation assert block break class connect connector constant constrainedby der discrete each else elseif elsewhen encapsulated end enumeration equation expandable extends external false final flow for function if import impure in initial inner input loop model not operator or outer output package parameter partial protected public pure record redeclare replaceable return stream then true type when while within";
210
var modelicaBuiltin = "abs acos actualStream asin atan atan2 cardinality ceil cos cosh delay div edge exp floor getInstanceName homotopy inStream integer log log10 mod pre reinit rem semiLinear sign sin sinh spatialDistribution sqrt tan tanh";
211
var modelicaAtoms = "Real Boolean Integer String";
213
function def(mimes, mode) {
214
if (typeof mimes == "string")
221
for (var prop in obj)
222
if (obj.hasOwnProperty(prop))
231
mode.helperType = mimes[0];
232
CodeMirror.registerHelper("hintWords", mimes[0], words);
235
for (var i=0; i<mimes.length; ++i)
236
CodeMirror.defineMIME(mimes[i], mode);
239
def(["text/x-modelica"], {
241
keywords: words(modelicaKeywords),
242
builtin: words(modelicaBuiltin),
243
atoms: words(modelicaAtoms)