From b09ba9c74b209e87c8952ffdbd5ae4cb26c8722f Mon Sep 17 00:00:00 2001
From: thorstenhater <24411438+thorstenhater@users.noreply.github.com>
Date: Fri, 15 May 2020 23:47:45 +0200
Subject: [PATCH] Modcc/fix range parse (#1040)

* [WIP] Investigate the effect of __restrict__ specifier on GPU code.

* Fix range parsing and add unit test
---
 modcc/parser.cpp                |  2 ++
 test/unit-modcc/test_parser.cpp | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/modcc/parser.cpp b/modcc/parser.cpp
index ed776735..55960aa3 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 4e86bf3c..4730560b 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"
-- 
GitLab