Fix some issues introduced by error reporting
This commit is contained in:
		
							parent
							
								
									afb492b3b0
								
							
						
					
					
						commit
						98c83e435b
					
				| 
						 | 
				
			
			@ -58,10 +58,20 @@ namespace backends {
 | 
			
		|||
                topLevel["num_rules"] = templ::make_string(std::to_string(grammar.rules.size()));
 | 
			
		||||
                topLevel["num_symbols"] = templ::make_string(std::to_string(grammar.terminals.size() + 1 + grammar.variables.size())); // + 1 for EOF
 | 
			
		||||
 | 
			
		||||
                std::set<std::string> terminals = grammar.terminals;
 | 
			
		||||
                terminals.insert(util::EOF_PLACEHOLDER);
 | 
			
		||||
 | 
			
		||||
                std::string lastTerminal = "";
 | 
			
		||||
                std::vector<templ::TemplateContext> symbols;
 | 
			
		||||
                for (auto& s : grammar.terminals)
 | 
			
		||||
                    symbols.push_back(templ::make_map({{"symbol", templ::make_string("T_" + s)}}));
 | 
			
		||||
                symbols.push_back(templ::make_map({{"symbol", templ::make_string("T_EOF")}}));
 | 
			
		||||
                for (auto& s : terminals) {
 | 
			
		||||
                    if (s == util::EOF_PLACEHOLDER)
 | 
			
		||||
                        symbols.push_back(templ::make_map({{"symbol", templ::make_string("T_EOF")}}));
 | 
			
		||||
                    else
 | 
			
		||||
                        symbols.push_back(templ::make_map({{"symbol", templ::make_string("T_" + s)}}));
 | 
			
		||||
                    lastTerminal = s;
 | 
			
		||||
                }
 | 
			
		||||
                topLevel["last_terminal"] = templ::make_string("T_" + lastTerminal);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                for (auto& s : grammar.variables)
 | 
			
		||||
                    symbols.push_back(templ::make_map({{"symbol", templ::make_string("V_" + s)}}));
 | 
			
		||||
| 
						 | 
				
			
			@ -89,8 +99,6 @@ namespace backends {
 | 
			
		|||
                }
 | 
			
		||||
                topLevel["rulenames"] = templ::make_array(std::move(rulenamesT));
 | 
			
		||||
 | 
			
		||||
                std::set<std::string> terminals = grammar.terminals;
 | 
			
		||||
                terminals.insert(util::EOF_PLACEHOLDER);
 | 
			
		||||
                std::vector<templ::TemplateContext> states(table.act.size());
 | 
			
		||||
                for (std::size_t i = 0; i < table.act.size(); i++) {
 | 
			
		||||
                    std::map<const std::string, templ::TemplateContext> st;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -155,7 +155,7 @@ Value {{name}}<Value>::parse() {
 | 
			
		|||
                    constexpr std::uint64_t verr = static_cast<std::uint64_t>({{name}}_Symbol::V_error);
 | 
			
		||||
                    std::vector<{{name}}_Symbol> expected;
 | 
			
		||||
                    {{#symbols}}
 | 
			
		||||
                    if ({{name}}_Symbol::{{symbol}} <= {{name}}_Symbol::T_EOF && (TABLE[stateStack.top()][static_cast<std::uint64_t>({{name}}_Symbol::{{symbol}})] & 0x3) != ERROR) {
 | 
			
		||||
                    if ({{name}}_Symbol::{{symbol}} <= {{name}}_Symbol::{{last_terminal}} && (TABLE[stateStack.top()][static_cast<std::uint64_t>({{name}}_Symbol::{{symbol}})] & 0x3) != ERROR) {
 | 
			
		||||
                        expected.emplace_back({{name}}_Symbol::{{symbol}});
 | 
			
		||||
                    }
 | 
			
		||||
                    {{/symbols}}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue