Permalink
Browse files

Slight refactoring to share logic between echo -e and $''.

  • Loading branch information...
Andy Chu
Andy Chu committed Jan 9, 2018
1 parent c4d7f7d commit 5555e82fa16de5f80060725e3aeb3e2fa87cf331
Showing with 5 additions and 9 deletions.
  1. +1 −0 core/lexer.py
  2. +4 −9 osh/lex.py
View
@@ -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
View
@@ -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.
@@ -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),
@@ -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

0 comments on commit 5555e82

Please sign in to comment.