5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"), require("../javascript/javascript"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror", "../javascript/javascript"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.defineMode("pegjs", function (config) {
15
var jsMode = CodeMirror.getMode(config, "javascript");
17
function identifier(stream) {
18
return stream.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);
22
startState: function () {
27
inCharacterClass: false,
33
token: function (stream, state) {
37
if (!state.inString && !state.inComment && ((stream.peek() == '"') || (stream.peek() == "'"))) {
38
state.stringType = stream.peek();
40
state.inString = true;
42
if (!state.inString && !state.inComment && stream.match('/*')) {
43
state.inComment = true;
48
while (state.inString && !stream.eol()) {
49
if (stream.peek() === state.stringType) {
51
state.inString = false;
52
} else if (stream.peek() === '\\') {
56
stream.match(/^.[^\\\"\']*/);
59
return state.lhs ? "property string" : "string";
60
} else if (state.inComment) {
61
while (state.inComment && !stream.eol()) {
62
if (stream.match('*/')) {
63
state.inComment = false;
65
stream.match(/^.[^\*]*/);
69
} else if (state.inCharacterClass) {
70
while (state.inCharacterClass && !stream.eol()) {
71
if (!(stream.match(/^[^\]\\]+/) || stream.match(/^\\./))) {
72
state.inCharacterClass = false;
75
} else if (stream.peek() === '[') {
77
state.inCharacterClass = true;
79
} else if (stream.match('//')) {
82
} else if (state.braced || stream.peek() === '{') {
83
if (state.localState === null) {
84
state.localState = CodeMirror.startState(jsMode);
86
var token = jsMode.token(stream, state.localState);
87
var text = stream.current();
89
for (var i = 0; i < text.length; i++) {
90
if (text[i] === '{') {
92
} else if (text[i] === '}') {
98
} else if (identifier(stream)) {
99
if (stream.peek() === ':') {
103
} else if (['[', ']', '(', ')'].indexOf(stream.peek()) != -1) {
106
} else if (!stream.eatSpace()) {