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

Fix postfix if after escaped newline #484

Merged
merged 6 commits into from
Aug 29, 2017
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: 4 additions & 1 deletion lib/rdoc/ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def initialize(content, options)
@indent_stack = []
@lex_state = :EXPR_BEG
@space_seen = false
@escaped_nl = false
@first_in_method_statement = false
@after_question = false

Expand Down Expand Up @@ -504,7 +505,7 @@ def lex_init()
@continue = true
else
@continue = false
@lex_state = :EXPR_BEG
@lex_state = :EXPR_BEG unless @escaped_nl
until (@indent_stack.empty? ||
[TkLPAREN, TkLBRACK, TkLBRACE,
TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
Expand All @@ -515,6 +516,7 @@ def lex_init()
@here_readed.clear
tk = Token(TkNL)
end
@escaped_nl = false
tk
end

Expand Down Expand Up @@ -885,6 +887,7 @@ def lex_int2
if peek(0) == "\n"
@space_seen = true
@continue = true
@escaped_nl = true
end
Token("\\")
end
Expand Down
38 changes: 38 additions & 0 deletions test/test_rdoc_ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,44 @@ def test_class_tokenize_string_with_escape
assert_equal expected, tokens
end

def test_class_tokenize_postfix_if_after_escaped_newline
tokens = RDoc::RubyLex.tokenize <<'RUBY', nil
def a
1 if true
1 \
if true
end
RUBY

expected = [
@TK::TkDEF .new( 0, 1, 0, "def"),
@TK::TkSPACE .new( 3, 1, 3, " "),
@TK::TkIDENTIFIER.new( 4, 1, 4, "a"),
@TK::TkNL .new( 5, 1, 5, "\n"),
@TK::TkSPACE .new( 6, 2, 0, " "),
@TK::TkINTEGER .new( 8, 2, 2, "1"),
@TK::TkSPACE .new( 9, 2, 3, " "),
@TK::TkIF_MOD .new(10, 2, 4, "if"),
@TK::TkSPACE .new(12, 2, 6, " "),
@TK::TkTRUE .new(13, 2, 7, "true"),
@TK::TkNL .new(17, 2, 6, "\n"),
@TK::TkSPACE .new(18, 3, 0, " "),
@TK::TkINTEGER .new(20, 3, 2, "1"),
@TK::TkSPACE .new(21, 3, 3, " "),
@TK::TkBACKSLASH .new(22, 3, 4, "\\"),
@TK::TkNL .new(23, 3, 18, "\n"),
@TK::TkSPACE .new(24, 4, 0, " "),
@TK::TkIF_MOD .new(28, 4, 4, "if"),
@TK::TkSPACE .new(30, 4, 6, " "),
@TK::TkTRUE .new(31, 4, 7, "true"),
@TK::TkNL .new(35, 4, 24, "\n"),
@TK::TkEND .new(36, 5, 0, "end"),
@TK::TkNL .new(39, 5, 36, "\n")
]

assert_equal expected, tokens
end

def test_class_tokenize_backtick_with_escape
tokens = RDoc::RubyLex.tokenize <<'RUBY', nil
[
Expand Down