-
Notifications
You must be signed in to change notification settings - Fork 106
stdin #95
Comments
Looking at the sources, the filename argument is mandatory, and there is no syntax for accepting stdin. |
I also checked the sources, and it looks like the gsl is always trying to find the filename of the script using a set of rules. Is this a shortcoming that the rules are not relaxed for accepting stdin, or this is required by design? I can prepare a pull request at some point to fix this if there are no objections. |
Having a console/REPL way of working would be fun, indeed. On Sat, May 9, 2015 at 1:19 PM, Serge Aleynikov [email protected]
|
Since the use of the if (is_stdin)
{
char
*line = NULL;
size_t
len = 0;
THREAD
*gthr = gsl_start(thread-> queue, 0, switches, 1, & root);
while (getline(&line, &len, stdin) >= 0) {
RESULT_NODE *new_node = new_result_node();
gsl_evaluate(gthr, line, 0, &new_node, thread-> queue);
destroy_result(new_node);
}
gsl_finish(gthr);
break;
}
else
gsl_execute (thread-> queue, 0, switches,
1, & root); Insertion of this code along with allowing the use of "/dev/stdin" results in the input being evaluated but doesn't print evaluation result:
I checked the content pointed to by |
Thanks! The more I play with gsl the more useful it seems to be. :-) Having a functional top-level console evaluation loop for gsl would be quite helpful. Though I have a wish for a few more syntactic features:
|
These are neat ideas. One warning on using gsl: if you're good with abstractions, it rapidly takes you places where other people can't easily follow. This can be counter-productive, if you want to make software that others can contribute to. |
I agree that current gsl imperative syntax is straight-forward to learn. Though given the fact that most of the modern languages nowadays include some functional features, I should say that people are not as scared about lambdas as they were a few years back. |
For sure! We merge all patches so long as they don't break existing code. On Sat, May 9, 2015 at 7:54 PM, Serge Aleynikov [email protected]
|
Just to get back on the original "stdin" issue, I pushed an experimental branch that you or @jschultz can take a look at: https://github.com/saleyn/gsl/tree/stdin (compare: master...saleyn:stdin) as the starting point where I left it off with the comments above. |
I'll try to find take a look at the stdin issue in the next few weeks. One difficulty might that gsl parses scripts by reading a file until the
This idea has been discussed in the past and rejected on the basis that
I presume these two go together, as I can't see any purpose for an
|
@jschultz thank you for taking the time to look into this.
In the defense of the ';' proposal, in the template mode it is quite frequent to have a one-liner assignment or function call surrounded by the 'if/ifend' pair. in those cases it would be more succinct to be able to put that on one line.
After looking through the source of gsl I can see that it is not trivial to make gsl grammar changes. I wonder why in its design some common parser/lexer wasn't used (e.g. yacc or its analog) with a BNF-like grammar? It seems to me that gsl 5.0 could very well be implemented on top of some common runtime that addresses many things that gsl does (such as multi-threaded concurrent job control, etc). Erlang seems to be a good fit for it as it handles concurrency out of the box, is cross-platform, has yacc-like parser, XML support, etc. All it would take would be to write a BNF grammar for gsl syntax, and an Erlang expression evaluator... |
I think we started GSL in 1991 or so, and the focus was always on fitting the job of code generation. We experimented with it as a general purpose scripting language (e.g. for web page generation and server scripting) but that was pointless given other languages much better at that. We're still making small improvements to it, and this is how we like to work: solve clear and obvious problems with minimal patches. In terms of future code generators, I think one should revisit the question. For simple procedural code generation, GSL is unbeatable. However for serious use, grammar-based code generation is far more effective. We did that in 2005 with XNF, a generator generator driven by XML grammars. This is where new languages would be profitable. |
I think I asked this before, but the situation might have changed: Is XNF publicly available somewhere? I remember, that you told me it is to complicated for normal people. ;-) Any plans to change that? |
Yes, there's a git repo with the entire stack we used to build OpenAMQ, https://github.com/imatix/openamq/tree/master/tooling/base2 On Tue, May 12, 2015 at 9:15 AM, Achim [email protected] wrote:
|
Certainly using tools like yacc and Erlang have long seemed to me like Cheers, |
It seems to me that the complication of having template/script context can be reduced to having a context-free grammar if at the stage of the lexer it treats a whole template block as a blob of text, while working in the script mode, and at the parsing stage would apply a secondary-level lexer to the template text in order to being able to detect $(...) expressions. A better approach would be to define a grammar for a stateful lexer, so that it's able to switch between the template/script states. There are some Erlang projects available for implementing advanced stateful lexers, e.g.: Though my plate is quite full for the next few months, but thereafter I could offer some help if there is interest in trying this approach. |
This is all no doubt possible, but the fact of having to think about Cheers, On 13/05/15 23:23, Serge Aleynikov wrote:
|
One thing that's hard not to agree with is that gsl does what it's designed to do quite well. :-) |
Is there a simple way to have gsl read from stdin instead of a given script file? If so, could you please document it?
I understand that I can use the workaround below to open stdin device and read from it:
This doesn't seem to work either:
The text was updated successfully, but these errors were encountered: