Skip to content

Commit

Permalink
Support more general timing constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
MasWag committed Oct 18, 2024
1 parent 4b6b8e4 commit c064f36
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Syntax of Timed Regular Expressions
| expr expr (Concatenation)
| expr | expr (Disjunction)
| expr & expr (Conjunction)
| expr % (s,t) (Time Restriction)
| expr % (s,t) | expr % [s,t) | expr % (s,t] | expr % [s,t] | expr % (>s) | expr % (>=s) | expr % (<t) | expr % (<=t) | expr % (=t) (Time Restriction)

Related Tool
-------------
Expand Down
2 changes: 1 addition & 1 deletion doc/TRE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ expr : c (An event)
| expr expr (Concatenation)
| expr | expr (Disjunction)
| expr & expr (Conjunction)
| expr % (s,t) (Time Restriction)
| expr % (s,t) | expr % [s,t) | expr % (s,t] | expr % [s,t] | expr % (>s) | expr % (>=s) | expr % (<t) | expr % (<=t) | expr % (=t) (Time Restriction)
```

For the basic examples, please read [Getting Started](./getting_started.md). We only show advanced specifications here.
Expand Down
10 changes: 8 additions & 2 deletions monaa/tre_lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ using token = MONAA::TREParser::token;
"%" return token::WITHIN;
"(" return token::LPAREN;
")" return token::RPAREN;
"[" return token::LSQPAREN;
"]" return token::RSQPAREN;
"<" return token::LT;
">" return token::GT;
"<=" return token::LE;
">=" return token::GE;
"=" return token::EQ;
"," return token::COMMA;

[a-zA-Z$] {
Expand All @@ -45,8 +52,7 @@ using token = MONAA::TREParser::token;
return token::INT;
}

[[:blank:]]+
"\n" return token::END;

%%


16 changes: 16 additions & 0 deletions monaa/tre_parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@
WITHIN "%"
LPAREN "("
RPAREN ")"
LSQPAREN "["
RSQPAREN "]"
COMMA ","
GT ">"
GE ">="
LE "<="
LT "<"
EQ "="
;

%locations
Expand All @@ -69,6 +76,15 @@ expr : ATOM { $$ = std::make_shared<TRE>(TRE::op::atom, $1); }

/* We support only open intervals now */
interval : LPAREN INT COMMA INT RPAREN { $$ = std::make_shared<Interval>($2, $4); }
| LSQPAREN INT COMMA INT RPAREN { $$ = std::make_shared<Interval>(Bounds($2, 1), Bounds($4, 0)); }
| LPAREN INT COMMA INT RSQPAREN { $$ = std::make_shared<Interval>(Bounds($2, 0), Bounds($4, 1)); }
| LSQPAREN INT COMMA INT RSQPAREN { $$ = std::make_shared<Interval>(Bounds($2, 1), Bounds($4, 1)); }
| LT INT { $$ = std::make_shared<Interval>(Bounds(0, 1), Bounds($2, 0)); }
| LE INT { $$ = std::make_shared<Interval>(Bounds(0, 1), Bounds($2, 1)); }
| EQ INT { $$ = std::make_shared<Interval>(Bounds($2, 1), Bounds($2, 1)); }
| GE INT { $$ = std::make_shared<Interval>(Bounds($2, 1), Bounds(std::numeric_limits<double>::infinity(), 0)); }
| GT INT { $$ = std::make_shared<Interval>($2); }
| LPAREN interval RPAREN { $$ = $2; }
%%


Expand Down
72 changes: 72 additions & 0 deletions test/tre_driver_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,78 @@ BOOST_FIXTURE_TEST_CASE(simpleTimedParse, SimpleTimedExpression)
result << *(driver.getResult());
BOOST_CHECK_EQUAL(result.str(), "((a(ba))%((1, 0),(2, 0)))");
}

BOOST_AUTO_TEST_CASE(closeTimedParse) {
TREDriver driver;
std::stringstream stream, result;
stream << "(aba)%[2,4]";
BOOST_TEST_REQUIRE(driver.parse(stream));
result << *(driver.getResult());
BOOST_CHECK_EQUAL(result.str(), "((a(ba))%((2, 1),(4, 1)))");
}

BOOST_AUTO_TEST_CASE(leftOpenTimedParse) {
TREDriver driver;
std::stringstream stream, result;
stream << "(aba)%(2,4]";
BOOST_TEST_REQUIRE(driver.parse(stream));
result << *(driver.getResult());
BOOST_CHECK_EQUAL(result.str(), "((a(ba))%((2, 0),(4, 1)))");
}

BOOST_AUTO_TEST_CASE(rightOpenTimedParse) {
TREDriver driver;
std::stringstream stream, result;
stream << "(aba)%[2,4)";
BOOST_TEST_REQUIRE(driver.parse(stream));
result << *(driver.getResult());
BOOST_CHECK_EQUAL(result.str(), "((a(ba))%((2, 1),(4, 0)))");
}

BOOST_AUTO_TEST_CASE(ltParse) {
TREDriver driver;
std::stringstream stream, result;
stream << "(aba)%(< 3)";
BOOST_TEST_REQUIRE(driver.parse(stream));
result << *(driver.getResult());
BOOST_CHECK_EQUAL(result.str(), "((a(ba))%((0, 1),(3, 0)))");
}

BOOST_AUTO_TEST_CASE(leParse) {
TREDriver driver;
std::stringstream stream, result;
stream << "(aba)%(<= 3)";
BOOST_TEST_REQUIRE(driver.parse(stream));
result << *(driver.getResult());
BOOST_CHECK_EQUAL(result.str(), "((a(ba))%((0, 1),(3, 1)))");
}

BOOST_AUTO_TEST_CASE(eqParse) {
TREDriver driver;
std::stringstream stream, result;
stream << "(aba)%(= 3)";
BOOST_TEST_REQUIRE(driver.parse(stream));
result << *(driver.getResult());
BOOST_CHECK_EQUAL(result.str(), "((a(ba))%((3, 1),(3, 1)))");
}

BOOST_AUTO_TEST_CASE(geParse) {
TREDriver driver;
std::stringstream stream, result;
stream << "(aba)%(>= 3)";
BOOST_TEST_REQUIRE(driver.parse(stream));
result << *(driver.getResult());
BOOST_CHECK_EQUAL(result.str(), "((a(ba))%((3, 1),(inf, 0)))");
}

BOOST_AUTO_TEST_CASE(gtParse) {
TREDriver driver;
std::stringstream stream, result;
stream << "(aba)%(> 3)";
BOOST_TEST_REQUIRE(driver.parse(stream));
result << *(driver.getResult());
BOOST_CHECK_EQUAL(result.str(), "((a(ba))%((3, 0),(inf, 0)))");
}
BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit c064f36

Please sign in to comment.