diff --git a/modcc/parser.cpp b/modcc/parser.cpp index ed776735c544ecd1092b1575ff0a7ce75d550509..55960aa3cd9a3fe547499f9d1c48c92286ccf109 100644 --- a/modcc/parser.cpp +++ b/modcc/parser.cpp @@ -765,6 +765,7 @@ std::pair<Token, Token> Parser::range_description() { get_token(); lb = token_; + get_token(); if(token_.type != tok::comma) { error(pprintf("range description must separate lower and upper bound with a comma '%'", token_)); return {}; @@ -773,6 +774,7 @@ std::pair<Token, Token> Parser::range_description() { get_token(); ub = token_; + get_token(); if(token_.type != tok::gt) { error(pprintf("range description must end with a right angle bracket '%'", token_)); return {}; diff --git a/test/unit-modcc/test_parser.cpp b/test/unit-modcc/test_parser.cpp index 4e86bf3c6e60f742d7d2d2ff33e2001fcd665959..4730560b39996471220239263a2a147f6cb675fd 100644 --- a/test/unit-modcc/test_parser.cpp +++ b/test/unit-modcc/test_parser.cpp @@ -159,6 +159,32 @@ TEST(Parser, parameters_from_constant) { EXPECT_EQ("1.2", param_block.parameters[1].value); } +TEST(Parser, parameters_range) { + const char str[] = + "PARAMETER { \n" + " tau = 0.2 <0,1000> \n" + " rho = 0.2 \n" + "}"; + + expression_ptr null; + Module m(str, str+std::strlen(str), ""); + Parser p(m, false); + p.parse_parameter_block(); + + EXPECT_EQ(lexerStatus::happy, p.status()); + verbose_print(null, p, str); + + auto param_block = m.parameter_block(); + EXPECT_EQ("tau", param_block.parameters[0].name()); + EXPECT_EQ("0.2", param_block.parameters[0].value); + EXPECT_EQ("0", param_block.parameters[0].range.first.spelling); + EXPECT_EQ("1000", param_block.parameters[0].range.second.spelling); + EXPECT_EQ("rho", param_block.parameters[1].name()); + EXPECT_EQ("0.2", param_block.parameters[1].value); + EXPECT_EQ("", param_block.parameters[1].range.first.spelling); + EXPECT_EQ("", param_block.parameters[1].range.second.spelling); +} + TEST(Parser, net_receive) { char str[] = "NET_RECEIVE (x, y) { \n"