5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"), require("../clike/clike"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror", "../clike/clike"], mod);
11
})(function(CodeMirror) {
14
var keywords = ("this super static final const abstract class extends external factory " +
15
"implements mixin get native set typedef with enum throw rethrow " +
16
"assert break case continue default in return new deferred async await covariant " +
17
"try catch finally do else for if switch while import library export " +
18
"part of show hide is as extension on yield late required").split(" ");
19
var blockKeywords = "try catch finally do else for if switch while".split(" ");
20
var atoms = "true false null".split(" ");
21
var builtins = "void bool num int double dynamic var String Null Never".split(" ");
25
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
29
function pushInterpolationStack(state) {
30
(state.interpolationStack || (state.interpolationStack = [])).push(state.tokenize);
33
function popInterpolationStack(state) {
34
return (state.interpolationStack || (state.interpolationStack = [])).pop();
37
function sizeInterpolationStack(state) {
38
return state.interpolationStack ? state.interpolationStack.length : 0;
41
CodeMirror.defineMIME("application/dart", {
43
keywords: set(keywords),
44
blockKeywords: set(blockKeywords),
45
builtin: set(builtins),
48
"@": function(stream) {
49
stream.eatWhile(/[\w\$_\.]/);
54
"'": function(stream, state) {
55
return tokenString("'", stream, state, false);
57
"\"": function(stream, state) {
58
return tokenString("\"", stream, state, false);
60
"r": function(stream, state) {
61
var peek = stream.peek();
62
if (peek == "'" || peek == "\"") {
63
return tokenString(stream.next(), stream, state, true);
68
"}": function(_stream, state) {
70
if (sizeInterpolationStack(state) > 0) {
71
state.tokenize = popInterpolationStack(state);
77
"/": function(stream, state) {
78
if (!stream.eat("*")) return false
79
state.tokenize = tokenNestedComment(1)
80
return state.tokenize(stream, state)
82
token: function(stream, _, style) {
83
if (style == "variable") {
85
var isUpper = RegExp('^[_$]*[A-Z][a-zA-Z0-9_$]*$','g');
86
if (isUpper.test(stream.current())) {
94
function tokenString(quote, stream, state, raw) {
95
var tripleQuoted = false;
96
if (stream.eat(quote)) {
97
if (stream.eat(quote)) tripleQuoted = true;
100
function tokenStringHelper(stream, state) {
102
while (!stream.eol()) {
103
if (!raw && !escaped && stream.peek() == "$") {
104
pushInterpolationStack(state);
105
state.tokenize = tokenInterpolation;
108
var next = stream.next();
109
if (next == quote && !escaped && (!tripleQuoted || stream.match(quote + quote))) {
110
state.tokenize = null;
113
escaped = !raw && !escaped && next == "\\";
117
state.tokenize = tokenStringHelper;
118
return tokenStringHelper(stream, state);
121
function tokenInterpolation(stream, state) {
123
if (stream.eat("{")) {
126
state.tokenize = null;
128
state.tokenize = tokenInterpolationIdentifier;
133
function tokenInterpolationIdentifier(stream, state) {
134
stream.eatWhile(/[\w_]/);
135
state.tokenize = popInterpolationStack(state);
139
function tokenNestedComment(depth) {
140
return function (stream, state) {
142
while (ch = stream.next()) {
143
if (ch == "*" && stream.eat("/")) {
145
state.tokenize = null
148
state.tokenize = tokenNestedComment(depth - 1)
149
return state.tokenize(stream, state)
151
} else if (ch == "/" && stream.eat("*")) {
152
state.tokenize = tokenNestedComment(depth + 1)
153
return state.tokenize(stream, state)
160
CodeMirror.registerHelper("hintWords", "application/dart", keywords.concat(atoms).concat(builtins));
163
CodeMirror.defineMode("dart", function(conf) {
164
return CodeMirror.getMode(conf, "application/dart");