Update syntax parser system.

This commit is contained in:
2026-08-20 19:33:45 +01:00
parent 1489b08d57
commit 6ea03d651a
8 changed files with 357 additions and 155 deletions
+19 -3
View File
@@ -5,6 +5,15 @@
#include "tries.h"
namespace bed::internal::syntax::ruby {
enum struct ScopeTypes : uint8_t {
None,
Comment,
Method,
Class,
Module,
Block
};
struct alignas(2) RubyState {
struct RubyInternalState {
uint16_t brace_level;
@@ -17,9 +26,16 @@ struct alignas(2) RubyState {
COMMENT,
END
} state;
static constexpr const uint8_t EXPECTING_EXPRESSION = 0b00010000;
static constexpr const uint8_t ALLOW_INTERPOLATION = 0b00000001;
uint8_t flags;
static constexpr uint8_t NAME_MASK = 0b00000011;
enum : uint8_t {
NONE_NAME = 0b00,
CLASS_NAME = 0b01,
DEF_NAME = 0b10,
MODULE_NAME = 0b11
};
static constexpr uint8_t ALLOW_INTERPOLATION = 1 << 6;
static constexpr uint8_t EXPECTING_EXPRESSION = 1 << 7;
uint8_t flags = 0;
char delim_start;
char delim_end;
};
+4 -1
View File
@@ -99,5 +99,8 @@ struct RubyParser {
}
};
void ruby_parse(void **v_state, std::string_view line, bool first_line, std::vector<Token> *);
void ruby_parse(
void **v_state, std::string_view line, bool first_line,
std::vector<Token> *tokens, std::vector<ParseEvent> *events
);
} // namespace bed::internal::syntax::ruby
+22 -7
View File
@@ -209,25 +209,31 @@ const static std::vector<std::string> errors = {
};
const static std::vector<std::string> base_keywords = {
"class",
"module",
"begin",
"end",
"else",
"rescue",
"ensure",
"do",
"when",
};
const static std::vector<std::string> expecting_keywords = {
"if",
"elsif",
};
const static std::vector<std::string> expecting_end_keywords = {
"case",
"for",
};
const static std::vector<std::string> conditional_keywords = {
"if",
"unless",
"while",
"until",
"unless",
};
const static std::vector<std::string> end_keywords = {
"begin",
"do",
};
const static std::vector<std::string> operator_keywords = {
@@ -312,6 +318,9 @@ struct RubyTries {
trie::Trie<void> builtins_trie;
trie::Trie<void> methods_trie;
trie::Trie<void> errors_trie;
trie::Trie<void> expecting_end_keywords_trie;
trie::Trie<void> conditional_keywords_trie;
trie::Trie<void> end_keywords_trie;
RubyTries() {
for (auto &keyword : base_keywords)
base_keywords_trie.insert(keyword);
@@ -331,6 +340,12 @@ struct RubyTries {
methods_trie.insert(keyword);
for (auto &keyword : errors)
errors_trie.insert(keyword);
for (auto &keyword : expecting_end_keywords)
expecting_end_keywords_trie.insert(keyword);
for (auto &keyword : conditional_keywords)
conditional_keywords_trie.insert(keyword);
for (auto &keyword : end_keywords)
end_keywords_trie.insert(keyword);
}
};
} // namespace bed::internal::syntax::ruby