Skip to content

Commit

Permalink
Slight refactoring to share logic between echo -e and $''.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Jan 9, 2018
1 parent c4d7f7d commit 5555e82
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
1 change: 1 addition & 0 deletions core/lexer.py
Expand Up @@ -256,6 +256,7 @@ def Tokens(self, line):
if not matches:
raise AssertionError(
'no match at position %d: %r (%r)' % (pos, line, line[pos]))
# NOTE: Need longest-match semantics to find \377 vs \.
end_pos, tok_type, tok_val = max(matches, key=lambda m: m[0])
yield tok_type, line[pos:end_pos]
pos = end_pos
13 changes: 4 additions & 9 deletions osh/lex.py
Expand Up @@ -405,6 +405,10 @@ def IsKeyword(name):

# Backslash that ends a line. Note '.' doesn't match a newline character.
C('\\\n', Id.Char_Literals),

# e.g. \A is not an escape, and \x doesn't match a hex escape. This could be
# an error.
C('\\', Id.Char_Literals),
]

# Used by ECHO_LEXER in core/builtin.py.
Expand All @@ -415,12 +419,6 @@ def IsKeyword(name):

C(r'\c', Id.Char_Stop),

# e.g. \A -> \A, is not a backslash escape.
# This has to come AFTER the \c and so forth.
#
# This includes embedded \n? Is that possible with echo -e?
R(r'\\.', Id.Char_Literals),

# Backslash that ends the string.
R(r'\\$', Id.Char_Literals),

Expand All @@ -443,9 +441,6 @@ def IsKeyword(name):
# well.
R(r"[^\\'\0]+", Id.Char_Literals),

# e.g. \x doesn't match a hex escape. This could be an error.
C('\\', Id.Char_Literals),

C("'", Id.Right_SingleQuote),

# Backslash that ends the file! Caught by re2c exhaustiveness check. Parser
Expand Down

0 comments on commit 5555e82

Please sign in to comment.