[Pharo-project] Compiling code on a web request; non interactive compilation
Hi, I'm sending code from a web-based editor back into Pharo for compilation and trying to catch compilation errors and return them to the browser. I've created a notifier which implements #notify:at:in: and I pass an instance into the compiler in something like: compiler := Compiler new. compiler from: codeToCompile class: aClass context: nil notifying: notifier. compiler translate: codeToCompile readStream noPattern: false ifFail: [ ... ] Is there a better compiler API to use? I've noticed that I appear to have to mock additional methods in the notifier e.g. #selectFrom:to: and #selectionInterval, though still find that a morphic UI appears in my image asking for variable creation confirmation etc. I then tried using the NonInteractiveUIManager, but found my image quit with DNU on NonInteractiveUIManager>>#openDebuggerOn:context:label:contents:fullView:, which I duly implemented, but am starting to feel like there must be easier way. Have I missed something? Thanks Nick
Nick, I've had success in tODE with the following: [ main currentSystem evaluate: aString in: nil to: self object notifying: self notifier ifFail: [ self error: 'evaluation failed' ] ] on: UndeclaredVariable , UnknownSelector do: [ :ex | (ex isKindOf: UnknownSelector) ifTrue: [ ^ ex resume: ex name asSymbol ]. self notify: 'Undeclared variable -->' at: ex interval first in: aString readStream. ex resume: nil ] `self notifier` is my GUI mock class that intercepts several methods and for the most part drops things on the floor. The exception handler above catches unknown selectors and continues (basically declaring them as valid), while the UndeclaredVariable exception ends up inserting a message in the tODE editor...It looks like the mock class also forwards #notify:at:in: messages ... Dale ----- Original Message ----- | From: "Nick Ager" <nick.ager@gmail.com> | To: "pharo-project" <Pharo-project@lists.gforge.inria.fr> | Sent: Wednesday, September 7, 2011 3:39:57 PM | Subject: [Pharo-project] Compiling code on a web request; non interactive compilation | | Hi, | | | I'm sending code from a web-based editor back into Pharo for | compilation and trying to catch compilation errors and return them | to the browser. | | | I've created a notifier which implements #notify:at:in: and I pass an | instance into the compiler in something like: | | | | compiler := Compiler new. | compiler from: codeToCompile class: aClass context: nil notifying: | notifier. | compiler translate: codeToCompile readStream noPattern: false ifFail: | [ ... ] | | | Is there a better compiler API to use? | | | I've noticed that I appear to have to mock additional methods in the | notifier e.g. #selectFrom:to: and #selectionInterval, though still | find that a morphic UI appears in my image asking for variable | creation confirmation etc. | | | I then tried using the NonInteractiveUIManager, but found my image | quit with DNU on | NonInteractiveUIManager>>#openDebuggerOn:context:label:contents:fullView:, | which I duly implemented, but am starting to feel like there must be | easier way. Have I missed something? | | | Thanks | | | Nick
Thanks Dale that worked for me though I needed to add an accessor #interval in UnknownSelector On 7 September 2011 23:56, Dale Henrichs <dhenrich@vmware.com> wrote:
Nick,
I've had success in tODE with the following:
[ main currentSystem evaluate: aString in: nil to: self object notifying: self notifier ifFail: [ self error: 'evaluation failed' ] ] on: UndeclaredVariable , UnknownSelector do: [ :ex | (ex isKindOf: UnknownSelector) ifTrue: [ ^ ex resume: ex name asSymbol ]. self notify: 'Undeclared variable -->' at: ex interval first in: aString readStream. ex resume: nil ]
`self notifier` is my GUI mock class that intercepts several methods and for the most part drops things on the floor.
The exception handler above catches unknown selectors and continues (basically declaring them as valid), while the UndeclaredVariable exception ends up inserting a message in the tODE editor...It looks like the mock class also forwards #notify:at:in: messages ...
Dale
----- Original Message ----- | From: "Nick Ager" <nick.ager@gmail.com> | To: "pharo-project" <Pharo-project@lists.gforge.inria.fr> | Sent: Wednesday, September 7, 2011 3:39:57 PM | Subject: [Pharo-project] Compiling code on a web request; non interactive compilation | | Hi, | | | I'm sending code from a web-based editor back into Pharo for | compilation and trying to catch compilation errors and return them | to the browser. | | | I've created a notifier which implements #notify:at:in: and I pass an | instance into the compiler in something like: | | | | compiler := Compiler new. | compiler from: codeToCompile class: aClass context: nil notifying: | notifier. | compiler translate: codeToCompile readStream noPattern: false ifFail: | [ ... ] | | | Is there a better compiler API to use? | | | I've noticed that I appear to have to mock additional methods in the | notifier e.g. #selectFrom:to: and #selectionInterval, though still | find that a morphic UI appears in my image asking for variable | creation confirmation etc. | | | I then tried using the NonInteractiveUIManager, but found my image | quit with DNU on | NonInteractiveUIManager>>#openDebuggerOn:context:label:contents:fullView:, | which I duly implemented, but am starting to feel like there must be | easier way. Have I missed something? | | | Thanks | | | Nick
participants (2)
-
Dale Henrichs -
Nick Ager