Ruby parser: support heredocs for block navigation

This commit is contained in:
2026-08-31 13:06:41 +01:00
parent 25f4d8efa8
commit 151817973f
+4 -2
View File
@@ -102,7 +102,7 @@ bool handle_escapes(RubyParser &p, std::vector<Token> *tokens, uint32_t &start,
return false; return false;
}; };
bool handle_heredoc(RubyParser &p, std::vector<Token> *tokens) { bool handle_heredoc(RubyParser &p, std::vector<Token> *tokens, std::vector<ParseEvent> *events) {
uint8_t *heredocs = p.state->heredocs(); uint8_t *heredocs = p.state->heredocs();
uint32_t start = p.i; uint32_t start = p.i;
if (start == 0) { if (start == 0) {
@@ -114,6 +114,7 @@ bool handle_heredoc(RubyParser &p, std::vector<Token> *tokens) {
&& memcmp(p.line.data() + start, heredocs + 1, heredoc_len) == 0) { && memcmp(p.line.data() + start, heredocs + 1, heredoc_len) == 0) {
if (!p.dequeue_doc(heredoc_len)) if (!p.dequeue_doc(heredoc_len))
p.current().state = RubyState::RubyInternalState::NONE; p.current().state = RubyState::RubyInternalState::NONE;
events->push_back(true);
tokens->push_back({p.i, p.len(), Token::Annotation}); tokens->push_back({p.i, p.len(), Token::Annotation});
p.current().flags |= RubyState::RubyInternalState::EXPECTING_EXPRESSION; p.current().flags |= RubyState::RubyInternalState::EXPECTING_EXPRESSION;
return true; return true;
@@ -366,6 +367,7 @@ bool handle_syntax(RubyParser &p, std::vector<Token> *tokens, std::vector<ParseE
return false; return false;
p.current().flags &= ~RubyState::RubyInternalState::EXPECTING_EXPRESSION; p.current().flags &= ~RubyState::RubyInternalState::EXPECTING_EXPRESSION;
if (!delim.empty()) { if (!delim.empty()) {
events->push_back(false);
tokens->push_back({s, p.i + j, Token::Annotation}); tokens->push_back({s, p.i + j, Token::Annotation});
uint8_t header = delim.size(); uint8_t header = delim.size();
if (interpolation) if (interpolation)
@@ -1073,7 +1075,7 @@ void ruby_parse(
} }
if (!p.heredoc_start_line if (!p.heredoc_start_line
&& p.current().state == RubyState::RubyInternalState::HEREDOC) { && p.current().state == RubyState::RubyInternalState::HEREDOC) {
if (handle_heredoc(p, tokens)) if (handle_heredoc(p, tokens, events))
return; return;
else else
continue; continue;