Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Developing groupped terms feature. #65

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ if (CTPG_ENABLE_TESTS)
tests/buffers.cpp
tests/contexts.cpp
tests/custom_lexer.cpp
tests/groupped_terms.cpp
)

target_link_libraries(testbin PRIVATE Catch2::Catch2 ctpg::ctpg)
Expand Down
8 changes: 5 additions & 3 deletions examples/custom-lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class int_lexer
ErrorStream& error_stream)
{
if (start == end)
return recognized_term{};
return unrecognized_term;
if (*start >= '0' && *start <= '9') // recognize only single digit numbers
{
// idx == 1, recognized 'number' term
Expand All @@ -31,7 +31,7 @@ class int_lexer
// idx == 0, recognized 'comma' term
return recognized(0, options, start, sp, error_stream);
}
return recognized_term{};
return unrecognized_term;
}

private:
Expand All @@ -43,11 +43,13 @@ class int_lexer
source_point sp,
ErrorStream& error_stream)
{
// respect the verbose option, print conditionally any debug message, with the source point
if (options.verbose)
error_stream << sp << " LEXER MATCH: Recognized " << idx << " \n";

// all terms have length == 1
// update source point to refer the exact character
sp.update(start, start + 1);
// all terms have length == 1
return recognized_term(idx, 1);
}
};
Expand Down
4 changes: 2 additions & 2 deletions examples/regex-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

using namespace ctpg;

constexpr char pattern[] = R"([0-9a-zA-Z_]+)";
constexpr regex::expr<pattern> r;
constexpr char p[] = R"([0-9a-zA-Z_]+)";
constexpr regex::expr<p> r;

int main(int argc, char* argv[])
{
Expand Down
Loading