Skip to content

Commit c38cfe8

Browse files
committed
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.
1 parent 108db21 commit c38cfe8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/HLL/Compiler.nqp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class HLL::Compiler does HLL::Backend::Default {
2323
@!stages := nqp::split(' ', 'start parse ast ' ~ $!backend.stages());
2424

2525
# Command options and usage.
26-
@!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'
26+
@!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'
2727
#?if js
2828
~ ' substagestats beautify nqp-runtime=s perl6-runtime=s libpath=s shebang execname=s source-map'
2929
#?endif
@@ -300,7 +300,16 @@ class HLL::Compiler does HLL::Backend::Default {
300300
elsif !@a {
301301
# Is STDIN a TTY display? If so, start the REPL, otherwise, simply
302302
# assume the program to eval is given on STDIN.
303-
$result := stdin().t()
303+
my $force := %adverbs<force-stdin-eval-mode>//'';
304+
my $wants-interactive := $force
305+
?? $force eq 'interactive'
306+
?? 1 !! $force eq 'non-interactive'
307+
?? 0 !! self.panic(
308+
"Unknown STDIN eval mode '$force'. Valid values"
309+
~ " are 'non-interactive' and 'interactive'"
310+
)
311+
!! stdin().t();
312+
$result := $wants-interactive
304313
?? self.interactive(|%adverbs)
305314
!! self.evalfiles('-', |%adverbs);
306315
}

0 commit comments

Comments
 (0)