8000 procedural macro to generate pratt parser at compile time · Issue #3 · matklad/minipratt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

procedural macro to generate pratt parser at compile time #3

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

Open
sergeyt opened this issue May 8, 2020 · 3 comments
Open

procedural macro to generate pratt parser at compile time #3

sergeyt opened this issue May 8, 2020 · 3 comments

Comments

@sergeyt
Copy link
sergeyt commented May 8, 2020

@matklad thanks for wonderful examples of pratt-style parsers

wondering if you have time to generalize it further :)

here is an idea of an declarative way to make expression parsers in no time:

enum UnaryOp {
  #[prefix(1)]
  Plus,
  #[postfix(1)]
  Percent,
  // ...
}

enum BinaryOp {
  #[binary(1, 1)]
  Add,
  #[binary(2, 2)]
  Multiply,
  // ...
}

enum Expr {
  #[primary]
  String,
 #[binary]
  BinExpr(BinaryOp, Box<Expr>, Box<Expr>),
  //  ...
}

// how to invoke parser
let expr = Expr::parse(Token::lexer());

i.e. you just define binding power for operators and define expression categories.

actually the idea is inspired by logos which provides declarative way to generate lexers

I know there are several attempts to do that, but they are still verbose IMO :)

@sergeyt
Copy link
Author
sergeyt commented May 8, 2020

@maciejhirsz you might be interested :)

@matklad
Copy link
Owner
matklad commented May 8, 2020

Not sure if it is an interesting point on a tradeoff curve. If I am willing to stomach code generation anyway, using [G]LR or at least a proper external grammar DSL seems like a better idea. The main appeal of Pratt parseing to me is that you don't need any extra tools to do it :-)

@sergeyt
Copy link
Author
sergeyt commented May 8, 2020

@matklad I know it does not sound super interesting :). there are a bunch of expression-like languages like Excel, DAX, RDL, etc with little differences. As usual it would be nice to have, but adapting code of this repo is faster approach for now

maybe @segeljakt (author of pratt) might be interested to implement such declarative approach :)

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
0