Add basic scripting support.
- Fix certain bugs in ruby parser - And a lot more cleanup/minor fixes.
This commit is contained in:
@@ -48,6 +48,7 @@ struct ParseState {
|
||||
uint64_t line, uint64_t original, uint64_t final
|
||||
);
|
||||
static ParseState *concat(Language &lang, ParseState *a, ParseState *b);
|
||||
static void *state_before(Language &lang, ParseState *root, vase::Shard *vase, uint64_t line);
|
||||
};
|
||||
|
||||
struct ParseStateBranch : ParseState {
|
||||
@@ -83,18 +84,25 @@ struct ParsePieceBuilder {
|
||||
std::vector<ParseState *> pieces;
|
||||
std::vector<uint16_t> blocks;
|
||||
void *piece_state{nullptr};
|
||||
void *prev_state{nullptr};
|
||||
uint64_t chunk_start{0};
|
||||
uint64_t chunk_lines{0};
|
||||
ParsePieceBuilder(Language &lang, uint64_t first_line)
|
||||
: lang(lang), chunk_start(first_line) {}
|
||||
void add(
|
||||
void *state,
|
||||
uint64_t line,
|
||||
const std::vector<ParseEvent> &events
|
||||
) {
|
||||
ParsePieceBuilder(Language &lang, uint64_t first_line, void *entry_state)
|
||||
: lang(lang), chunk_start(first_line) {
|
||||
prev_state = lang.copy(entry_state);
|
||||
}
|
||||
~ParsePieceBuilder() {
|
||||
if (prev_state)
|
||||
lang.destroy(prev_state);
|
||||
if (piece_state)
|
||||
lang.destroy(piece_state);
|
||||
}
|
||||
ParsePieceBuilder(const ParsePieceBuilder &) = delete;
|
||||
ParsePieceBuilder &operator=(const ParsePieceBuilder &) = delete;
|
||||
void add(void *state, uint64_t line, const std::vector<ParseEvent> &events) {
|
||||
if (chunk_lines == 0) {
|
||||
chunk_start = line;
|
||||
piece_state = lang.copy(state);
|
||||
piece_state = lang.copy(prev_state);
|
||||
}
|
||||
for (const auto &ev : events) {
|
||||
blocks.push_back(
|
||||
@@ -103,6 +111,9 @@ struct ParsePieceBuilder {
|
||||
);
|
||||
}
|
||||
++chunk_lines;
|
||||
if (prev_state)
|
||||
lang.destroy(prev_state);
|
||||
prev_state = lang.copy(state);
|
||||
if (chunk_lines == ParseStateLeaf::MAX_CHUNK)
|
||||
flush();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ ParserSnapshot make_parser(vase::Shard *vase, uint64_t lines, Language *lang);
|
||||
ParserSnapshot retain(const ParserSnapshot &snap);
|
||||
void release(ParserSnapshot &snap);
|
||||
|
||||
void *state_before(const ParserSnapshot &snap, vase::Shard *vase, uint64_t line);
|
||||
uint64_t next_closing(const ParserSnapshot &snap, uint64_t line);
|
||||
uint64_t prev_opening(const ParserSnapshot &snap, uint64_t line);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user