!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.registerHelper("wordChars","r",/[\w.]/),e.defineMode("r",function(e){function t(e){for(var t=e.split(" "),n={},r=0;r<t.length;++r)n[t[r]]=!0;return n}function n(e,t){c=null;var n=e.next();if("#"==n)return e.skipToEnd(),"comment";if("0"==n&&e.eat("x"))return e.eatWhile(/[\da-f]/i),"number";if("."==n&&e.eat(/\d/))return e.match(/\d*(?:e[+\-]?\d+)?/),"number";if(/\d/.test(n))return e.match(/\d*(?:\.\d+)?(?:e[+\-]\d+)?L?/),"number";if("'"==n||'"'==n)return t.tokenize=r(n),"string";if("`"==n)return e.match(/[^`]+`/),"variable-3";if("."==n&&e.match(/.[.\d]+/))return"keyword";if(/[\w\.]/.test(n)&&"_"!=n){e.eatWhile(/[\w\.]/);var i=e.current();return l.propertyIsEnumerable(i)?"atom":u.propertyIsEnumerable(i)?(d.propertyIsEnumerable(i)&&!e.match(/\s*if(\s+|$)/,!1)&&(c="block"),"keyword"):f.propertyIsEnumerable(i)?"builtin":"variable"}return"%"==n?(e.skipTo("%")&&e.next(),"operator variable-2"):"<"==n&&e.eat("-")||"<"==n&&e.match("<-")||"-"==n&&e.match(/>>?/)?"operator arrow":"="==n&&t.ctx.argList?"arg-is":s.test(n)?"$"==n?"operator dollar":(e.eatWhile(s),"operator"):/[\(\){}\[\];]/.test(n)?(c=n,";"==n?"semi":null):null}function r(e){return function(t,r){if(t.eat("\\")){var i=t.next();return"x"==i?t.match(/^[a-f0-9]{2}/i):("u"==i||"U"==i)&&t.eat("{")&&t.skipTo("}")?t.next():"u"==i?t.match(/^[a-f0-9]{4}/i):"U"==i?t.match(/^[a-f0-9]{8}/i):/[0-7]/.test(i)&&t.match(/^[0-7]{1,2}/),"string-2"}for(var a;null!=(a=t.next());){if(a==e){r.tokenize=n;break}if("\\"==a){t.backUp(1);break}}return"string"}}function i(e,t,n){e.ctx={type:t,indent:e.indent,flags:0,column:n.column(),prev:e.ctx}}function a(e,t){var n=e.ctx;e.ctx={type:n.type,indent:n.indent,flags:n.flags|t,column:n.column,prev:n.prev}}function o(e){e.indent=e.ctx.indent,e.ctx=e.ctx.prev}var c,l=t("NULL NA Inf NaN NA_integer_ NA_real_ NA_complex_ NA_character_"),f=t("list quote bquote eval return call parse deparse"),u=t("if else repeat while function for in next break"),d=t("if else repeat while function for"),s=/[+\-*\/^<>=!&|~$:]/;return{startState:function(){return{tokenize:n,ctx:{type:"top",indent:-e.indentUnit,flags:2},indent:0,afterIdent:!1}},token:function(e,t){if(e.sol()&&(0==(3&t.ctx.flags)&&(t.ctx.flags|=2),4&t.ctx.flags&&o(t),t.indent=e.indentation()),e.eatSpace())return null;var n=t.tokenize(e,t);return"comment"!=n&&0==(2&t.ctx.flags)&&a(t,1),";"!=c&&"{"!=c&&"}"!=c||"block"!=t.ctx.type||o(t),"{"==c?i(t,"}",e):"("==c?(i(t,")",e),t.afterIdent&&(t.ctx.argList=!0)):"["==c?i(t,"]",e):"block"==c?i(t,"block",e):c==t.ctx.type?o(t):"block"==t.ctx.type&&"comment"!=n&&a(t,4),t.afterIdent="variable"==n||"keyword"==n,n},indent:function(t,r){if(t.tokenize!=n)return 0;var i=r&&r.charAt(0),a=t.ctx,o=i==a.type;return 4&a.flags&&(a=a.prev),"block"==a.type?a.indent+("{"==i?0:e.indentUnit):1&a.flags?a.column+(o?0:1):a.indent+(o?0:e.indentUnit)},lineComment:"#"}}),e.defineMIME("text/x-rsrc","r")});