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