[Pharo-project] non-interactive compiling with feedback
Hello, i want to add some scripting capabilities to my app, and I wand to use plain smalltalk for that. The only problem is that I still haven't found a way to generate a compiled which would return a string describing a problem in case a syntax errors. Can I get some help? -- Milan Mimica
Hmm, you can compile a method with Behavior>>#compile:notifying: and send an observer implementing: #notify:at:in: and some other stuff like #selection #deselect... That way you can capture the errors... Guille On Sat, Mar 17, 2012 at 9:08 AM, Milan Mimica <milan.mimica@gmail.com>wrote:
Hello,
i want to add some scripting capabilities to my app, and I wand to use plain smalltalk for that. The only problem is that I still haven't found a way to generate a compiled which would return a string describing a problem in case a syntax errors. Can I get some help?
-- Milan Mimica
On 18 March 2012 23:20, Guillermo Polito <guillermopolito@gmail.com> wrote:
Hmm, you can compile a method with Behavior>>#compile:notifying:
and send an observer implementing:
#notify:at:in:
and some other stuff like #selection #deselect...
That way you can capture the errors...
This almost works. It doesn't raise errors for undeclared variables, instead it prompts for variable replacement. | method requestor | requestor := Mock new. (requestor stub: #selectionInterval) returns: (1 to: 2). requestor stub: #selectFrom:to:. (requestor stub: #bindingOf:) returns: nil. (requestor stub: #notify:at:in:) will: [ self halt ]. method := Compiler new compiledMethodFor: 'a:=1' in: nil to: nil notifying: requestor proxy ifFail: nil logged: false. method inspect I would like to catch the error. It is an error, right? -- Milan Mimica
Hi Milan, On Mon, Mar 19, 2012 at 11:22 AM, Milan Mimica <milan.mimica@gmail.com>wrote:
On 18 March 2012 23:20, Guillermo Polito <guillermopolito@gmail.com>wrote:
Hmm, you can compile a method with Behavior>>#compile:notifying:
and send an observer implementing:
#notify:at:in:
and some other stuff like #selection #deselect...
That way you can capture the errors...
This almost works. It doesn't raise errors for undeclared variables, instead it prompts for variable replacement.
| method requestor | requestor := Mock new. (requestor stub: #selectionInterval) returns: (1 to: 2). requestor stub: #selectFrom:to:. (requestor stub: #bindingOf:) returns: nil. (requestor stub: #notify:at:in:) will: [ self halt ]. method := Compiler new compiledMethodFor: 'a:=1' in: nil to: nil notifying: requestor proxy ifFail: nil logged: false. method inspect
I would like to catch the error. It is an error, right?
the answer is "not necessarily". Smalltalk deals with circular references between globals in source by using Undeclared. So if the source of class A references class B and vice verse, and they are filed-in one after another, when class A's source is compiled, a reference to B will be created in undeclared. When B's source is compiled, that Undeclared binding will be moved to Smalltalk and updated to reference class B. So one could say in non-interactive use a) compiling source containing an undeclared reference merits only a warning b) compiling source containiing an undeclared reference in the form of a variable beginning with lower-case is an error, since globals should be capitalized c) force classes to be defined before their source is compiled IMO, it's not an error, and a) is a good option. Note that if you did make it an error in all circumstances you'd badly break the system. --
Milan Mimica
-- HTH, Eliot
On 19 March 2012 21:04, Eliot Miranda <eliot.miranda@gmail.com> wrote:
a) compiling source containing an undeclared reference merits only a warning
IMO, it's not an error, and a) is a good option. Note that if you did make it an error in all circumstances you'd badly break the system.
Hi Eliot, a) works for me. I just need a string to display to the user, on compile time. So how do I get a warning? -- Milan Mimica http://sparklet.sf.net
On Mon, Mar 19, 2012 at 1:11 PM, Milan Mimica <milan.mimica@gmail.com>wrote:
On 19 March 2012 21:04, Eliot Miranda <eliot.miranda@gmail.com> wrote:
a) compiling source containing an undeclared reference merits only a warning
IMO, it's not an error, and a) is a good option. Note that if you did make it an error in all circumstances you'd badly break the system.
Hi Eliot,
a) works for me. I just need a string to display to the user, on compile time. So how do I get a warning?
Look at UndeclaredVariableWarning. The Squeak code isn't well favtored. defaultAction needs to be decomposed further into a messageText implementation. But basically I'd want the UndeclaredVariableWarning's messageText to provide the warning string. So I could do e.g. [Compiler evaluate: aString] on: UndeclaredVariableWarning do: [:ex| Transcript cr; show: ex messageText]
-- Milan Mimica http://sparklet.sf.net
-- best, Eliot
On 19 March 2012 23:28, Eliot Miranda <eliot.miranda@gmail.com> wrote:
Look at UndeclaredVariableWarning. The Squeak code isn't well favtored. defaultAction needs to be decomposed further into a messageText implementation. But basically I'd want the UndeclaredVariableWarning's messageText to provide the warning string. So I could do e.g.
[Compiler evaluate: aString] on: UndeclaredVariableWarning do: [:ex| Transcript cr; show: ex messageText]
Had to do this to make it work: MorphicUIManager default interactiveParser: false. -- Milan Mimica http://sparklet.sf.net
hi, generally if you compile source-code you will get a more or less descriptive error you can handle: [ myClass compile: 'foo;' ] on: Error do: [ :err| "handle the error" self halt ]. most of the time you will get a SyntaxErrorNotification. best cami On 2012-03-17, at 13:08, Milan Mimica wrote:
Hello,
i want to add some scripting capabilities to my app, and I wand to use plain smalltalk for that. The only problem is that I still haven't found a way to generate a compiled which would return a string describing a problem in case a syntax errors. Can I get some help?
-- Milan Mimica
If you have Grease loaded: Gofer new squeaksource: 'CodeGenerator'; package: 'CodeGenerator'; load. [CGSmalltalk new setSourceAsCode; targetClass: Object; compile: 'testMethod ^ 42. ^ 32' ] on: SyntaxErrorNotification " or Notification " do: [: ex | ^ ex errorMessage ] 2012/3/17 Milan Mimica <milan.mimica@gmail.com>
Hello,
i want to add some scripting capabilities to my app, and I wand to use plain smalltalk for that. The only problem is that I still haven't found a way to generate a compiled which would return a string describing a problem in case a syntax errors. Can I get some help?
-- Milan Mimica
-- Hernán Morales Institute of Veterinary Genetics. National Scientific and Technical Research Council (CONICET). La Plata (1900), Buenos Aires, Argentina. Telephone: +54 (0221) 421-1799. Internal: 422 Fax: 425-7980 or 421-1799.
What does it do this code? a := 1. (undeclared 'a') On 19 March 2012 07:13, Hernán Morales Durand <hernan.morales@gmail.com>wrote:
If you have Grease loaded:
Gofer new squeaksource: 'CodeGenerator'; package: 'CodeGenerator'; load.
[CGSmalltalk new setSourceAsCode; targetClass: Object; compile: 'testMethod ^ 42. ^ 32' ] on: SyntaxErrorNotification " or Notification " do: [: ex | ^ ex errorMessage ]
2012/3/17 Milan Mimica <milan.mimica@gmail.com>
Hello,
i want to add some scripting capabilities to my app, and I wand to use plain smalltalk for that. The only problem is that I still haven't found a way to generate a compiled which would return a string describing a problem in case a syntax errors. Can I get some help?
-- Milan Mimica
-- Hernán Morales Institute of Veterinary Genetics. National Scientific and Technical Research Council (CONICET). La Plata (1900), Buenos Aires, Argentina. Telephone: +54 (0221) 421-1799. Internal: 422 Fax: 425-7980 or 421-1799.
-- Milan Mimica http://sparklet.sf.net
participants (5)
-
Camillo Bruni -
Eliot Miranda -
Guillermo Polito -
Hernán Morales Durand -
Milan Mimica