5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.defineMode("ebnf", function (config) {
15
var commentType = {slash: 0, parenthesis: 1};
16
var stateType = {comment: 0, _string: 1, characterClass: 2};
17
var bracesMode = null;
19
if (config.bracesMode)
20
bracesMode = CodeMirror.getMode(config, config.bracesMode);
23
startState: function () {
34
token: function (stream, state) {
38
if (state.stack.length === 0) {
40
if ((stream.peek() == '"') || (stream.peek() == "'")) {
41
state.stringType = stream.peek();
43
state.stack.unshift(stateType._string);
44
} else if (stream.match('/*')) {
45
state.stack.unshift(stateType.comment);
46
state.commentType = commentType.slash;
47
} else if (stream.match('(*')) {
48
state.stack.unshift(stateType.comment);
49
state.commentType = commentType.parenthesis;
55
switch (state.stack[0]) {
56
case stateType._string:
57
while (state.stack[0] === stateType._string && !stream.eol()) {
58
if (stream.peek() === state.stringType) {
61
} else if (stream.peek() === "\\") {
65
stream.match(/^.[^\\\"\']*/);
68
return state.lhs ? "property string" : "string";
70
case stateType.comment:
71
while (state.stack[0] === stateType.comment && !stream.eol()) {
72
if (state.commentType === commentType.slash && stream.match('*/')) {
74
state.commentType = null;
75
} else if (state.commentType === commentType.parenthesis && stream.match('*)')) {
77
state.commentType = null;
79
stream.match(/^.[^\*]*/);
84
case stateType.characterClass:
85
while (state.stack[0] === stateType.characterClass && !stream.eol()) {
86
if (!(stream.match(/^[^\]\\]+/) || stream.match('.'))) {
93
var peek = stream.peek();
95
if (bracesMode !== null && (state.braced || peek === "{")) {
96
if (state.localState === null)
97
state.localState = CodeMirror.startState(bracesMode);
99
var token = bracesMode.token(stream, state.localState),
100
text = stream.current();
103
for (var i = 0; i < text.length; i++) {
104
if (text[i] === "{") {
105
if (state.braced === 0) {
106
token = "matchingbracket";
109
} else if (text[i] === "}") {
111
if (state.braced === 0) {
112
token = "matchingbracket";
124
state.stack.unshift(stateType.characterClass);
132
if (stream.match("%%")) {
134
} else if (stream.match(/[%][A-Za-z]+/)) {
136
} else if (stream.match(/[%][}]/)) {
137
return "matchingbracket";
141
if (stream.match(/[\/][A-Za-z]+/)) {
145
if (stream.match(/[\][a-z]+/)) {
149
if (stream.match(".")) {
156
if (stream.match(peek)) {
160
if (stream.match("$$")) {
162
} else if (stream.match(/[$][0-9]+/)) {
166
if (stream.match(/<<[a-zA-Z_]+>>/)) {
171
if (stream.match('//')) {
174
} else if (stream.match('return')) {
176
} else if (stream.match(/^[a-zA-Z_][a-zA-Z0-9_]*/)) {
177
if (stream.match(/(?=[\(.])/)) {
179
} else if (stream.match(/(?=[\s\n]*[:=])/)) {
183
} else if (["[", "]", "(", ")"].indexOf(stream.peek()) != -1) {
186
} else if (!stream.eatSpace()) {
194
CodeMirror.defineMIME("text/x-ebnf", "ebnf");