Handle built-in symbols correctly in conflict manager
This commit is contained in:
parent
44c4bf5f5e
commit
b217cd38fb
3 changed files with 37 additions and 6 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include <string>
|
||||
#include <set>
|
||||
#include "compiler/util/string_helpers.h"
|
||||
#include "compiler/rules/built_in_symbols.h"
|
||||
#include "compiler/prepared_grammar.h"
|
||||
|
||||
namespace tree_sitter {
|
||||
|
|
@ -106,13 +107,26 @@ namespace tree_sitter {
|
|||
}
|
||||
}
|
||||
|
||||
string ParseConflictManager::symbol_name(const rules::Symbol &symbol) {
|
||||
if (symbol.is_built_in()) {
|
||||
if (symbol == rules::ERROR())
|
||||
return "ERROR";
|
||||
else if (symbol == rules::END_OF_INPUT())
|
||||
return "END_OF_INPUT";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
if (symbol.is_token())
|
||||
return lex_grammar.rule_name(symbol);
|
||||
else
|
||||
return parse_grammar.rule_name(symbol);
|
||||
}
|
||||
|
||||
void ParseConflictManager::record_conflict(const rules::Symbol &symbol,
|
||||
const ParseAction &left,
|
||||
const ParseAction &right) {
|
||||
string name = symbol.is_token() ?
|
||||
lex_grammar.rule_name(symbol) :
|
||||
parse_grammar.rule_name(symbol);
|
||||
conflicts_.insert(Conflict(name + ": " +
|
||||
conflicts_.insert(Conflict(symbol_name(symbol) + ": " +
|
||||
message_for_action(left, parse_grammar) + " / " +
|
||||
message_for_action(right, parse_grammar)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,11 @@ namespace tree_sitter {
|
|||
bool resolve_parse_action(const rules::Symbol &symbol,
|
||||
const ParseAction &old_action,
|
||||
const ParseAction &new_action);
|
||||
|
||||
void record_conflict(const rules::Symbol &symbol, const ParseAction &left, const ParseAction &right);
|
||||
const std::vector<Conflict> conflicts() const;
|
||||
|
||||
private:
|
||||
std::string symbol_name(const rules::Symbol &symbol);
|
||||
void record_conflict(const rules::Symbol &symbol, const ParseAction &left, const ParseAction &right);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue