Skip to content

Commit

Permalink
Fix 2 alias test cases by threading the ParseContext properly.
Browse files Browse the repository at this point in the history
Down to 6 failures now, which are all related to aliasing grammatical
constructs other than SimpleComamand.

Unrealted: removed unused code in bool_parse.py
  • Loading branch information
Andy Chu committed Sep 6, 2018
1 parent 8995c56 commit f52e2a4
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 36 deletions.
2 changes: 0 additions & 2 deletions osh/bool_parse.py
Expand Up @@ -82,7 +82,6 @@ def _NextOne(self, lex_mode=lex_mode_e.DBRACKET):
self.b_kind = LookupKind(self.op_id)
#log('--- word %s', self.cur_word)
#log('op_id %s %s %s', self.op_id, self.b_kind, lex_mode)
return True

def _Next(self, lex_mode=lex_mode_e.DBRACKET):
"""Advance to the next token, skipping newlines.
Expand All @@ -95,7 +94,6 @@ def _Next(self, lex_mode=lex_mode_e.DBRACKET):
self._NextOne(lex_mode=lex_mode)
if self.op_id != Id.Op_Newline:
break
return True

def _LookAhead(self):
n = len(self.words)
Expand Down
3 changes: 1 addition & 2 deletions osh/bool_parse_test.py
Expand Up @@ -41,8 +41,7 @@ def _MakeParser(code_str):
w_parser, _ = parse_ctx.MakeParserForCompletion(code_str + ' ]]', arena)
w_parser._Next(lex_mode_e.DBRACKET) # for tests only
p = bool_parse.BoolParser(w_parser)
if not p._Next():
raise AssertionError
p._Next()
return p


Expand Down
9 changes: 3 additions & 6 deletions osh/cmd_parse.py
Expand Up @@ -257,16 +257,13 @@ class CommandParser(object):
lexer: for lookahead in function def, PushHint of ()
line_reader: for here doc
"""
def __init__(self, parse_ctx, w_parser, lexer_, line_reader, arena, aliases=None):
def __init__(self, parse_ctx, w_parser, lexer_, line_reader, arena=None):
self.parse_ctx = parse_ctx
self.w_parser = w_parser # for normal parsing
self.lexer = lexer_ # for pushing hints, lookahead to (
self.line_reader = line_reader # for here docs
self.arena = arena # for adding here doc and alias spans
if aliases is None:
self.aliases = {}
else:
self.aliases = aliases # aliases to expand at parse time
self.arena = arena or parse_ctx.arena # for adding here doc and alias spans
self.aliases = parse_ctx.aliases # aliases to expand at parse time

self.Reset()

Expand Down
29 changes: 4 additions & 25 deletions osh/parse_lib.py
Expand Up @@ -19,26 +19,6 @@ def InitLexer(s, arena):
return line_reader, lx


# API:
# - MakeParser(reader, arena) - for top level, 'source'
# - eval: MakeParser(StringLineReader(), arena)
# - source: MakeParser(FileLineReader(), arena)
# - MakeParserForCommandSub(line_reader, lexer) -- arena is inside line_reader
# - MakeParserForCompletion(code_str, arena)
# - MakeWordParserForHereDoc(line_reader, arena)
# - MakeWordParserForPlugin(code_str, arena)
#
# TODO:
#
# class ParseState
# def __init__(self):
# self.arena
# self.aliases # need to be threaded through
# self.line_reader
#
# def MakeParser(...)
# def MakeParserForCommandSub(...)
#
# When does line_reader change?
# - here docs
# - aliases
Expand Down Expand Up @@ -69,8 +49,7 @@ def MakeParser(self, line_reader):
line_lexer = lexer.LineLexer(match.MATCHER, '', self.arena)
lx = lexer.Lexer(line_lexer, line_reader)
w_parser = word_parse.WordParser(self, lx, line_reader)
c_parser = cmd_parse.CommandParser(self, w_parser, lx, line_reader, self.arena,
aliases=self.aliases)
c_parser = cmd_parse.CommandParser(self, w_parser, lx, line_reader)
return w_parser, c_parser

def MakeWordParserForHereDoc(self, line_reader):
Expand All @@ -84,8 +63,7 @@ def MakeParserForCommandSub(self, line_reader, lexer):
It's a new instance based on same lexer and arena.
"""
w_parser = word_parse.WordParser(self, lexer, line_reader)
c_parser = cmd_parse.CommandParser(self, w_parser, lexer, line_reader,
self.arena)
c_parser = cmd_parse.CommandParser(self, w_parser, lexer, line_reader)
return c_parser

def MakeWordParserForPlugin(self, code_str, arena):
Expand Down Expand Up @@ -114,7 +92,8 @@ def MakeParserForCompletion(self, code_str, arena):
line_lexer = lexer.LineLexer(match.MATCHER, '', arena) # AtEnd() is true
lx = lexer.Lexer(line_lexer, line_reader)
w_parser = word_parse.WordParser(self, lx, line_reader)
c_parser = cmd_parse.CommandParser(self, w_parser, lx, line_reader, arena)
c_parser = cmd_parse.CommandParser(self, w_parser, lx, line_reader,
arena=arena)
return w_parser, c_parser

# Another parser instantiation:
Expand Down
2 changes: 1 addition & 1 deletion test/spec.sh
Expand Up @@ -232,7 +232,7 @@ blog-other1() {
}

alias() {
sh-spec spec/alias.test.sh --osh-failures-allowed 8 \
sh-spec spec/alias.test.sh --osh-failures-allowed 6 \
${REF_SHELLS[@]} $ZSH $OSH_LIST "$@"
}

Expand Down

0 comments on commit f52e2a4

Please sign in to comment.