Fix segfault when grammar consists of a single token
This commit is contained in:
parent
df3613d511
commit
6a8addb84f
2 changed files with 26 additions and 1 deletions
22
spec/compiler/compile_spec.cc
Normal file
22
spec/compiler/compile_spec.cc
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include "compiler/compiler_spec_helper.h"
|
||||
#include "tree_sitter/compiler.h"
|
||||
|
||||
using namespace rules;
|
||||
|
||||
START_TEST
|
||||
|
||||
describe("Compile", []() {
|
||||
describe("when the grammar's start symbol is a token", [&]() {
|
||||
it("does not fail", [&]() {
|
||||
Grammar grammar({
|
||||
{ "rule1", str("the-value") }
|
||||
});
|
||||
|
||||
auto result = compile(grammar, "test_grammar");
|
||||
const GrammarError *error = get<2>(result);
|
||||
AssertThat(error, Equals<const GrammarError *>(nullptr));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
END_TEST
|
||||
|
|
@ -135,7 +135,10 @@ class ParseTableBuilder {
|
|||
conflict_manager(ParseConflictManager(grammar, lex_grammar)) {}
|
||||
|
||||
pair<ParseTable, vector<Conflict> > build() {
|
||||
ParseItem start_item(rules::START(), make_shared<Symbol>(0), 0);
|
||||
auto start_symbol = grammar.rules.empty() ?
|
||||
make_shared<Symbol>(0, rules::SymbolOptionToken) :
|
||||
make_shared<Symbol>(0);
|
||||
ParseItem start_item(rules::START(), start_symbol, 0);
|
||||
add_parse_state(
|
||||
item_set_closure(start_item, { rules::END_OF_INPUT() }, grammar));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue