Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

word_parse.py: parse_backslash (errors + hinting questions) #1824

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions osh/word_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def ReadSingleQuoted(self, lex_mode, left_token, tokens, is_ysh_expr):

# x = $'\z' is disallowed; ditto for echo $'\z' if shopt -u parse_backslash
if is_ysh_expr or not self.parse_opts.parse_backslash():
p_die("Invalid char escape in C-style string literal", tok)
p_die("Invalid char escape in C-style $'-string literal (parse_backslash, no verbatims)\n\t* use \\\\ to denote a \\ ?\n\t* 'chain'\"different\"$'literals' ?\n\t* (ysh) use u'- or b'-literal instead ?\n\t* (ysh) concat r'- ++ u'- or b'-literals ?", tok)

tokens.append(tok)

Expand Down Expand Up @@ -944,7 +944,7 @@ def _ReadLikeDQ(self, left_token, is_ysh_expr, out_parts):
if (is_ysh_expr or
not self.parse_opts.parse_backslash()):
p_die(
"Invalid char escape in double quoted string",
"Invalid char escape in \"-string literal (parse_backslash, no verbatims)\n\tAllowed: \\\", \\$, or \\\\ to denote \", $, or \\\n\t* use \\\\ to denote a \\ ?\n\t* 'chain'\"different\"$'literals' ?\n\t* (ysh) concat \"- ++ u'- or b'-literals ?",
self.cur_token)
elif self.token_type == Id.Lit_Dollar:
if is_ysh_expr or not self.parse_opts.parse_dollar():
Expand Down Expand Up @@ -1611,7 +1611,7 @@ def _MaybeReadWordPart(self, is_first, lex_mode, parts):
ch = lexer.TokenSliceLeft(tok, 1)
if not self.parse_opts.parse_backslash():
if not pyutil.IsValidCharEscape(ch):
p_die('Invalid char escape (parse_backslash)',
p_die("Invalid char escape (parse_backslash, no verbatims, no quotings)\n\t* remove \ ?\n\t* use \\\\ to denote a \\ ?\n\t* use \"raw\" '-string-literal ?\n\t* use \"interpreted\" $'-string-literal ?\n\t* (ysh) use \"raw\" r'-string-literal ?\n\t* (ysh) use \"interpreted\" u'- or b'-string-literal ?",
self.cur_token)

part = word_part.EscapedLiteral(self.cur_token,
Expand Down
Loading