Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
slash and the expansion is followed by a slash, the trailing slash
in the directory name is now removed to maintain the correct
number of slashes.
- The syntax for specifying a file descriptor with a variable name in
braces before a redirection operator is now reserved for future
implementation. The syntax is now treated as a syntax error.
- [line-editing] Updated the completion scripts to support Git
2.48.1.
- [line-editing] Added the completion script for `git-mv`.
Expand Down
3 changes: 3 additions & 0 deletions NEWS.ja
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
- チルダ展開がスラッシュで終わるディレクトリ名を生成し、その展開の
後にスラッシュが続く場合、ディレクトリ名の末尾のスラッシュを削除
することでスラッシュの数が正しく維持されるようになった
- リダイレクト演算子の前に中括弧で囲んだ変数名でファイル記述子を指定
する構文を、将来の実装のために予約した。この構文は今後は構文エラーと
なる
- [行編集] 補完スクリプトを Git 2.48.1 相当に更新
- [行編集] git-mv の補完を追加
- [行編集] cd と pushd の補完で、補完候補となるディレクトリ名を探す
Expand Down
2 changes: 2 additions & 0 deletions doc/ja/redir.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ dfn:[リダイレクト]はコマンドのファイル記述子を変更する

リダイレクト演算子は、+<+ または +>+ で始まります。+<+ で始まるリダイレクト演算子はデフォルトでは標準入力 (ファイル記述子 0) に作用します。+>+ で始まるリダイレクト演算子はデフォルトでは標準出力 (ファイル記述子 1) に作用します。どちらの種類の演算子でも、演算子の直前に非負整数を指定することでデフォルト以外のファイル記述子に作用させることができます (このとき整数と演算子との間に一切空白などを入れてはいけません。また整数を{zwsp}link:syntax.html#quotes[クォート]してもいけません)。

リダイレクト演算子の直前に置かれた +{{{名前}}}+ の形式のトークンは、将来の拡張のために予約されています。現在のところ、このようなトークンは構文エラーになります。

[[file]]
== ファイルへのリダイレクト

Expand Down
4 changes: 4 additions & 0 deletions doc/redir.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ by the integer.
The integer must immediately precede the +<+ or +>+ without any whitespaces
in between. The integer must not be link:syntax.html#quotes[quoted], either.

Words of the form +&#x7B;{{name}}&#x7D;+ that immediately precede a
redirection operator are reserved for future use.
Currently, they cause a syntax error if used.

[[file]]
== Redirection to files

Expand Down
27 changes: 20 additions & 7 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ typedef enum tokentype_T {
TT_UNKNOWN,
TT_END_OF_INPUT,
TT_WORD,
TT_IO_NUMBER,
TT_IO_NUMBER, TT_IO_LOCATION,
/* operators */
TT_NEWLINE,
TT_AMP, TT_AMPAMP, TT_LPAREN, TT_RPAREN, TT_SEMICOLON, TT_DOUBLE_SEMICOLON,
Expand Down Expand Up @@ -1141,21 +1141,26 @@ void next_token(parsestate_T *ps)

default:
/* Okay, the next token seems to be a word, possibly being a
* reserved word or an IO_NUMBER token. */
* reserved word or an IO_NUMBER or IO_LOCATION token. */
ps->index = index;
wordunit_T *token = parse_word(ps, is_token_delimiter_char);
index = ps->index;

wordfree(ps->token);
ps->token = token;

/* Is this an IO_NUMBER token? */
/* Is this an IO_NUMBER or IO_LOCATION token? */
if (ps->src.contents[index] == L'<' ||
ps->src.contents[index] == L'>') {
if (is_digits_only(ps->token)) {
ps->tokentype = TT_IO_NUMBER;
break;
}
if (ps->src.contents[startindex] == L'{' &&
ps->src.contents[index - 1] == L'}') {
ps->tokentype = TT_IO_LOCATION;
break;
}
}

/* Is this a reserved word? */
Expand Down Expand Up @@ -1831,12 +1836,12 @@ bool is_closing_brace(wchar_t c)

/* Performs alias substitution with the given parse state. Proceeds to the
* next token if substitution occurred. This function does not substitute an
* IO_NUMBER token, but do a keyword token. */
* IO_NUMBER or IO_LOCATION token, but do a keyword token. */
bool psubstitute_alias(parsestate_T *ps, substaliasflags_T flags)
{
if (!ps->enable_alias)
return false;
if (ps->tokentype == TT_IO_NUMBER)
if (ps->tokentype == TT_IO_NUMBER || ps->tokentype == TT_IO_LOCATION)
return false;
if (!is_single_string_word(ps->token))
return false;
Expand Down Expand Up @@ -2262,6 +2267,12 @@ redir_T *tryparse_redirect(parsestate_T *ps)
{
int fd;

if (ps->tokentype == TT_IO_LOCATION) {
serror(ps,
Ngt("specifying file descriptor in braces is not supported"));
next_token(ps);
}

if (ps->tokentype == TT_IO_NUMBER) {
unsigned long lfd;
wchar_t *endptr;
Expand Down Expand Up @@ -2375,11 +2386,13 @@ redir_T *tryparse_redirect(parsestate_T *ps)
}

/* Performs alias substitution on the current token.
* Rejects the current token if it is an IO_NUMBER token. */
* Rejects the current token if it is an IO_NUMBER or IO_LOCATION token. */
void validate_redir_operand(parsestate_T *ps)
{
do {
if (posixly_correct && ps->tokentype == TT_IO_NUMBER) {
if (posixly_correct &&
(ps->tokentype == TT_IO_NUMBER ||
ps->tokentype == TT_IO_LOCATION)) {
assert(ps->next_index > 0);
serror(ps, Ngt("put a space between `%lc' and `%lc' "
"for disambiguation"),
Expand Down
18 changes: 18 additions & 0 deletions tests/redir-y.tst
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,26 @@ __ERR__
#`
#'
#`

test_Oe -e 2 'IO_LOCATION as redirection operand (filename)'
# Here the token "{n}" is an IO_LOCATION token for the second redirection, and
# hence cannot be the operand of the first.
> {n}> foo
__IN__
syntax error: put a space between `}' and `>' for disambiguation
__ERR__
#'
#`
#'
#`
)

test_Oe -e 2 'IO_LOCATION not yet supported'
{n}> foo
__IN__
syntax error: specifying file descriptor in braces is not supported
__ERR__

test_Oe -e 2 'missing target for <'
<
__IN__
Expand Down