Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement --force-stdin-eval-mode command line arg
- Takes 'interactive' and 'non-interactive' as valid values
- Provides the means to switch between REPL and plain eval STDIN
    without depending on whether STDIN is a TTY or not. At the
    very least, this lets us easily write REPL tests.
  • Loading branch information
zoffixznet committed Oct 7, 2017
1 parent 108db21 commit c38cfe8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/HLL/Compiler.nqp
Expand Up @@ -23,7 +23,7 @@ class HLL::Compiler does HLL::Backend::Default {
@!stages := nqp::split(' ', 'start parse ast ' ~ $!backend.stages());

# Command options and usage.
@!cmdoptions := nqp::split(' ', 'e=s help|h target=s trace|t=s encoding=s output|o=s source-name=s combine version|v show-config verbose-config|V stagestats=s? ll-exception rxtrace nqpevent=s profile=s? profile-compile=s? profile-filename=s profile-stage=s'
@!cmdoptions := nqp::split(' ', 'e=s help|h target=s trace|t=s encoding=s output|o=s source-name=s combine version|v show-config verbose-config|V stagestats=s? ll-exception rxtrace nqpevent=s profile=s? profile-compile=s? profile-filename=s profile-stage=s force-stdin-eval-mode=s'
#?if js
~ ' substagestats beautify nqp-runtime=s perl6-runtime=s libpath=s shebang execname=s source-map'
#?endif
Expand Down Expand Up @@ -300,7 +300,16 @@ class HLL::Compiler does HLL::Backend::Default {
elsif !@a {
# Is STDIN a TTY display? If so, start the REPL, otherwise, simply
# assume the program to eval is given on STDIN.
$result := stdin().t()
my $force := %adverbs<force-stdin-eval-mode>//'';
my $wants-interactive := $force
?? $force eq 'interactive'
?? 1 !! $force eq 'non-interactive'
?? 0 !! self.panic(
"Unknown STDIN eval mode '$force'. Valid values"
~ " are 'non-interactive' and 'interactive'"
)
!! stdin().t();
$result := $wants-interactive
?? self.interactive(|%adverbs)
!! self.evalfiles('-', |%adverbs);
}
Expand Down

0 comments on commit c38cfe8

Please sign in to comment.