// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
* Link to the project's GitHub page:
* https://github.com/duralog/CodeMirror
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
})(function(CodeMirror) {
CodeMirror.defineMode('livescript', function(){
var tokenBase = function(stream, state) {
var next_rule = state.next || "start";
var nr = Rules[next_rule];
for (var i$ = 0; i$ < nr.length; ++i$) {
if (r.regex && stream.match(r.regex)) {
state.next = r.next || state.next;
if (stream.match(r = Rules[next_rule])) {
if (r.regex && stream.match(r.regex)) {
lastToken: {style: null, indent: 0, content: ""}
token: function(stream, state){
while (stream.pos == stream.start)
var style = tokenBase(stream, state);
indent: stream.indentation(),
content: stream.current()
return style.replace(/\./g, ' ');
var indentation = state.lastToken.indent;
if (state.lastToken.content.match(indenter)) {
var identifier = '(?![\\d\\s])[$\\w\\xAA-\\uFFDC](?:(?!\\s)[$\\w\\xAA-\\uFFDC]|-[A-Za-z])*';
var indenter = RegExp('(?:[({[=:]|[-~]>|\\b(?:e(?:lse|xport)|d(?:o|efault)|t(?:ry|hen)|finally|import(?:\\s*all)?|const|var|let|new|catch(?:\\s*' + identifier + ')?))\\s*$');
var keywordend = '(?![$\\w]|-[A-Za-z]|\\s*:(?![:=]))';
regex: '(?:t(?:h(?:is|row|en)|ry|ypeof!?)|c(?:on(?:tinue|st)|a(?:se|tch)|lass)|i(?:n(?:stanceof)?|mp(?:ort(?:\\s+all)?|lements)|[fs])|d(?:e(?:fault|lete|bugger)|o)|f(?:or(?:\\s+own)?|inally|unction)|s(?:uper|witch)|e(?:lse|x(?:tends|port)|val)|a(?:nd|rguments)|n(?:ew|ot)|un(?:less|til)|w(?:hile|ith)|o[fr]|return|break|let|var|loop)' + keywordend
token: 'constant.language',
regex: '(?:true|false|yes|no|on|off|null|void|undefined)' + keywordend
token: 'invalid.illegal',
regex: '(?:p(?:ackage|r(?:ivate|otected)|ublic)|i(?:mplements|nterface)|enum|static|yield)' + keywordend
token: 'language.support.class',
regex: '(?:R(?:e(?:gExp|ferenceError)|angeError)|S(?:tring|yntaxError)|E(?:rror|valError)|Array|Boolean|Date|Function|Number|Object|TypeError|URIError)' + keywordend
token: 'language.support.function',
regex: '(?:is(?:NaN|Finite)|parse(?:Int|Float)|Math|JSON|(?:en|de)codeURI(?:Component)?)' + keywordend
token: 'variable.language',
regex: '(?:t(?:hat|il|o)|f(?:rom|allthrough)|it|by|e)' + keywordend
regex: identifier + '\\s*:(?![:=])'
token: 'keyword.operator',
regex: '(?:\\.{3}|\\s+\\?)'
token: 'keyword.variable',
regex: '(?:@+|::|\\.\\.)',
token: 'keyword.operator',
regex: '\\\\\\S[^\\s,;)}\\]]*'
regex: '\\/(?:[^[\\/\\n\\\\]*(?:(?:\\\\.|\\[[^\\]\\n\\\\]*(?:\\\\.[^\\]\\n\\\\]*)*\\])[^[\\/\\n\\\\]*)*)\\/[gimy$]{0,4}',
token: 'constant.numeric',
regex: '(?:0x[\\da-fA-F][\\da-fA-F_]*|(?:[2-9]|[12]\\d|3[0-6])r[\\da-zA-Z][\\da-zA-Z_]*|(?:\\d[\\d_]*(?:\\.\\d[\\d_]*)?|\\.\\d[\\d_]*)(?:e[+-]?\\d[\\d_]*)?[\\w$]*)'
token: 'keyword.operator',
regex: '.*?//[gimy$?]{0,4}',
token: 'keyword.operator',
regex: '[^\\\\\']*(?:\\\\.[^\\\\\']*)*\'',
regex: '[^\\\\"]*(?:\\\\.[^\\\\"]*)*"',
regex: '[^\\\\`]*(?:\\\\.[^\\\\`]*)*`',
for (var i = 0, len = r.length; i < len; ++i) {
if (typeof rr.regex === 'string') {
Rules[idx][i].regex = new RegExp('^' + rr.regex);
} else if (typeof rr.regex === 'string') {
Rules[idx].regex = new RegExp('^' + r.regex);
CodeMirror.defineMIME('text/x-livescript', 'livescript');