Note:primitive support/customization is handled by ScriptParser class methods when Scripting framework is used. In case of using S8 Compiler framework for scripting, directives/primitives are customized by events on SmalltalkParser (see SmalltalkParser>>#directive:ws:) |
"PP primitive support" (Compiler new respondsTo: #parse:onError:) ifFalse: [ self note: 'Compiler support for scripting is missing'. ^self abortPage ]. (Compiler new parse: ' <primitive: #hello> ^#ok ' onError: [:error| ^self note: 'NIY - ',error description ]) evaluate notNil ifTrue: [ self error: 'This should not happen' ].
"Sample implementation" Object subclass: #Sample! ! Sample class methodsFor: #compiler ! compiler | custom parser | custom := super compiler. parser := SmalltalkParser new. parser when: #needsDirectiveParser:ws: do: [:pNumber :ws| parser ,#basic: ,ws ,$# ,(PPInlineParser upTo: $>) ==> [:node| "JSDirectiveNode code: 'return ' ,node last printString protected: false" ReturnNode new addNode: (ValueNode with: node last); yourself ] ]. custom when: #needsParser do: [ parser ]. ^custom! ! ! Sample methodsFor: #testing ! hello <basic: #hello> ^#ok! ! (Compiler new parse: ' Sample new hello ' onError: [:error| ^self error: 'This should not happen' ]) evaluate = #hello ifFalse: [ self error: 'Wrong result' ].! Sample removeFromSystem!