summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-02-08 12:36:57 +0100
committerRoland Reichwein <mail@reichwein.it>2020-02-08 12:36:57 +0100
commit2114083569546d6af32e8c638b3ebf677c433123 (patch)
tree6797141a4f79b13ecac55b8c25b27b8853b8d06c
parent8828bd96989d839a1d34c5cfc625fefdfa80a136 (diff)
Minor fixes
-rw-r--r--grammer.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/grammer.cpp b/grammer.cpp
index 8f2b42b..8a4f6b7 100644
--- a/grammer.cpp
+++ b/grammer.cpp
@@ -58,20 +58,20 @@ bool Compiler::RootIsStartSymbol() const
namespace {
-bool ChildIdIsToken(int32_t child_id)
-{
- return child_i < 0;
-}
+ bool ChildIdIsToken(int32_t child_id)
+ {
+ return child_id < 0;
+ }
-index_t TokenIdFromChildId(int32_t child_id)
-{
- return index_t(-child_id) - 1;
-}
+ index_t TokenIdFromChildId(int32_t child_id)
+ {
+ return index_t(-child_id) - 1;
+ }
-int32_t ChildIdFromTokenId(index_t token_id)
-{
- return -1 - int32_t(token_id);
-}
+ int32_t ChildIdFromTokenId(index_t token_id)
+ {
+ return -1 - int32_t(token_id);
+ }
} // namespace
@@ -123,7 +123,7 @@ void Compiler::AddFirstNode()
const std::string& child_type = tokens[0].type;
auto it = ReverseBNF.find(child_type);
if (it == ReverseBNF.end())
- throw std::runtime_error("Type not found: "s + child_type + " ("s + tokens[0].value + ")"s);
+ throw std::runtime_error("Illegal first token: "s + child_type + " ("s + tokens[0].value + ")"s);
std::set<std::string>& alternatives_set {it->second};
@@ -150,7 +150,7 @@ void Compiler::AddFirstNode()
}
if (node_type == "") // no matching type found
- throw std::runtime_error("No matching first node found.");
+ throw std::runtime_error("Syntax error on first token: "s + child_type + " ("s + tokens[0].value + ")"s);
nodes.emplace_back({0, 0, node_type, node_variant, alternatives, child_ids});
@@ -169,14 +169,13 @@ bool Compiler::AddRootNode()
index_t old_root_node_id {root_node_id};
index_t new_root_node_id {nodes.size()};
- nodes[root_node_id].parent_node_id = new_root_node_id;
std::set<std::string>& alternatives_set {it->second};
std::string node_type;
index_t node_variant;
std::deque<std::pair<std::string, index_t>> alternatives; // only for valid elements from alternatives_set
- std::vector<index_t> child_ids{1, old_root_node_id};
+ std::vector<index_t> child_ids{size_t(1), old_root_node_id};
for (const auto& type : alternatives_set) {
const auto& variants{bnf[type]};
@@ -196,6 +195,7 @@ bool Compiler::AddRootNode()
return false;
// now add!
+ nodes[old_root_node_id].parent_node_id = new_root_node_id;
root_node_id = new_root_node_id;
nodes.emplace_back({root_node_id, root_node_id, node_type, node_variant, alternatives, child_ids});
// keep tokens_used as is