Lively Kernel canvas
ometaSmalltalkParser<:Parser{/*----------------------------------recognizingtokens------------------------------------*/space=super(#space)|fromTo('"','"'),identifier=letter:xletterOrDigit*:xs->[x].concat(xs).join(''),unaryId=spacesidentifier:x~':'->x,binaryOp=spaces(char:c?(SmalltalkParser.isBinaryChar(c))->c)+:cs->cs.join(''),keywordPart=spacesidentifier:x':'->{x+':'},variable=spacesidentifier:name->{newStVariableNode(name)},instanceVariable=token('@')identifier:name->{newStInstanceVariableNode('@'+name)},literal=(stringLiteral|numberLiteral):v->{newStLiteralNode(v)},numberLiteral=('+'->1|'-'->{-1}|empty->1):signdigit+:num1('.'digit+|empty->'0'):num2->{sign*Number(num1.concat(['.']).concat(num2).inject('',function(num,ea){returnnum+ea}))},stringLiteral='\''(token('\'\'')->'\''|~'\''char)*:val'\''->val.join(''),arrayLiteral=token('#{')sequence:seqtoken('}')->{newStArrayLiteralNode(seq)},/*--------------------------------------expressions---------------------------------------*/primary=spaces(variable|instanceVariable|literal|arrayLiteral|'('expression:e')'->e|block),expression=exit|cascade|assignment|evaluation,exit=token('^')expression:e->{newStReturnNode(e)},assignment=(variable|instanceVariable):variabletoken(':=')expression:value->{newStAssignmentNode(variable,value)},cascade=evaluation:first(token(';')message)+:msgNodes->{if(!first.isMessage)throw(newError('Firstpartofcascadenotmessage'));varreceiver=first.receiver;msgNodes=[first].concat(msgNodes);msgNodes.forEach(function(ea){ea.receiver=receiver});newStCascadeNode(msgNodes,receiver);},evaluation=keywordSend,message=(keywordMsg|binaryMsg|unaryMsg),unarySend=primary:recunaryMsg*:msgNodes->{msgNodes.inject(rec,function(receiver,node){node.setReceiver(receiver);returnnode})},unaryMsg=unaryId:name->{newStUnaryMessageNode(name,null,null)},binarySend=unarySend:recbinaryMsg*:nodes->{nodes.inject(rec,function(receiver,node){node.setReceiver(receiver);returnnode})},binaryMsg=binaryOp:nameunarySend:arg->{newStBinaryMessageNode(name,[arg],null)},keywordSend=binarySend:reckeywordMsg:msgNode->{msgNode.setReceiver(rec);msgNode}|binarySend,keywordMsg=(keywordPart:keywordbinarySend:arg->[keyword,arg])+:partsAndArgs->{varname='',args=[];partsAndArgs.forEach(function(ea){name+=ea[0];args.push(ea[1])});newStKeywordMessageNode(name,args,null);},block=token('[')opt(#blockArgs):argsopt(#declaredVars):declaredopt(#sequence):stoken(']')->{newStInvokableNode(s,args,declared)},blockArgs=(token(':')identifier:arg->arg)+:argstoken('|')->args,/*------------------------------------methodrelated-------------------------------------*/sequence=(expression:e(token('.')|empty)->e)+:children->{newStSequenceNode(children)},declaredVars=token('|')(variable:v)*:varstoken('|')->vars,propertyOrMethod=pos:startspaces('-'->false|'+'->true):isMeta(property:ptoken('.')->p|method):nodepos:endspaces->{node.setMeta(isMeta);node.type='propertyOrMethod';node.startIndex=start;node.stopIndex=end-1;node},property=assignment:assgn->{newStPropertyNode(assgn)},method=methodNameAndArgs:nameAndArgs(primitiveBody|stMethodBody):methodNode->{methodNode.setMethodName(nameAndArgs[0]);methodNode.setArgs(nameAndArgs[1]);methodNode},stMethodBody=opt(#declaredVars):varsopt(#sequence):seq->{newStInvokableNode(seq,null,vars)},primitiveBody=token('{')->{$elf.count=0}(~'}'char:c->{if(c=='{')$elf.count++;c}|?($elf.count>0)token('}'):t->{$elf.count--;t})*:bodytoken('}')(token('.')|empty)->{newStPrimitveMethodNode(null,'{'+body.join('')+'}')},methodNameAndArgs=((keywordPart:keywordspacesidentifier:arg->[keyword,arg])+:partsAndArgs->{varname='';varargs=[];partsAndArgs.forEach(function(ea){name+=ea[0];args.push(ea[1])});[name,args]}|binaryOp:msgNamespacesidentifier:arg->[msgName,[arg]]|unaryId:msgName->[msgName,null]),/*-------------------------------------classrelated-------------------------------------*/smalltalkClass=pos:ptoken('<')(identifier:n->{newStLiteralNode(n)}):name(token(':')variable:superclass|empty)token('>')spacespropertyOrMethod*:methodsAndPropertiesspaces->{varklass=newStClassNode(name,methodsAndProperties,superclass);klass.type='smalltalkClass'klass.startIndex=p;klass.stopIndex=this.pos()-1;klass},smalltalkClasses=pos:p(smalltalkClass)*:clsend->{varall=newStFileNode(cls);all.type='smalltalkClasses';all.startIndex=p;all.stopIndex=this.pos()-1;all},/*-----------------------------------------helper----------------------------------------*/opt:rule=apply(rule)|empty->null,fromTo:x:y=seq(x)(~seq(y)char)*seq(y),log:x->{console.log(x);true}}20 [x].concat(xs).join(''),\n\nunaryId =\n spaces identifier:x ~':'\n -> x,\n\nbinaryOp =\n spaces (char:c ?(SmalltalkParser.isBinaryChar(c)) -> c)+:cs\n -> cs.join(''),\n \nkeywordPart =\n spaces identifier:x ':'\n -> {x + ':'},\n\nvariable =\n spaces identifier:name\n -> { new StVariableNode(name) },\n\ninstanceVariable =\n token('@') identifier:name\n -> { new StInstanceVariableNode('@' + name) },\n\nliteral =\n (stringLiteral | numberLiteral):v\n -> { new StLiteralNode(v) },\n\nnumberLiteral =\n ('+' -> 1 | '-' -> {-1} | empty -> 1):sign digit+:num1 ('.' digit+ | empty -> '0'):num2\n -> {sign * Number(num1.concat(['.']).concat(num2).inject('', function(num, ea) { return num + ea })) },\n\nstringLiteral =\n '\\'' (token('\\'\\'') -> '\\'' | ~'\\'' char)*:val '\\''\n -> val.join(''),\n\narrayLiteral =\n token('#{') sequence:seq token('}')\n -> { new StArrayLiteralNode(seq) },\n\n/*-----------------------------\n--------- expressions ---------\n------------------------------*/\nprimary =\n spaces (variable\n | instanceVariable\n | literal\n | arrayLiteral\n | '(' expression:e ')' -> e\n | block),\n\nexpression =\n exit | cascade | assignment | evaluation,\n\nexit =\n token('^') expression:e\n -> { new StReturnNode(e) },\n\nassignment =\n (variable | instanceVariable):variable token(':=') expression:value\n\t-> { new StAssignmentNode(variable, value) },\n\ncascade =\n\tevaluation:first (token(';') message)+:msgNodes\n\t-> {\n\t\tif (!first.isMessage) throw(new Error('First part of cascade not message'));\n\t\tvar receiver = first.receiver;\n\t\tmsgNodes = [first].concat(msgNodes);\n\t\tmsgNodes.forEach(function(ea) { ea.receiver = receiver });\n\t\tnew StCascadeNode(msgNodes, receiver);\n\t},\n\nevaluation =\n keywordSend,\n\nmessage =\n (keywordMsg | binaryMsg | unaryMsg),\n\nunarySend =\n primary:rec unaryMsg*:msgNodes\n\t-> {msgNodes.inject(rec, function(receiver, node) {\n\t node.setReceiver(receiver); return node }) },\n\nunaryMsg =\n\tunaryId:name\n\t-> { new StUnaryMessageNode(name, null, null) },\n\nbinarySend =\n\tunarySend:rec binaryMsg*:nodes\n\t-> { nodes.inject(rec, function(receiver, node) {\n\t\tnode.setReceiver(receiver); return node }) },\n\nbinaryMsg =\n\tbinaryOp:name unarySend:arg\n\t-> { new StBinaryMessageNode(name, [arg], null) },\n\nkeywordSend =\n\tbinarySend:rec keywordMsg:msgNode\n\t-> { msgNode.setReceiver(rec); msgNode }\n\t| binarySend,\n\nkeywordMsg =\n\t(keywordPart:keyword binarySend:arg -> [keyword, arg])+:partsAndArgs\n\t-> {\n\t\tvar name = '', args = [];\n\t\tpartsAndArgs.forEach(function(ea) { name += ea[0]; args.push(ea[1]) });\n\t\tnew StKeywordMessageNode(name, args, null);\n\t},\n\nblock =\n\ttoken('[')\n\topt(#blockArgs):args\n\topt(#declaredVars):declared\n\topt(#sequence):s\n\ttoken(']')\n\t-> { new StInvokableNode(s, args, declared) },\n\nblockArgs =\n\t(token(':') identifier:arg -> arg)+:args token('|')\n\t-> args,\n\n/*-----------------------------\n------- method related -------\n------------------------------*/\nsequence =\n (expression:e ( token('.') | empty ) -> e)+:children\n -> { new StSequenceNode(children) },\n\ndeclaredVars =\n token('|') (variable:v)*:vars token('|')\n -> vars,\n\npropertyOrMethod =\n pos:start spaces ('-' -> false | '+' -> true):isMeta (property:p token('.') -> p | method):node pos:end spaces\n -> { node.setMeta(isMeta);\n\t\tnode.type = 'propertyOrMethod';\n\t\tnode.startIndex = start;\n\t\tnode.stopIndex = end-1;\n\t\tnode\n\t},\n \nproperty =\n assignment:assgn\n -> { new StPropertyNode(assgn) },\n\n \nmethod =\n\tmethodNameAndArgs:nameAndArgs (primitiveBody | stMethodBody):methodNode\n\t-> {\n\t\tmethodNode.setMethodName(nameAndArgs[0]);\n\t\tmethodNode.setArgs(nameAndArgs[1]);\n\t\tmethodNode\n\t},\n\nstMethodBody =\n opt(#declaredVars):vars opt(#sequence):seq\n\t-> { new StInvokableNode(seq, null, vars) },\n\nprimitiveBody =\n\ttoken('{') -> {$elf.count = 0}\n\t( ~'}' char:c -> {if (c=='{') $elf.count++; c} | ?($elf.count > 0) token('}'):t -> {$elf.count--; t}\n\t)*:body\n\ttoken('}') (token('.') | empty)\n\t-> { new StPrimitveMethodNode(null, '{' + body.join('') + '}') },\n\n\nmethodNameAndArgs =\n\t((keywordPart:keyword spaces identifier:arg -> [keyword, arg])+:partsAndArgs\n\t\t-> {var name = ''; var args = [];\n\t\t\tpartsAndArgs.forEach(function(ea) { name += ea[0]; args.push(ea[1]) });\n\t\t\t[name, args]}\n\t| binaryOp:msgName spaces identifier:arg -> [msgName, [arg]]\n\t| unaryId:msgName -> [msgName, null]\n\t),\n\n/*-----------------------------\n-------- class related -------\n------------------------------*/\nsmalltalkClass =\n\tpos:p token('<') (identifier:n -> {new StLiteralNode(n)}):name ( token(':') variable:superclass | empty) token('>')\n\tspaces propertyOrMethod*:methodsAndProperties spaces\n\t-> { var klass = new StClassNode(name, methodsAndProperties, superclass);\n\t\tklass.type = 'smalltalkClass'\n\t\tklass.startIndex = p;\n\t\tklass.stopIndex = this.pos()-1;\n\t\tklass\n\t},\n\nsmalltalkClasses =\n\tpos:p (smalltalkClass)*:cls end\n\t-> {\n\t\tvar all = new StFileNode(cls);\n\t\tall.type = 'smalltalkClasses';\n\t\tall.startIndex = p;\n\t\tall.stopIndex = this.pos()-1;\n\t\tall\n\t},\n\n/*-----------------------------\n------------ helper ----------\n------------------------------*/\nopt:rule =\n\tapply(rule) | empty -> null,\n\nfromTo :x :y =\n\tseq(x) (~seq(y) char)* seq(y),\n\nlog:x\n\t-> {console.log(x); true}\n}\n"]]>232truetruefalse [x].concat(xs).join(''),\n\nunaryId =\n spaces identifier:x ~':'\n -> x,\n\nbinaryOp =\n spaces (char:c ?(SmalltalkParser.isBinaryChar(c)) -> c)+:cs\n -> cs.join(''),\n \nkeywordPart =\n spaces identifier:x ':'\n -> {x + ':'},\n\nvariable =\n spaces identifier:name\n -> { new StVariableNode(name) },\n\ninstanceVariable =\n token('@') identifier:name\n -> { new StInstanceVariableNode('@' + name) },\n\nliteral =\n (stringLiteral | numberLiteral):v\n -> { new StLiteralNode(v) },\n\nnumberLiteral =\n ('+' -> 1 | '-' -> {-1} | empty -> 1):sign digit+:num1 ('.' digit+ | empty -> '0'):num2\n -> {sign * Number(num1.concat(['.']).concat(num2).inject('', function(num, ea) { return num + ea })) },\n\nstringLiteral =\n '\\'' (token('\\'\\'') -> '\\'' | ~'\\'' char)*:val '\\''\n -> val.join(''),\n\narrayLiteral =\n token('#{') sequence:seq token('}')\n -> { new StArrayLiteralNode(seq) },\n\n/*-----------------------------\n--------- expressions ---------\n------------------------------*/\nprimary =\n spaces (variable\n | instanceVariable\n | literal\n | arrayLiteral\n | '(' expression:e ')' -> e\n | block),\n\nexpression =\n exit | cascade | assignment | evaluation,\n\nexit =\n token('^') expression:e\n -> { new StReturnNode(e) },\n\nassignment =\n (variable | instanceVariable):variable token(':=') expression:value\n\t-> { new StAssignmentNode(variable, value) },\n\ncascade =\n\tevaluation:first (token(';') message)+:msgNodes\n\t-> {\n\t\tif (!first.isMessage) throw(new Error('First part of cascade not message'));\n\t\tvar receiver = first.receiver;\n\t\tmsgNodes = [first].concat(msgNodes);\n\t\tmsgNodes.forEach(function(ea) { ea.receiver = receiver });\n\t\tnew StCascadeNode(msgNodes, receiver);\n\t},\n\nevaluation =\n keywordSend,\n\nmessage =\n (keywordMsg | binaryMsg | unaryMsg),\n\nunarySend =\n primary:rec unaryMsg*:msgNodes\n\t-> {msgNodes.inject(rec, function(receiver, node) {\n\t node.setReceiver(receiver); return node }) },\n\nunaryMsg =\n\tunaryId:name\n\t-> { new StUnaryMessageNode(name, null, null) },\n\nbinarySend =\n\tunarySend:rec binaryMsg*:nodes\n\t-> { nodes.inject(rec, function(receiver, node) {\n\t\tnode.setReceiver(receiver); return node }) },\n\nbinaryMsg =\n\tbinaryOp:name unarySend:arg\n\t-> { new StBinaryMessageNode(name, [arg], null) },\n\nkeywordSend =\n\tbinarySend:rec keywordMsg:msgNode\n\t-> { msgNode.setReceiver(rec); msgNode }\n\t| binarySend,\n\nkeywordMsg =\n\t(keywordPart:keyword binarySend:arg -> [keyword, arg])+:partsAndArgs\n\t-> {\n\t\tvar name = '', args = [];\n\t\tpartsAndArgs.forEach(function(ea) { name += ea[0]; args.push(ea[1]) });\n\t\tnew StKeywordMessageNode(name, args, null);\n\t},\n\nblock =\n\ttoken('[')\n\topt(#blockArgs):args\n\topt(#declaredVars):declared\n\topt(#sequence):s\n\ttoken(']')\n\t-> { new StInvokableNode(s, args, declared) },\n\nblockArgs =\n\t(token(':') identifier:arg -> arg)+:args token('|')\n\t-> args,\n\n/*-----------------------------\n------- method related -------\n------------------------------*/\nsequence =\n (expression:e ( token('.') | empty ) -> e)+:children\n -> { new StSequenceNode(children) },\n\ndeclaredVars =\n token('|') (variable:v)*:vars token('|')\n -> vars,\n\npropertyOrMethod =\n pos:start spaces ('-' -> false | '+' -> true):isMeta (property:p token('.') -> p | method):node pos:end spaces\n -> { node.setMeta(isMeta);\n\t\tnode.type = 'propertyOrMethod';\n\t\tnode.startIndex = start;\n\t\tnode.stopIndex = end-1;\n\t\tnode\n\t},\n \nproperty =\n assignment:assgn\n -> { new StPropertyNode(assgn) },\n\n \nmethod =\n\tmethodNameAndArgs:nameAndArgs (primitiveBody | stMethodBody):methodNode\n\t-> {\n\t\tmethodNode.setMethodName(nameAndArgs[0]);\n\t\tmethodNode.setArgs(nameAndArgs[1]);\n\t\tmethodNode\n\t},\n\nstMethodBody =\n opt(#declaredVars):vars opt(#sequence):seq\n\t-> { new StInvokableNode(seq, null, vars) },\n\nprimitiveBody =\n\ttoken('{') -> {$elf.count = 0}\n\t( ~'}' char:c -> {if (c=='{') $elf.count++; c} | ?($elf.count > 0) token('}'):t -> {$elf.count--; t}\n\t)*:body\n\ttoken('}') (token('.') | empty)\n\t-> { new StPrimitveMethodNode(null, '{' + body.join('') + '}') },\n\n\nmethodNameAndArgs =\n\t((keywordPart:keyword spaces identifier:arg -> [keyword, arg])+:partsAndArgs\n\t\t-> {var name = ''; var args = [];\n\t\t\tpartsAndArgs.forEach(function(ea) { name += ea[0]; args.push(ea[1]) });\n\t\t\t[name, args]}\n\t| binaryOp:msgName spaces identifier:arg -> [msgName, [arg]]\n\t| unaryId:msgName -> [msgName, null]\n\t),\n\n/*-----------------------------\n-------- class related -------\n------------------------------*/\nsmalltalkClass =\n\tpos:p token('<') (identifier:n -> {new StLiteralNode(n)}):name ( token(':') variable:superclass | empty) token('>')\n\tspaces propertyOrMethod*:methodsAndProperties spaces\n\t-> { var klass = new StClassNode(name, methodsAndProperties, superclass);\n\t\tklass.type = 'smalltalkClass'\n\t\tklass.startIndex = p;\n\t\tklass.stopIndex = this.pos()-1;\n\t\tklass\n\t},\n\nsmalltalkClasses =\n\tpos:p (smalltalkClass)*:cls end\n\t-> {\n\t\tvar all = new StFileNode(cls);\n\t\tall.type = 'smalltalkClasses';\n\t\tall.startIndex = p;\n\t\tall.stopIndex = this.pos()-1;\n\t\tall\n\t},\n\n/*-----------------------------\n------------ helper ----------\n------------------------------*/\nopt:rule =\n\tapply(rule) | empty -> null,\n\nfromTo :x :y =\n\tseq(x) (~seq(y) char)* seq(y),\n\nlog:x\n\t-> {console.log(x); true}\n}\n"]]>truetruefalse
false00.11truefalsetruetruefalse
nullfalsetruenullfalse
OMetaSmalltalkParserfalsenulltruefalse
false
false
falsenullfalsefalsenullnullnullnullfalse
truenull
truenull
false
HTMLandJavaScript30
ChiefScientistGroup161
HTMLandJavaScript16nullnull
40nullnull
Demo:SmalltalkwithOMeta40nulltrue
1618null
•PurposeoftheTalk>CoveratopicofrelevancetoSAP>Demonstrateworkinprogress>Plantseedsforfurtherdiscussion•HTML-past,present,andfuture•JavaScript-past,present,andfuture•Tools•TheLivelyKernel•TheLivelyWorkbench•Questions2815 Cover a topic of relevance to SAP\n\t> Demonstrate work in progress\n\t> Plant seeds for further discussion\n\n• HTML - past, present, and future\n\n• JavaScript - past, present, and future\n\n• Tools\n\n• The Lively Kernel\n\n• The Lively Workbench\n\n• Questions"]]>true
prevfalsenulltruefalsetrue
nextfalsenulltruefalsetrue
//simplecode1+2.#{1.2.3.4.5.}collect:[:i|i*2].WorldMorphcurrentsetFill:(Colorr:255g:0b:0).//HowwarmisitinPaloAlto?extractTemp:=[:doc||tempElem|tempElem:=(docgetElementsByTagName:'temp_f')item:0.tempElemgetAttribute:'data'.].r:=WebResourcecreate:'http://www.google.com/ig/api?weather=Palo%20Alto'.extractTempvalue:rgetgetDocument.//"livelify"worldWorldMorphcurrentgetSubmorphsforEach:[:morph|morphsetVar:'velocity'value:(Globalp:20t:20)random;setVar:'angularVelocity'value:0.1*Mathrandom;start:100Stepping:'stepAndBounce']19truetruefalse
29truetruefalse
false00.11truefalsetruetruefalse
nullfalsetruenullfalse
SmalltalkWorkspacefalsenulltruefalse
false
false
falsenullfalsefalsenullnullnullnullfalse
show/hideOMetasourcefalsenulltruefalsetruenullfalse
//simplecode1+2.#{1.2.3.4.5.}collect:[:i|i*2].WorldMorphcurrentsetFill:(Colorr:255g:0b:0).//HowwarmisitinPaloAlto?extractTemp:=[:doc||tempElem|tempElem:=(docgetElementsByTagName:'temp_f')item:0.tempElemgetAttribute:'data'.].r:=WebResourcecreate:'http://www.google.com/ig/api?weather=Palo%20Alto'.extractTempvalue:rgetgetDocument.//"livelify"worldWorldMorphcurrentgetSubmorphsforEach:[:morph|morphsetVar:'velocity'value:(Globalp:20t:20)random;setVar:'angularVelocity'value:0.1*Mathrandom;start:100Stepping:'stepAndBounce']19truetruefalse27truetruefalse
false00.11truefalsetruetruefalse
nullfalsetruenullfalse
TranslatedJavaScriptsourcefalsenulltruefalse
false
false
falsenullfalsefalsenullnullnullnullfalse
null96