Skip to content

Commit

Permalink
Fix unit tests and spec tests after last commit.
Browse files Browse the repository at this point in the history
The GetLineSourceString() change exposed the fact that some location
fields weren't filled in.
  • Loading branch information
Andy Chu committed Apr 23, 2019
1 parent ffa3322 commit f67e470
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bin/oil.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def ShellMain(lang, argv0, argv, login_shell):
bool_ev = expr_eval.BoolEvaluator(mem, exec_opts, word_ev, arena)
exec_deps.bool_ev = bool_ev

tracer = cmd_exec.Tracer(parse_ctx, exec_opts, mem, word_ev, trace_f)
tracer = dev.Tracer(parse_ctx, exec_opts, mem, word_ev, trace_f)
exec_deps.tracer = tracer

# HACK for circular deps
Expand Down
5 changes: 1 addition & 4 deletions core/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from asdl import const
from asdl import pretty
from core import alloc
from core import util
from core.util import log
from osh import word
Expand Down Expand Up @@ -168,9 +167,7 @@ def __init__(self, parse_ctx, exec_opts, mem, word_ev, f):
self.word_ev = word_ev
self.f = f # can be the --debug-file as well

# NOTE: We could use the same arena, since this doesn't happen during
# translation.
self.arena = alloc.SideArena('<$PS4>')
self.arena = parse_ctx.arena
self.parse_cache = {} # PS4 value -> CompoundWord. PS4 is scoped.

def _EvalPS4(self):
Expand Down
2 changes: 1 addition & 1 deletion core/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def InitExecutor(parse_ctx=None, comp_lookup=None, arena=None, mem=None):
bool_ev = expr_eval.BoolEvaluator(mem, exec_opts, word_ev, arena)
exec_deps.bool_ev = bool_ev

tracer = cmd_exec.Tracer(parse_ctx, exec_opts, mem, word_ev, debug_f)
tracer = dev.Tracer(parse_ctx, exec_opts, mem, word_ev, debug_f)
exec_deps.tracer = tracer

ex = cmd_exec.Executor(mem, fd_state, funcs, builtins, exec_opts,
Expand Down
16 changes: 9 additions & 7 deletions frontend/syntax.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ module syntax
-- clear where they come from.
| Variable(extent assigned) -- $PS1, $PS4, etc.
-- where the variable was last assigned
-- 3 instances of reparsing:

-- 3 instances of reparsing:
| Alias(string argv0, extent argv0_loc)
-- alias expansion (location of first word)
| Backticks(extent loc) -- reparsing in echo `echo \"hi\"`
-- (area between ` and ` )
| LValue(extent loc) -- reparsing of x+1 in a[x+1]=y
-- (area between [ and ] )
-- alias expansion (location of first word)
| Alias(string argv0, int argv0_spid)

-- reparsing in echo `echo \"hi\"`
| Backticks(int left_spid, int right_spid)

-- reparsing of x+1 in a[x+1]=y
| LValue(int left_spid, int right_spid)

-- A temporary value that's NOT stored in the LST. It's the beginning or end
-- of a line_span / extent.
Expand Down
5 changes: 2 additions & 3 deletions osh/cmd_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,8 @@ def _MaybeExpandAliases(self, words):
# through CommandParser instances.
aliases_in_flight = self.aliases_in_flight or []

# The last char that we might parse.
right_spid = word.RightMostSpanForWord(words[-1])
first_word_str = None # for error message
argv0_spid = word.LeftMostSpanForWord(words[0])

expanded = []
i = 0
Expand Down Expand Up @@ -731,7 +730,7 @@ def _MaybeExpandAliases(self, words):
# See docstring of BeginAliasExpansion() in parse_lib.py.

extent = None # TODO: GetLineNumber / GetLineSource for current span_id?
self.arena.PushSource(source.Alias(first_word_str, extent))
self.arena.PushSource(source.Alias(first_word_str, argv0_spid))
trail = self.parse_ctx.trail
trail.BeginAliasExpansion()
try:
Expand Down
12 changes: 5 additions & 7 deletions osh/word_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,15 +750,13 @@ def _ReadCommandSubPart(self, left_id):
code_str = ''.join(parts)
#log('code %r', code_str)

# NOTE: This is similar to how we parse aliases in osh/cmd_parse.py.
# It won't have the same location info as MakeParserForCommandSub(),
# because the lexer is different.
# NOTE: This is similar to how we parse aliases in osh/cmd_parse.py. It
# won't have the same location info as MakeParserForCommandSub(), because
# the lexer is different.
arena = self.parse_ctx.arena
extent = None # TODO: GetLineNumber
arena.PushSource(source.Backticks(extent))

line_reader = reader.StringLineReader(code_str, self.parse_ctx.arena)
line_reader = reader.StringLineReader(code_str, arena)
c_parser = self.parse_ctx.MakeOshParser(line_reader)
arena.PushSource(source.Backticks(left_spid, right_spid))
try:
node = c_parser.ParseCommandSub()
finally:
Expand Down

0 comments on commit f67e470

Please sign in to comment.