Skip to content

Commit

Permalink
[fix] osh -n respects --one-pass-parse
Browse files Browse the repository at this point in the history
It's not always on

TODO: I think we can get rid of this flag once we get rid of the Arena.

It's only useful for the "arena invariant", which test/arena.sh tests,
and ysh-ify uses.
  • Loading branch information
Andy C committed Jul 29, 2023
1 parent e3cbbc6 commit 1247046
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 6 additions & 5 deletions core/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,9 @@ def Main(lang, arg_r, environ, login_shell, loader, readline):
if flag.one_pass_parse and not exec_opts.noexec():
raise error.Usage('--one-pass-parse requires noexec (-n)', loc.Missing)

# -n is equivalent to --tool syntax-tree
# flag.tool is '' if nothing is passed
tool_name = 'syntax-tree' if exec_opts.noexec() else flag.tool

# Tools always use one pass parse
one_pass_parse = True if len(tool_name) else flag.one_pass_parse
# Note: osh --tool syntax-tree is like osh -n --one-pass-parse
one_pass_parse = True if len(flag.tool) else flag.one_pass_parse

parse_ctx = parse_lib.ParseContext(arena,
parse_opts,
Expand Down Expand Up @@ -921,6 +918,10 @@ def Main(lang, arg_r, environ, login_shell, loader, readline):
# Tools that use the OSH/YSH parsing mode, etc.
#

# flag.tool is '' if nothing is passed
# osh --tool syntax-tree is equivalent to osh -n --one-pass-parse
tool_name = 'syntax-tree' if exec_opts.noexec() else flag.tool

if len(tool_name):
arena.SaveTokens()

Expand Down
5 changes: 4 additions & 1 deletion frontend/flag_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ def _AddShellOptions(spec):
MAIN_SPEC.LongFlag('--completion-display', ['minimal', 'nice'], default='nice')
# TODO: Add option for YSH prompt style? RHS prompt?

# Don't reparse a[x+1] and ``. Only valid in -n mode.
# $SH -n won't reparse a[x+1] and ``. Note that $SH --tool automatically turns
# it on.
# TODO: Do we only need this for the "arena invariant"? e.g. test/arena.sh I
# think we can REMOVE it if we get rid of the arena.
MAIN_SPEC.LongFlag('--one-pass-parse')

MAIN_SPEC.LongFlag('--print-status') # TODO: Replace with a shell hook
Expand Down

0 comments on commit 1247046

Please sign in to comment.