Skip to content

Commit 190941c

Browse files
wip
Signed-off-by: Christian Parpart <[email protected]>
1 parent 6adefd7 commit 190941c

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

src/regex_dfa/Lexable.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ inline Token LexerIterator<Token, Machine, RequiresBeginOfLine, Trace>::recogniz
322322
stack.push_back(BadState);
323323

324324
if constexpr (Trace)
325-
tracef("recognize: startState {}, offset {} {}",
325+
tracef("recognizeOne: startState {}, offset {} {}",
326326
stateName(state),
327327
offset_,
328328
isBeginOfLine_ ? "BOL" : "no-BOL");
@@ -331,6 +331,7 @@ inline Token LexerIterator<Token, Machine, RequiresBeginOfLine, Trace>::recogniz
331331
while (state != ErrorState)
332332
{
333333
Symbol ch = nextChar(); // one of: input character, ERROR or EOF
334+
fmt::print("recognizeOne: ch: {}\n", ch);
334335
currentToken_.literal.push_back(ch);
335336

336337
// we do not stack.clear() stack if isAcceptState(state) as we need this information iff
@@ -344,7 +345,7 @@ inline Token LexerIterator<Token, Machine, RequiresBeginOfLine, Trace>::recogniz
344345
while (state != BadState && !isAcceptState(state))
345346
{
346347
if constexpr (Trace)
347-
tracef("recognize: backtrack: current state {} {}; stack: {}",
348+
tracef("recognizeOne: backtrack: current state {} {}; stack: {}",
348349
stateName(state),
349350
isAcceptState(state) ? "accepting" : "non-accepting",
350351
toString(stack));
@@ -391,7 +392,7 @@ inline Token LexerIterator<Token, Machine, RequiresBeginOfLine, Trace>::recogniz
391392
currentToken_.offset,
392393
offset_,
393394
quotedString(currentToken_.literal),
394-
quoted(currentChar_));
395+
prettySymbol(currentChar_));
395396

396397
if (!isAcceptState(state))
397398
throw LexerError { offset_ };
@@ -464,7 +465,7 @@ inline Symbol LexerIterator<Token, Machine, RequiresBeginOfLine, Trace>::nextCha
464465
}
465466

466467
int ch = source_->get();
467-
fmt::print("source.get: => {} (0x{:02X}, {})\n", ch, (uint8_t)ch, prettySymbol(ch));
468+
fmt::print("source.get: => {} (0x{:02X}, {})\n", ch, (uint16_t)ch, prettySymbol(ch));
468469
if (ch < 0)
469470
{
470471
currentChar_ = Symbols::EndOfFile;
@@ -490,6 +491,7 @@ inline void LexerIterator<Token, Machine, RequiresBeginOfLine, Trace>::rollback(
490491
{
491492
offset_--;
492493
buffered_.push_back(currentToken_.literal.back());
494+
tracef("Lexer:{}: rollback '{}'", offset_, prettySymbol(buffered_.back()));
493495
}
494496
}
495497

src/regex_dfa/Lexer-inl.h

+1-20
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,6 @@
1717
namespace regex_dfa
1818
{
1919

20-
static inline std::string quoted(int ch)
21-
{
22-
if (ch == Symbols::Epsilon)
23-
return "ε";
24-
if (ch == Symbols::Error)
25-
return "Error";
26-
if (ch == Symbols::BeginOfLine)
27-
return "BOL";
28-
if (ch == Symbols::EndOfLine)
29-
return "EOL";
30-
if (ch == Symbols::EndOfFile)
31-
return "EOF";
32-
if (ch == '\n')
33-
return "\\n";
34-
if (ch == ' ')
35-
return "\\s";
36-
return fmt::format("{}", ch);
37-
}
38-
3920
static inline std::string quotedString(const std::string& s)
4021
{
4122
std::stringstream sstr;
@@ -255,7 +236,7 @@ inline Token Lexer<Token, Machine, RequiresBeginOfLine, Debug>::recognizeOne()
255236
oldOffset_,
256237
offset_,
257238
quotedString(word_),
258-
quoted(currentChar_));
239+
prettySymbol(currentChar_));
259240

260241
if (!isAcceptState(state))
261242
throw LexerError { offset_ };

src/regex_dfa/Lexer_test.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ TEST_CASE("regex_Lexable.one")
114114
auto src = Lexable<LookaheadToken, StateId, false, true> { ld,
115115
make_unique<stringstream>("abba abcdef"),
116116
[](const string& msg) {
117-
UNSCOPED_INFO(msg);
117+
fmt::print("trace: {}\n", msg);
118118
} };
119119
auto lexer = begin(src);
120120
auto eof = end(src);
@@ -168,8 +168,9 @@ TEST_CASE("regex_Lexer.match_eol")
168168
cc.parse(RULES);
169169

170170
LexerDef ld = cc.compile();
171+
INFO(fmt::format("LexerDef:\n{}", ld.to_string()));
171172
Lexable<LookaheadToken, StateId, false, true> ls { ld, "abba eol\nabba", [](const string& msg) {
172-
INFO(msg);
173+
fmt::print("trace: {}\n", msg);
173174
} };
174175
auto lexer = begin(ls);
175176

0 commit comments

Comments
 (0)