Improve ruby parsing heuristics.

This commit is contained in:
2026-08-21 12:28:16 +01:00
parent 6ea03d651a
commit 739d2e450e
6 changed files with 82 additions and 84 deletions
+3 -2
View File
@@ -10,6 +10,7 @@ struct RubyParser {
std::string_view line;
uint32_t i = 0;
bool heredoc_start_line = false;
bool ending = true;
RubyParser(void **v_state, std::string_view line)
: v_state(v_state), state((RubyState *)*v_state), line(line) {}
@@ -22,7 +23,7 @@ struct RubyParser {
return state->stack()[state->top - 1];
}
char peek(uint32_t offset = 0) {
char peek(int32_t offset = 0) {
uint32_t pos = i + offset;
return pos < line.size() ? line[pos] : '\0';
}
@@ -57,7 +58,7 @@ struct RubyParser {
.brace_level = 1,
.lit_brace_level = 0,
.state = RubyState::RubyInternalState::NONE,
.flags = 0,
.flags = RubyState::RubyInternalState::EXPECTING_EXPRESSION,
.delim_start = '\0',
.delim_end = '\0'
};
+2 -2
View File
@@ -212,10 +212,10 @@ const static std::vector<std::string> base_keywords = {
"else",
"rescue",
"ensure",
"when",
};
const static std::vector<std::string> expecting_keywords = {
"when",
"elsif",
};
@@ -247,13 +247,13 @@ const static std::vector<std::string> operator_keywords = {
"redo",
"rescue",
"retry",
"super",
"self",
"nil",
"undef",
};
const static std::vector<std::string> expecting_operators = {
"super",
"and",
"return",
"not",