Simplest 'REPL'

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Simplest 'REPL'

Seth
I've recently picked up pharo, and am writing a small interpreter for a trivial language the details of which are unimportant. However I am looking for the simplest way to avoid having to use playground and Transcript to do something like

| reader eval |
reader := MyReader from: 'some stuff in my DSL'.
eval := MyEvaluator from: reader.
Transcript show: eval evaluate.

I'm tired of having to change 'some stuff in my DSL' to a new expression and run it in playground.

I don't really care which is easier, a Morphic with an input box at the bottom to put my expressions in with output up top, or a something like CommandShellTranscript (which i have looked at but is too complex for me to figure out how to get the desired result from).

Basically I want to be able to use my DSL outside of playground, but still in image. 
Reply | Threaded
Open this post in threaded view
|

Re: Simplest 'REPL'

Hannes Hirzel
I understand that you want to write a tool with an input field and an
output field and a button 'Evaluate'.  Is this correct?

If yes you need to learn a little bit of Spec to construct your own tool.

Have a look at the examples for Spec in the help system.

There is also a booklet about Spec.  http://books.pharo.org/spec-tutorial/

HTH
Hannes

On 12/9/17, cheshirecatalyst <[hidden email]> wrote:

> I've recently picked up pharo, and am writing a small interpreter for a
> trivial language the details of which are unimportant. However I am looking
> for the simplest way to avoid having to use playground and Transcript to do
> something like
>
> | reader eval |
> reader := MyReader from: 'some stuff in my DSL'.
> eval := MyEvaluator from: reader.
> Transcript show: eval evaluate.
>
> I'm tired of having to change 'some stuff in my DSL' to a new expression
> and run it in playground.
>
> I don't really care which is easier, a Morphic with an input box at the
> bottom to put my expressions in with output up top, or a something like
> CommandShellTranscript (which i have looked at but is too complex for me to
> figure out how to get the desired result from).
>
> Basically I want to be able to use my DSL outside of playground, but still
> in image.
>

Reply | Threaded
Open this post in threaded view
|

Re: Simplest 'REPL'

Ben Coman
In reply to this post by Seth


On 9 December 2017 at 07:04, cheshirecatalyst <[hidden email]> wrote:
I've recently picked up pharo, and am writing a small interpreter for a trivial language the details of which are unimportant. However I am looking for the simplest way to avoid having to use playground and Transcript to do something like

| reader eval |
reader := MyReader from: 'some stuff in my DSL'.
eval := MyEvaluator from: reader.
Transcript show: eval evaluate.

I'm tired of having to change 'some stuff in my DSL' to a new expression and run it in playground.

I don't really care which is easier, a Morphic with an input box at the bottom to put my expressions in with output up top, or a something like CommandShellTranscript (which i have looked at but is too complex for me to figure out how to get the desired result from).

Basically I want to be able to use my DSL outside of playground, but still in image. 


A while ago I had success embedding the old Workspace into an application.
Start with...

Workspace subclass: #MyWorkspace
instanceVariableNames: ''
classVariableNames: ''
package: 'Tool-Workspace'

MyWorkspace >> whenTextAccepted: anAnnouncement
"MyWorkspace open"
self inform: anAnnouncement text 

MyWorkspace >> createTextView
| v |
v := super createTextView.
v beForPlainText.
^v.


cheers -ben

Reply | Threaded
Open this post in threaded view
|

Re: Simplest 'REPL'

Tudor Girba-2
In reply to this post by Seth
Hi,

I would encourage you to simply extend the inspector. Something like this:

MyEvaluator>>gtInspectorEvaluateIn: composite
        <gtInspectorPresentationOrder: 0>
        composite text
                title: ‘Evaluator’;
                populate: #selection iconName:#glamorousGo entitled: ‘Evaluate' with: [ :textPresentation |
                        self from: (MyReader from: textPresentation text)]

And then inspect MyEvaluator new.

If you cannot have an evaluator instance without the reader, add the extension to the class side of MyEvaluator and inspect the MyEvaluator class.

Cheers,
Doru



> On Dec 9, 2017, at 12:04 AM, cheshirecatalyst <[hidden email]> wrote:
>
> I've recently picked up pharo, and am writing a small interpreter for a trivial language the details of which are unimportant. However I am looking for the simplest way to avoid having to use playground and Transcript to do something like
>
> | reader eval |
> reader := MyReader from: 'some stuff in my DSL'.
> eval := MyEvaluator from: reader.
> Transcript show: eval evaluate.
>
> I'm tired of having to change 'some stuff in my DSL' to a new expression and run it in playground.
>
> I don't really care which is easier, a Morphic with an input box at the bottom to put my expressions in with output up top, or a something like CommandShellTranscript (which i have looked at but is too complex for me to figure out how to get the desired result from).
>
> Basically I want to be able to use my DSL outside of playground, but still in image.

--
www.tudorgirba.com
www.feenk.com

"Yesterday is a fact.
 Tomorrow is a possibility.
 Today is a challenge."





Reply | Threaded
Open this post in threaded view
|

Re: Simplest 'REPL'

Seth
In reply to this post by Hannes Hirzel
Thanks I ended up going in this direction sort of.



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html