This repository has been archived by the owner on Sep 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvash.js
72 lines (59 loc) · 2.55 KB
/
vash.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
CodeMirror.defineMode("vash", function (config, parserConfig) {
//config settings
var scriptStartRegex = parserConfig.scriptStartRegex || /^@[{\(_\$a-zA-Z]/i,
scriptEndRegex = parserConfig.scriptEndRegex || /^[\}\)\<]/i;
//scriptEndRegex = parserConfig.scriptEndRegex || /^[\}\)\;]$/i;
//inner modes
var scriptingMode, htmlMixedMode;
//tokenizer when in html mode
function htmlDispatch(stream, state) {
if (stream.match(scriptStartRegex, false)) {
state.token = scriptingDispatch;
return scriptingMode.token(stream, state.scriptState);
}
else
return htmlMixedMode.token(stream, state.htmlState);
}
//tokenizer when in scripting mode
function scriptingDispatch(stream, state) {
if (stream.match(scriptEndRegex, false)) {
state.token = htmlDispatch;
return htmlMixedMode.token(stream, state.htmlState);
}
else
return scriptingMode.token(stream, state.scriptState);
}
return {
startState: function () {
scriptingMode = scriptingMode || CodeMirror.getMode(config, parserConfig.scriptingModeSpec);
htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed");
return {
token: parserConfig.startOpen ? scriptingDispatch : htmlDispatch,
htmlState: CodeMirror.startState(htmlMixedMode),
scriptState: CodeMirror.startState(scriptingMode)
};
},
token: function (stream, state) {
return state.token(stream, state);
},
indent: function (state, textAfter) {
if (state.token == htmlDispatch)
return htmlMixedMode.indent(state.htmlState, textAfter);
else if (scriptingMode.indent)
return scriptingMode.indent(state.scriptState, textAfter);
},
copyState: function (state) {
return {
token: state.token,
htmlState: CodeMirror.copyState(htmlMixedMode, state.htmlState),
scriptState: CodeMirror.copyState(scriptingMode, state.scriptState)
};
},
electricChars: "/{}:",
innerMode: function (state) {
if (state.token == scriptingDispatch) return { state: state.scriptState, mode: scriptingMode };
else return { state: state.htmlState, mode: htmlMixedMode };
}
};
}, "htmlmixed");
CodeMirror.defineMIME("application/x-razor", { name: "vash", scriptingModeSpec: "text/x-razor" });