What is the "Use Case" of REPL Command argument(s) getting executed?

35 views
Skip to first unread message

Collin Bennett

unread,
May 11, 2015, 6:43:39 PM5/11/15
to scri...@googlegroups.com
I have been focusing on the IReplCommand objects in the source.  From what I understand, Repl.cs treats any line that starts with a colon as an indication we want to execute a command.  Therefore any argument should be passed the IReplCommand Execute method processing. 

What I have notice, is that all arguments of the command gets executed. In the example of my screen shot, the argument is treated like as a variable and gets evaluated.  What is the "Use Case" for such evaluation?

Right now by design, any arguments that is quoted, doesn't get evaluated; therefore it's becomes a true argument of the command.  I believe getting rid of the evaluation would allow expansion of the IReplCommand.

What does anyone thinks?




Adam Ralph

unread,
May 12, 2015, 2:12:50 AM5/12/15
to scri...@googlegroups.com
The use case is exactly what you demonstrate. I can build a path in a variable
foo

and then
:cd foo
Message has been deleted

Collin Bennett

unread,
May 12, 2015, 7:42:54 AM5/12/15
to scri...@googlegroups.com
Ok. Let's take a clue from bash in how they deal with shell variables: $.

var foo = "wipe";
:alias clear $foo



Any argument prefix with a $ would then get evaluated.

I think the above style reads and types better than using quotes.

:alias "clear" foo
:alias "clear" "wipe"



Adam Ralph

unread,
May 13, 2015, 2:25:42 AM5/13/15
to scri...@googlegroups.com
What about:

:cd string.Format(@"\\{0}\{1}\{2}, server, share, path)

of even just

:cd foo + bar

Granted you could write the second example in your suggested syntax as

:cd $foo + $bar

but where does the '+' operator come from? We don't want to write another language parser for REPL command evaluation.

Ultimately bash has it's own syntax, C# has another.

Collin Bennett

unread,
May 13, 2015, 11:57:48 AM5/13/15
to scri...@googlegroups.com
Right now, the parser for the REPL command is very limited.  I would like the opportunity to make such improvements.  Any features that I am talking about, I am going to write it.  I want to focus on the development of the REPL interface. 

So currently the REPL command logic executes all arguments one by one. 

What I am currently proposing is only the arguments that begins with $ get evaluated by the ScriptEngine. 

Would this change be considered a breaking API?

Filip W

unread,
May 13, 2015, 12:10:05 PM5/13/15
to Collin Bennett, scri...@googlegroups.com
what do you find limiting about it? you can do really elaborate operations, for example:

> string GetPath(Assembly assembly) {
* var uri = new Uri(assembly.CodeBase);
* return Path.GetDirectoryName(uri.LocalPath);
* }
> var mscorlib = typeof(object).Assembly;
> :cd GetPath(mscorlib)
> :cwd
C:\Windows\Microsoft.NET\Framework64\v4.0.30319
>

I don't like the idea of introducing $ tokens for the very reasons Adam mentioned.

Collin Bennett

unread,
May 13, 2015, 1:27:00 PM5/13/15
to scri...@googlegroups.com, black...@gmail.com
Limited in the sense that the arguments are split with a simple whitespace.  

For example - long file names:

> :cd "\\Foo Bar"

System.Exception: Argument is not a valid expression: "\\Foo
   at ScriptCs.Repl.Execute(String script, String[] scriptArgs) in C:\GitHub\scr
iptcs\src\ScriptCs.Core\Repl.cs:line 91

>

I will create a PR that keeps quoted arguments together.  And we can visit the $ token later when I have a better "Use Case".
Reply all
Reply to author
Forward
0 new messages