smalltalk.js 1.83 KB
CodeMirror.defineMode("smalltalk",function(e,t){var n=/[+\-\/\\*~<>=@%|&?!.:;^]/,a=/true|false|nil|self|super|thisContext/,i=function(e,t){this.next=e,this.parent=t},r=function(e,t,n){this.name=e,this.context=t,this.eos=n},o=function(){this.context=new i(s,null),this.expectVariable=!0,this.indentation=0,this.userIndentationDelta=0};o.prototype.userIndent=function(t){this.userIndentationDelta=t>0?t/e.indentUnit-this.indentation:0};var s=function(e,t,o){var s=new r(null,t,(!1)),d=e.next();return'"'===d?s=l(e,new i(l,t)):"'"===d?s=u(e,new i(u,t)):"#"===d?(e.eatWhile(/[^ .]/),s.name="string-2"):"$"===d?(e.eatWhile(/[^ ]/),s.name="string-2"):"|"===d&&o.expectVariable?s.context=new i(c,t):/[\[\]{}()]/.test(d)?(s.name="bracket",s.eos=/[\[{(]/.test(d),"["===d?o.indentation++:"]"===d&&(o.indentation=Math.max(0,o.indentation-1))):n.test(d)?(e.eatWhile(n),s.name="operator",s.eos=";"!==d):/\d/.test(d)?(e.eatWhile(/[\w\d]/),s.name="number"):/[\w_]/.test(d)?(e.eatWhile(/[\w\d_]/),s.name=o.expectVariable?a.test(e.current())?"keyword":"variable":null):s.eos=o.expectVariable,s},l=function(e,t){return e.eatWhile(/[^"]/),new r("comment",e.eat('"')?t.parent:t,(!0))},u=function(e,t){return e.eatWhile(/[^']/),new r("string",e.eat("'")?t.parent:t,(!1))},c=function(e,t,n){var a=new r(null,t,(!1)),i=e.next();return"|"===i?(a.context=t.parent,a.eos=!0):(e.eatWhile(/[^|]/),a.name="variable"),a};return{startState:function(){return new o},token:function(e,t){if(t.userIndent(e.indentation()),e.eatSpace())return null;var n=t.context.next(e,t.context,t);return t.context=n.context,t.expectVariable=n.eos,t.lastToken=n,n.name},blankLine:function(e){e.userIndent(0)},indent:function(t,n){var a=t.context.next===s&&n&&"]"===n.charAt(0)?-1:t.userIndentationDelta;return(t.indentation+a)*e.indentUnit},electricChars:"]"}}),CodeMirror.defineMIME("text/x-stsrc",{name:"smalltalk"});