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

Any method to integrate a customized lexer in your library? #261

Closed
asmwarrior opened this issue Jan 10, 2023 · 2 comments
Closed

Any method to integrate a customized lexer in your library? #261

asmwarrior opened this issue Jan 10, 2023 · 2 comments

Comments

@asmwarrior
Copy link

Hi, as we know, the PEG grammar is text(character) based, which means we write lexer and parser grammar together.
But in my application, I have my own lexer(mainly the C-preprocessor) implemented myself, so my question is: can the library support parsing rules for custom lexer.

For example, the lexer has some kinds of std::vector<Token> supplied, the Token class may have definition like:

class Token
{
    TokenKind kind;
    std::string lexeme;
}

Any idea or suggestions?
I mean it could be a generalized peg grammar?

Thanks.

@yhirose
Copy link
Owner

yhirose commented Jan 10, 2023

@asmwarrior, thanks for your question. In short, it's difficult to do it...

Here is the interface of Ope which is a parser combinator.

  size_t parse_core(const char *s, size_t n, SemanticValues & /*vs*/,
                    Context &c, std::any & /*dt*/) const override {

As you can see, it takes a char pointer. If you can change it to take a list of tokens (and change all the related code for it), it might be doable. But it must be better and easier to write such a parser from scratch instead of changing cpp-peglib. And we can't call it a PEG parser. Hope it helps.

@yhirose yhirose closed this as completed Jan 10, 2023
@asmwarrior
Copy link
Author

OK, I see. Thanks for the reply.

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