ReadLine method

Developer
Apr 23, 2012 at 10:59 AM

Hi Roman,

I'm working on a console for GrammarExplorer.
Console will support both WriteLine and ReadLine methods for grammar samples.

Where should I put ReadLine() method implementation?
Looks like it should be in ScriptApp, am I right?

Coordinator
Apr 23, 2012 at 6:17 PM

Look at CommandLine.cs class - it uses IConsoleAdaptor interface. You should create ConsoleAdapter class for your console control (or make the control itself implement the interface). Not sure I understand the question, that's as far as I can guess.

Developer
Apr 23, 2012 at 8:09 PM
Edited Apr 23, 2012 at 8:10 PM
rivantsov wrote:

Not sure I understand the question, that's as far as I can guess.

Sorry for being not quite clear.

I'd like to extend the "Run grammar sample" feature of the GrammarExplorer.
The current implementation of InterpretedLanguageGrammar.RunSample can only write text, but cannot read user input.
RunSample method creates a ScriptApp instance, calls _app.Evaluate() and returns _app.OutputBuffer.
To enable ReadLine operation, I should pass my IConsoleAdaptor implementation, right?

I'm going to do it like this:
1. Extend RunSampleArgs class, add IConsoleAdaptor parameter.
2. Extend ScriptApp class, add IConsoleAdaptor property (say, Console).
3. AstNode will be able to use ScriptThread.App.Console.ReadLine/WriteLine methods.

It is the right way to do things?

Coordinator
Apr 24, 2012 at 7:42 AM

Keep in mind that supporting console mode (REPL) is optional, even if evaluation is supported. Like SearchGrammar - you can evaluate input query (and produce converted SQL) but it does not make much sense to start REPL session.

So grammar must somehow indicate that it supports REPL/console, and secondly, create and return the ComandLine instance. Not sure how to do it most intuitively. One option is to extend (and rename) ICanRunSample interface, to allow it to a) create full-blown interactive console, and/or b) provide one-time evaluation of the script in the editor panel.

Any ideas? everybody?

Developer
Apr 24, 2012 at 9:37 AM
Edited Apr 24, 2012 at 4:43 PM
rivantsov wrote:

Keep in mind that supporting console mode (REPL) is optional, even if evaluation is supported. Like SearchGrammar - you can evaluate input query (and produce converted SQL) but it does not make much sense to start REPL session.

I'm not currently speaking about REPL, it's another thing. Consider the following grammar sample:

  WriteLine("Type in yor name: ");
  Name = ReadLine();
  WriteLine("Hello, ", Name, "!");

Think of it as a console application that uses IConsoleAdaptor (ScriptApp.Console property) for I/O.
When executed by the GrammarExplorer, these operations are performed by ConsoleTextBox.
In the CommandLine app, they are directed to a native system console.

I propose to extend ICanRunSample in a way that it supports both I/O directions,
so the GrammarExplorer can run samples like the above.

Supporting REPL would be another task.

rivantsov wrote:

So grammar must somehow indicate that it supports REPL/console, and secondly, create and return the ComandLine instance.

I think that the console should be provided by the application, not by the grammar.

When we run console application, the window is created for us by the operating system —
we use STDIN/STDOUT and don't care whether it's a real console window or a file.

rivantsov wrote:

One option is to extend (and rename) ICanRunSample interface, to allow it to a) create full-blown interactive console, and/or b) provide one-time evaluation of the script in the editor panel.

Looks like it should be two different interfaces :)
ICanRunSample supports one-time evaluation, and, say ICanRunREPL supports interactive console.

Coordinator
Apr 24, 2012 at 5:39 PM

ok then, agree with your prev proposal, to add console adaptor to ScriptApp

Developer
Apr 26, 2012 at 12:39 AM
Edited Apr 26, 2012 at 1:31 AM

Hi Roman,

I've created a project Irony.WinForms that contains two text box controls: IronyTextBox and ConsoleTextBox.
IronyTextBox supports syntax highlighting (Language property should be set to some LanguageData).
ConsoleTextBox is an implementation of IConsoleAdaptor.

GrammarExplorer now uses both controls: IronyTextBox for code snippets and ConsoleTextBox for runtime output.

I've modified a Refal program arith.ref (simple expression translator) to read input expressions from a console.
It's basically a read-evaluate-print loop run by interpreted grammar sample:

Irony GrammarExplorer Console sample running Refal expression translator

Other samples — wiki, sql, expression evaluator — work as usual.

I didn't push my changes to the main repo yet.
I'll be unavailable for about two weeks, so I suppose it's better to wait until I'm back and ready for bug fixing :)

Coordinator
Apr 26, 2012 at 1:17 PM

that's great, thanks! will look at it

Roman