Permalink
Browse files

Remove lexer code that supported the previous approach to alias.

Remove some other unused code, and add a comment about another approach
that is more like dash and bash.
  • Loading branch information...
Andy Chu
Andy Chu committed Sep 6, 2018
1 parent 405c32b commit 8b72efa71c5e5ea08d0b5b46c6f0381054763fee
Showing with 11 additions and 30 deletions.
  1. +2 −27 core/lexer.py
  2. +9 −3 osh/cmd_parse.py
View
@@ -146,12 +146,8 @@ def __init__(self, line_lexer, line_reader):
"""
self.line_lexer = line_lexer
self.line_reader = line_reader
self.was_line_cont = False # last token was line continuation?
# TODO: unused?
self.line_id = -1 # Invalid one
self.translation_stack = []
self.buffers = []
def ResetInputObjects(self):
self.line_lexer.Reset('', -1, 0)
@@ -194,7 +190,7 @@ def PushHint(self, old_id, new_id):
"""
self.translation_stack.append((old_id, new_id))
def _ReadNormalInput(self, lex_mode):
def _Read(self, lex_mode):
"""Read from the normal line buffer, not an alias."""
t = self.line_lexer.Read(lex_mode)
if t.id == Id.Eol_Tok: # hit \0, read a new line
@@ -218,34 +214,13 @@ def _ReadNormalInput(self, lex_mode):
return t
# 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:
if 0:
log('Reading from %r at %d',
self.buffers[-1].line, self.buffers[-1].line_pos)
t = self.buffers[-1].Read(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
t = self._ReadNormalInput(lex_mode)
self.was_line_cont = (t.id == Id.Ignored_LineCont)
t = self._Read(lex_mode)
# TODO: Change to ALL IGNORED types, once you have SPACE_TOK. This means
# we don't have to handle them in the VS_1/VS_2/etc. states.
if t.id != Id.Ignored_LineCont:
break
#log('Read() Returning %s', t)
return t
def PushAliasBuffer(self, line_lexer):
"""Read from this stack of buffer before resuming normal input."""
self.buffers.append(line_lexer)
View
@@ -292,10 +292,7 @@ def ResetInputObjects(self):
"""Reset the internal state of our inputs.
Called by the interactive loop.
TODO: Should we just make new objects on every iteration?
"""
# All the stuff we read from
self.w_parser.Reset()
self.lexer.ResetInputObjects()
self.line_reader.Reset()
@@ -306,6 +303,15 @@ def Error(self):
def GetCompletionState(self):
return self.completion_stack
# NOTE: If our approach to _ExpandAliases isn't sufficient, we could have an
# expand_alias=True flag here? We would litter the parser with calls to this
# like dash and bash.
#
# Although it might be possible that you really need to mutate the parser
# state, and not just provide a parameter to _Next().
# You might also need a flag to indicate whether the previous expansion ends
# with ' '. I didn't see that in dash or bash code.
def _Next(self, lex_mode=lex_mode_e.OUTER):
"""Helper method."""
self.next_lex_mode = lex_mode

0 comments on commit 8b72efa

Please sign in to comment.