Project

General

Profile

Actions

Bug #19544

closed

Custom quotes inconsistency

Added by hurricup (Alexandr Evstigneev) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:112988]

Description

According to parse_percent in parse.y:

For % we should be able use ascii non alphanumeric delimiters.
But, p % jim beam ; does not work. Presumably because of some look-ahead distincting % from percent-string starter. Seems it is the same for any \s after %

For the explicit % construction, with type specifier %[QqWwIisrx] we should be able to use non-alphanumeric ascii characters, which includes \s. But:
This works:

p %s
jim beam

And this does not:

p %w
jim\ beam

with unterminated list error.

First seems unavoidable, but second looks like obvious error of finding terminating \n


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #19563: Ripper.tokenize(code).join != code when heredoc and multiline %w[] literal is on the same lineClosedActions

Updated by mame (Yusuke Endoh) over 1 year ago

Presumably because of some look-ahead distincting % from percent-string starter

It depends on the lex state, not look-ahead. If you place % in a context where the beginning of an expression is expected, you can write %-literal with spaces as delimiters.

p(% foo )       #=> "foo"
p(% jim\ beam ) #=> "jim beam"

%w cannot be used with a space delimiter because it interprets all whitespace characters as a word delimiter.

Updated by hurricup (Alexandr Evstigneev) over 1 year ago

mame (Yusuke Endoh) wrote in #note-1:

Presumably because of some look-ahead distincting % from percent-string starter

It depends on the lex state, not look-ahead. If you place % in a context where the beginning of an expression is expected, you can write %-literal with spaces as delimiters.

p(% foo )       #=> "foo"
p(% jim\ beam ) #=> "jim beam"

%w cannot be used with a space delimiter because it interprets all whitespace characters as a word delimiter.

Thank you! This sounds reasonable. Then feels that list-like quotations ops [WwIi] should error about \s term, not unterminated list, which may be confusing.

Updated by hurricup (Alexandr Evstigneev) over 1 year ago

mame (Yusuke Endoh) wrote in #note-1:

%w cannot be used with a space delimiter because it interprets all whitespace characters as a word delimiter.

Also, it could be usable, because space may be used as delimiter and \n as word separator and vice versa.

Actions #4

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Related to Bug #19563: Ripper.tokenize(code).join != code when heredoc and multiline %w[] literal is on the same line added

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like1Like0Like0Like0Like0