This commit is contained in:
yhirose 2020-08-07 10:21:47 -04:00
parent 14305f9f53
commit 0061f393de
2 changed files with 28 additions and 4 deletions

View File

@ -1239,12 +1239,10 @@ class LiteralString : public Ope,
public std::enable_shared_from_this<LiteralString> { public std::enable_shared_from_this<LiteralString> {
public: public:
LiteralString(std::string &&s, bool ignore_case) LiteralString(std::string &&s, bool ignore_case)
: lit_(s), ignore_case_(ignore_case), : lit_(s), ignore_case_(ignore_case), is_word_(false) {}
is_word_(false) {}
LiteralString(const std::string &s, bool ignore_case) LiteralString(const std::string &s, bool ignore_case)
: lit_(s), ignore_case_(ignore_case), : lit_(s), ignore_case_(ignore_case), is_word_(false) {}
is_word_(false) {}
size_t parse_core(const char *s, size_t n, SemanticValues &sv, Context &c, size_t parse_core(const char *s, size_t n, SemanticValues &sv, Context &c,
any &dt) const override; any &dt) const override;
@ -3438,6 +3436,21 @@ private:
} }
} }
// Check if the start rule has ignore operator
{
auto &rule = grammar[data.start];
if (rule.ignoreSemanticValue) {
if (log) {
auto line = line_info(s, rule.s_);
log(line.first, line.second,
"Ignore operator cannot be applied to '" + rule.name + "'.");
}
ret = false;
}
}
if (!ret) { return nullptr; }
// Check missing definitions // Check missing definitions
for (auto &x : grammar) { for (auto &x : grammar) {
auto &rule = x.second; auto &rule = x.second;

View File

@ -34,6 +34,17 @@ TEST_CASE("Empty syntax test", "[general]")
REQUIRE(ret == false); REQUIRE(ret == false);
} }
TEST_CASE("Start rule with ignore operator test", "[general]")
{
parser parser(R"(
~ROOT <- _
_ <- ' '
)");
bool ret = parser;
REQUIRE(ret == false);
}
TEST_CASE("Backslash escape sequence test", "[general]") TEST_CASE("Backslash escape sequence test", "[general]")
{ {
parser parser(R"( parser parser(R"(