Skip to content
Snippets Groups Projects
Commit dbd2cf4e authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Fix real values grammar

Values such as `1e4` where not interpreted as real! This kind of construction
produced a syntax error! This has been there for a long time (incredible!).
parent a0c197a5
No related branches found
No related tags found
1 merge request!37Feature/language
...@@ -25,8 +25,14 @@ struct integer ...@@ -25,8 +25,14 @@ struct integer
: plus< digit > {}; : plus< digit > {};
struct INTEGER : seq< integer, ignored >{}; struct INTEGER : seq< integer, ignored >{};
struct exponent
: seq< one< 'E', 'e' >,
opt< one< '+', '-' > >,
plus<digit>
>{};
struct real struct real
: seq< sor< seq< : sor< seq< sor< seq<
plus< digit >, plus< digit >,
one < '.' >, one < '.' >,
star< digit > star< digit >
...@@ -36,19 +42,11 @@ struct real ...@@ -36,19 +42,11 @@ struct real
plus< digit > plus< digit >
> >
>, >,
opt< opt< exponent >
seq<
one< 'E',
'e' >,
opt< one< '+',
'-' >
>, >,
plus<digit> seq< plus< digit, exponent > >
>
>
>{}; >{};
struct escaped_c : one< '\'', '"', '?', '\\', 'a', 'b', 'f', 'n', 'r', 't', 'v' > {}; struct escaped_c : one< '\'', '"', '?', '\\', 'a', 'b', 'f', 'n', 'r', 't', 'v' > {};
struct character : if_must_else< one< '\\' >, escaped_c, ascii::any> {}; struct character : if_must_else< one< '\\' >, escaped_c, ascii::any> {};
......
...@@ -54,7 +54,7 @@ import a_module_name; ...@@ -54,7 +54,7 @@ import a_module_name;
CHECK_AST(data, result); CHECK_AST(data, result);
} }
SECTION("real") SECTION("real 1")
{ {
std::string_view data = R"( std::string_view data = R"(
1.3; 1.3;
...@@ -68,6 +68,118 @@ import a_module_name; ...@@ -68,6 +68,118 @@ import a_module_name;
CHECK_AST(data, result); CHECK_AST(data, result);
} }
SECTION("real 2")
{
std::string_view data = R"(
.5;
)";
std::string_view result = R"(
(root:void)
`-(language::real:.5:R)
)";
CHECK_AST(data, result);
}
SECTION("real 3")
{
std::string_view data = R"(
5e-1;
)";
std::string_view result = R"(
(root:void)
`-(language::real:5e-1:R)
)";
CHECK_AST(data, result);
}
SECTION("real 4")
{
std::string_view data = R"(
2e+1;
)";
std::string_view result = R"(
(root:void)
`-(language::real:2e+1:R)
)";
CHECK_AST(data, result);
}
SECTION("real 5")
{
std::string_view data = R"(
2e1;
)";
std::string_view result = R"(
(root:void)
`-(language::real:2e1:R)
)";
CHECK_AST(data, result);
}
SECTION("real 6")
{
std::string_view data = R"(
5.e-1;
)";
std::string_view result = R"(
(root:void)
`-(language::real:5.e-1:R)
)";
CHECK_AST(data, result);
}
SECTION("real 7")
{
std::string_view data = R"(
5.e+1;
)";
std::string_view result = R"(
(root:void)
`-(language::real:5.e+1:R)
)";
CHECK_AST(data, result);
}
SECTION("real 8")
{
std::string_view data = R"(
3.4e+1;
)";
std::string_view result = R"(
(root:void)
`-(language::real:3.4e+1:R)
)";
CHECK_AST(data, result);
}
SECTION("real 9")
{
std::string_view data = R"(
.231e1;
)";
std::string_view result = R"(
(root:void)
`-(language::real:.231e1:R)
)";
CHECK_AST(data, result);
}
SECTION("true") SECTION("true")
{ {
std::string_view data = R"( std::string_view data = R"(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment