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

Parsing a "switch { case n: m }" #73

Closed
joagre opened this issue Dec 7, 2023 · 0 comments
Closed

Parsing a "switch { case n: m }" #73

joagre opened this issue Dec 7, 2023 · 0 comments

Comments

@joagre
Copy link

joagre commented Dec 7, 2023

I tried to write a grammar to parse the following toy example:

switch 1 {
  case 2:
    3,
    42
  case 4:
    5
}

I tried with the following but it is not the way to do it:

SwitchStmt <- "switch" _ Expr _ "{" _ CaseStmt+ _ "}"
CaseStmt <- "case" _ Expr _ ":" _ ExprList
ExprList <- Expr (_ "," _ Expr)*
Expr <- [0-9]+
_ <- WS*
WS <- " " / "\t" / "\n" / "\r"

Any hints?

Cheers
/J

@joagre joagre closed this as completed Dec 7, 2023
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

1 participant