Permalink
Browse files

A different approach to implementing alias.

The previous approach of PushAliasBuffer() only worked for a single
alias expansion.  Iteration was a problem.

Now we hook into ParseSimpleCommand and expand aliases iteratively.
We join the expanded aliases with the rest of the *text* from the
SimpleCommand, and then pass that into ParseCommand().

I made some comments about the cases that this doesn't handle.  And also
some notes about how dash and bash do it -- with global variables strewn
throughout the parser.

(Although I wonder if we could do that with self._Next() ? )

- Add more alias test cases
- Factor some free functions out of CommandParser.

All unit, spec, and gold tests pass.
  • Loading branch information...
Andy Chu
Andy Chu committed Sep 4, 2018
1 parent 4cdae03 commit 405c32b155b2d24ee97adeda06cf36bb4842d0b8
Showing with 457 additions and 204 deletions.
  1. +5 −1 core/lexer.py
  2. +282 −163 osh/cmd_parse.py
  3. +5 −1 osh/cmd_parse_test.py
  4. +33 −13 osh/parse_lib.py
  5. +131 −25 spec/alias.test.sh
  6. +1 −1 test/spec.sh
View
@@ -38,6 +38,10 @@ def __init__(self, match_func, line, arena):
self.Reset(line, -1, 0) # Invalid line_id to start
def __repr__(self):
return '<LineLexer at pos %d of line %r (id = %d)>' % (
self.line_pos, self.line, self.line_id)
def Reset(self, line, line_id, line_pos):
#assert line, repr(line) # can't be empty or None
self.line = line
@@ -216,6 +220,7 @@ def _ReadNormalInput(self, lex_mode):
# TODO: Collapse newlines here instead of in the WordParser?
def Read(self, lex_mode):
# TODO: Remove this whole section
while True:
# Read from alias buffers first
if self.buffers:
@@ -226,7 +231,6 @@ def Read(self, lex_mode):
if t.id == Id.Eol_Tok:
self.buffers.pop()
continue # read from next buffer or from the original line_Lexer
# TODO: Translate tokens here?
return t
Oops, something went wrong.

0 comments on commit 405c32b

Please sign in to comment.