diff options
Diffstat (limited to 'grammer.cpp')
-rw-r--r-- | grammer.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/grammer.cpp b/grammer.cpp index 4af1fd4..f949e2a 100644 --- a/grammer.cpp +++ b/grammer.cpp @@ -46,6 +46,16 @@ int32_t Gram::ChildIdFromTokenId(index_t token_id) return -1 - int32_t(token_id); } +index_t Gram::NodeIdFromChildId(int32_t child_id) +{ + return static_cast<index_t>(child_id); +} + +int32_t Gram::ChildIdFromNodeId(index_t node_id) +{ + return static_cast<int32_t>(node_id); +} + void Compiler::DumpTree() { Debug("= Dump ======================================="); @@ -73,7 +83,7 @@ void Compiler::DumpTree() todo.pop_front(); std::string line; - for (int i = 0; i < indent; i++) + for (size_t i = 0; i < indent; i++) line += "| "; if (ChildIdIsToken(current_index)) { index_t token_id {TokenIdFromChildId(current_index)}; @@ -85,7 +95,7 @@ void Compiler::DumpTree() line += "Node("s + std::to_string(current_index) + "): "s + node.type + "/" + std::to_string(node.variant); auto child_ids{node.child_ids}; - for (int i = 0; i < child_ids.size(); i++) { + for (size_t i = 0; i < child_ids.size(); i++) { todo.insert(todo.begin() + i, std::pair<int32_t, size_t>{child_ids[i], indent + 1}); } } @@ -405,7 +415,7 @@ namespace { if (ChildIdIsToken(child_id)) // token can't be ext node return false; - if (child_id >= nodes.size()) + if (NodeIdFromChildId(child_id) >= nodes.size()) throw std::runtime_error("Child node out of range at ext node detection: "s + std::to_string(child_id) + " vs. "s + std::to_string(nodes.size())); return nodes[child_id].type.ends_with("-EXT"); |