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
5 changes: 5 additions & 0 deletions lib/parser/lexer/literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def initialize(lexer, str_type, delimiter, str_s, heredoc_e = nil, indent = fals
!heredoc?
)

# Also capture delimiter in %w() style literals
unless @heredoc_e or @str_type.include?(delimiter)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parser follows the GitHub style guide, which instructs to never use and and or.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, #end_with? is much more clear in this case.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not only it is more clear, it also fixes a bug :)

  1) Failure:
TestLexer#test_regexp_escape_backslash_terminator [/home/whitequark/parser/test/test_lexer.rb:71]:
%r%blah\%blah%.
Expected: [:tREGEXP_BEG, "%r"]
  Actual: [:tREGEXP_BEG, "%r%"]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed dkubb styleguide, no problem for me to use the GH styleguide here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbj I'm not sure I would've used and or or in a boolean statement either :P

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkubb I remember I nitpicked about this some time :P

@str_type << delimiter
end

emit_start_tok unless @monolithic
end

Expand Down
18 changes: 9 additions & 9 deletions test/test_lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1456,23 +1456,23 @@ def test_regexp_escape_backslash_terminator

def test_regexp_escape_backslash_terminator_meta1
util_lex_token('%r{blah\\}blah}',
:tREGEXP_BEG, "%r",
:tREGEXP_BEG, "%r{",
:tSTRING_CONTENT, "blah\\}blah",
:tSTRING_END, "}",
:tREGEXP_OPT, "")
end

def test_regexp_escape_backslash_terminator_meta2
util_lex_token('%r/blah\\/blah/',
:tREGEXP_BEG, "%r",
:tREGEXP_BEG, "%r/",
:tSTRING_CONTENT, "blah\\/blah",
:tSTRING_END, "/",
:tREGEXP_OPT, "")
end

def test_regexp_escape_backslash_terminator_meta3
util_lex_token('%r/blah\\%blah/',
:tREGEXP_BEG, "%r",
:tREGEXP_BEG, "%r/",
:tSTRING_CONTENT, "blah\\%blah",
:tSTRING_END, "/",
:tREGEXP_OPT, "")
Expand Down Expand Up @@ -1795,7 +1795,7 @@ def test_string_pct_Q

def test_string_pct_W
util_lex_token("%W[s1 s2\ns3]", # TODO: add interpolation to these
:tWORDS_BEG, "%W",
:tWORDS_BEG, "%W[",
:tSTRING_CONTENT, "s1",
:tSPACE, nil,
:tSTRING_CONTENT, "s2",
Expand All @@ -1807,7 +1807,7 @@ def test_string_pct_W

def test_string_pct_W_bs_nl
util_lex_token("%W[s1 \\\ns2]", # TODO: add interpolation to these
:tWORDS_BEG, "%W",
:tWORDS_BEG, "%W[",
:tSTRING_CONTENT, "s1",
:tSPACE, nil,
:tSTRING_CONTENT, "\ns2",
Expand All @@ -1827,7 +1827,7 @@ def test_string_pct_other

def test_string_pct_w
util_bad_token("%w[s1 s2 ",
:tQWORDS_BEG, "%w",
:tQWORDS_BEG, "%w[",
:tSTRING_CONTENT, "s1",
:tSPACE, nil,
:tSTRING_CONTENT, "s2",
Expand All @@ -1836,7 +1836,7 @@ def test_string_pct_w

def test_string_pct_w_bs_nl
util_lex_token("%w[s1 \\\ns2]",
:tQWORDS_BEG, "%w",
:tQWORDS_BEG, "%w[",
:tSTRING_CONTENT, "s1",
:tSPACE, nil,
:tSTRING_CONTENT, "\ns2",
Expand All @@ -1846,7 +1846,7 @@ def test_string_pct_w_bs_nl

def test_string_pct_w_bs_sp
util_lex_token("%w[s\\ 1 s\\ 2]",
:tQWORDS_BEG, "%w",
:tQWORDS_BEG, "%w[",
:tSTRING_CONTENT, "s 1",
:tSPACE, nil,
:tSTRING_CONTENT, "s 2",
Expand All @@ -1856,7 +1856,7 @@ def test_string_pct_w_bs_sp

def test_string_pct_w_tab
util_lex_token("%w[abc\tdef]",
:tQWORDS_BEG, "%w",
:tQWORDS_BEG, "%w[",
:tSTRING_CONTENT, "abc",
:tSPACE, nil,
:tSTRING_CONTENT, "def",
Expand Down