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

Lexer.Parse called multiple times results in errors #19

Open
starius opened this issue Jul 28, 2015 · 2 comments
Open

Lexer.Parse called multiple times results in errors #19

starius opened this issue Jul 28, 2015 · 2 comments

Comments

@starius
Copy link
Contributor

starius commented Jul 28, 2015

#include <pire/pire.h>

int main() {
    Pire::Lexer lexer("abc");
    Pire::Scanner s1 = lexer.Parse().Compile<Pire::Scanner>();
    Pire::Scanner s2 = lexer.Parse().Compile<Pire::Scanner>();
    const char* text = "abc";
    std::cout << "abc "
              << Pire::Matches(s1, text, text + 3) << ' '
              << Pire::Matches(s2, text, text + 3) << std::endl;
    std::cout << "ab  "
              << Pire::Matches(s1, text, text + 2) << ' '
              << Pire::Matches(s2, text, text + 2) << std::endl;
    std::cout << "    "
              << Pire::Matches(s1, text, text + 0) << ' '
              << Pire::Matches(s2, text, text + 0) << std::endl;
}

Output:

abc 1 0
ab  0 0
    0 1

Expected output:

abc 1 1
ab  0 0
    0 0
@dprokoptsev
Copy link
Contributor

Not sure why on Earth you've guessed it shouldn't.

@starius
Copy link
Contributor Author

starius commented Jul 28, 2015

If lexer should be a disposable object, please document it and throw an exception, when it is tried to be parsed twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants