mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
Fix #238
This commit is contained in:
parent
604fe1808e
commit
4198d81bc6
10
peglib.h
10
peglib.h
@ -7,6 +7,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* Configuration
|
||||
*/
|
||||
|
||||
#ifndef CPPPEGLIB_HEURISTIC_ERROR_TOKEN_MAX_CHAR_COUNT
|
||||
#define CPPPEGLIB_HEURISTIC_ERROR_TOKEN_MAX_CHAR_COUNT 32
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <any>
|
||||
#include <cassert>
|
||||
@ -702,7 +710,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
size_t count = 8;
|
||||
size_t count = CPPPEGLIB_HEURISTIC_ERROR_TOKEN_MAX_CHAR_COUNT;
|
||||
size_t j = 0;
|
||||
while (count > 0 && j < i) {
|
||||
j += codepoint_length(&pos[j], i - j);
|
||||
|
@ -1041,3 +1041,27 @@ TEST(GeneralTest, InvalidCutOperator) {
|
||||
ret = parser.parse("b");
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
|
||||
TEST(GeneralTest, HeuristicErrorTokenTest) {
|
||||
auto parser = peg::parser(R"(
|
||||
program <- enum+
|
||||
enum <- 'enum' enum_kind^untyped_enum
|
||||
enum_kind <- 'sequence' / 'bitmask'
|
||||
|
||||
%whitespace <- [ \r\t\n]*
|
||||
%word <- [a-zA-Z0-9_]
|
||||
|
||||
untyped_enum <- '' { message "invalid/missing enum type, expected one of 'sequence' or 'bitmask', got '%t'"}
|
||||
)");
|
||||
|
||||
parser.log = [&](size_t ln, size_t col, const std::string &msg) {
|
||||
EXPECT_EQ(1, ln);
|
||||
EXPECT_EQ(6, col);
|
||||
EXPECT_EQ("invalid/missing enum type, expected one of 'sequence' or "
|
||||
"'bitmask', got 'sequencer'",
|
||||
msg);
|
||||
};
|
||||
|
||||
auto ret = parser.parse("enum sequencer");
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user