From 27572db31aee81c325139c6c756ba6bcae5d8d09 Mon Sep 17 00:00:00 2001 From: pantor Date: Wed, 22 Nov 2017 08:11:18 +0100 Subject: [PATCH] fix parse bug --- src/inja.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/inja.hpp b/src/inja.hpp index 8303117..4f95da4 100644 --- a/src/inja.hpp +++ b/src/inja.hpp @@ -509,7 +509,7 @@ public: {Parsed::Function::DivisibleBy, Regex{"divisibleBy\\(\\s*(.*?)\\s*,\\s*(.*?)\\s*\\)"}}, {Parsed::Function::Odd, Regex{"odd\\(\\s*(.*?)\\s*\\)"}}, {Parsed::Function::Even, Regex{"even\\(\\s*(.*?)\\s*\\)"}}, - {Parsed::Function::ReadJson, Regex{"\\s*(.*?)\\s*"}} + {Parsed::Function::ReadJson, Regex{"\\s*(.*)\\s*"}} }; Parser() { } @@ -517,7 +517,7 @@ public: Parsed::ElementExpression element_function(Parsed::Function func, unsigned int number_args, const Match& match) { std::vector args = {}; for (unsigned int i = 0; i < number_args; i++) { - args.push_back( parse_expression(match.str(i + 1)) ); + args.push_back( parse_expression(match.str(i + 1)) ); // str(0) is whole group } Parsed::ElementExpression result = Parsed::ElementExpression(func); @@ -583,11 +583,14 @@ public: return element_function(Parsed::Function::Different, 2, match_function); } case Parsed::Function::ReadJson: - default: { + { Parsed::ElementExpression result = Parsed::ElementExpression(Parsed::Function::ReadJson); - result.command = input; + result.command = match_function.str(1); return result; } + default: { + throw std::runtime_error("Parser error: Could not parse input: " + input); + } } }