'use strict';(function(g){"object"==typeof exports&&"object"==typeof module?g(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],g):g(CodeMirror)})(function(g){g.defineMode("crystal",function(g){function l(a,b){return new RegExp((b?"":"^")+"(?:"+a.join("|")+")"+(b?"$":"\\b"))}function h(a,b,c){c.tokenize.push(a);return a(b,c)}function r(a,b){if(a.eatSpace())return null;if("\\"!=b.lastToken&&a.match("{%",!1))return h(k("%","%"),a,b);if("\\"!=b.lastToken&&
a.match("{{",!1))return h(k("{","}"),a,b);if("#"==a.peek())return a.skipToEnd(),"comment";if(a.match(n)){a.eat(/[?!]/);var c=a.current();return a.eat(":")?"atom":"."==b.lastToken?"property":C.test(c)?(D.test(c)?"fun"==c&&0<=b.blocks.indexOf("lib")||"def"==c&&"abstract"==b.lastToken||(b.blocks.push(c),b.currentIndent+=1):"operator"!=b.lastStyle&&b.lastStyle||!E.test(c)?"end"==c&&(b.blocks.pop(),--b.currentIndent):(b.blocks.push(c),b.currentIndent+=1),x.hasOwnProperty(c)&&b.tokenize.push(x[c]),"keyword"):
F.test(c)?"atom":"variable"}if(a.eat("@")){if("["==a.peek())return h(p("[","]","meta"),a,b);a.eat("@");a.match(n)||a.match(q);return"variable-2"}if(a.match(q))return"tag";if(a.eat(":")){if(a.eat('"'))return h(t('"',"atom",!1),a,b);if(a.match(n)||a.match(q)||a.match(u)||a.match(v)||a.match(y))return"atom";a.eat(":");return"operator"}if(a.eat('"'))return h(t('"',"string",!0),a,b);if("%"==a.peek()){c="string";var e=!0;if(a.match("%r")){c="string-2";var d=a.next()}else if(a.match("%w"))e=!1,d=a.next();
else if(a.match("%q"))e=!1,d=a.next();else if(d=a.match(/^%([^\w\s=])/))d=d[1];else return a.match(/^%[a-zA-Z0-9_\u009F-\uFFFF]*/)?"meta":"operator";w.hasOwnProperty(d)&&(d=w[d]);return h(t(d,c,e),a,b)}if(c=a.match(/^<<-('?)([A-Z]\w*)\1/))return h(G(c[2],!c[1]),a,b);if(a.eat("'"))return a.match(/^(?:[^']|\\(?:[befnrtv0'"]|[0-7]{3}|u(?:[0-9a-fA-F]{4}|\{[0-9a-fA-F]{1,6}\})))/),a.eat("'"),"atom";if(a.eat("0"))return a.eat("x")?a.match(/^[0-9a-fA-F]+/):a.eat("o")?a.match(/^[0-7]+/):a.eat("b")&&a.match(/^[01]+/),
"number";if(a.eat(/^\d/))return a.match(/^\d*(?:\.\d+)?(?:[eE][+-]?\d+)?/),"number";if(a.match(u))return a.eat("="),"operator";if(a.match(v)||a.match(H))return"operator";if(c=a.match(/[({[]/,!1))return c=c[0],h(p(c,w[c],null),a,b);if(a.eat("\\"))return a.next(),"meta";a.next();return null}function p(a,b,c,e){return function(d,f){if(!e&&d.match(a))return f.tokenize[f.tokenize.length-1]=p(a,b,c,!0),f.currentIndent+=1,c;var g=r(d,f);d.current()===b&&(f.tokenize.pop(),--f.currentIndent,g=c);return g}}
function k(a,b,c){return function(e,d){return!c&&e.match("{"+a)?(d.currentIndent+=1,d.tokenize[d.tokenize.length-1]=k(a,b,!0),"meta"):e.match(b+"}")?(--d.currentIndent,d.tokenize.pop(),"meta"):r(e,d)}}function z(a,b){if(a.eatSpace())return null;a.match(n)?a.eat(/[!?]/):a.match(u)||a.match(v)||a.match(y);b.tokenize.pop();return"def"}function m(a,b){if(a.eatSpace())return null;a.match(q);b.tokenize.pop();return"def"}function t(a,b,c){return function(e,d){for(var f=!1;e.peek();)if(f)e.next(),f=!1;else{if(e.match("{%",
!1)){d.tokenize.push(k("%","%"));break}if(e.match("{{",!1)){d.tokenize.push(k("{","}"));break}if(c&&e.match("#{",!1)){d.tokenize.push(p("#{","}","meta"));break}f=e.next();if(f==a){d.tokenize.pop();break}f=c&&"\\"==f}return b}}function G(a,b){return function(c,e){if(c.sol()&&(c.eatSpace(),c.match(a)))return e.tokenize.pop(),"string";for(var d=!1;c.peek();)if(d)c.next(),d=!1;else{if(c.match("{%",!1)){e.tokenize.push(k("%","%"));break}if(c.match("{{",!1)){e.tokenize.push(k("{","}"));break}if(b&&c.match("#{",
!1)){e.tokenize.push(p("#{","}","meta"));break}d=b&&"\\"==c.next()}return"string"}}var u=/^(?:[-+/%|&^]|\*\*?|[<>]{2})/,v=/^(?:[=!]~|===|<=>|[<>=!]=?|[|&]{2}|~)/,y=/^(?:\[\][?=]?)/,H=/^(?:\.(?:\.{2})?|->|[?:])/,n=/^[a-z_\u009F-\uFFFF][a-zA-Z0-9_\u009F-\uFFFF]*/,q=/^[A-Z_\u009F-\uFFFF][a-zA-Z0-9_\u009F-\uFFFF]*/,C=l("abstract alias as asm begin break case class def do else elsif end ensure enum extend for fun if include instance_sizeof lib macro module next of out pointerof private protected rescue return require select sizeof struct super then type typeof uninitialized union unless until when while with yield __DIR__ __END_LINE__ __FILE__ __LINE__".split(" ")),
F=l(["true","false","nil","self"]),D=l("def fun macro class module struct lib enum union do for".split(" ")),E=l("if unless case while until begin then".split(" ")),A=["end","else","elsif","rescue","ensure"],I=l(A),B=["\\)","\\}","\\]"],J=new RegExp("^(?:"+B.join("|")+")$"),x={def:z,fun:z,macro:function(a,b){if(a.eatSpace())return null;var c;if(c=a.match(n)){if("def"==c)return"keyword";a.eat(/[?!]/)}b.tokenize.pop();return"def"},"class":m,module:m,struct:m,lib:m,"enum":m,union:m},w={"[":"]","{":"}",
"(":")","<":">"};return{startState:function(){return{tokenize:[r],currentIndent:0,lastToken:null,lastStyle:null,blocks:[]}},token:function(a,b){var c=b.tokenize[b.tokenize.length-1](a,b);a=a.current();c&&"comment"!=c&&(b.lastToken=a,b.lastStyle=c);return c},indent:function(a,b){b=b.replace(/^\s*(?:\{%)?\s*|\s*(?:%\})?\s*$/g,"");return I.test(b)||J.test(b)?g.indentUnit*(a.currentIndent-1):g.indentUnit*a.currentIndent},fold:"indent",electricInput:l(B.concat(A),!0),lineComment:"#"}});g.defineMIME("text/x-crystal",
"crystal")});
