dannymcgee / vscode-wgsl

Rich language support for WebGPU Shading Language
Apache License 2.0
14 stars 1 forks source link

Update `switch` statement parsing #33

Closed dannymcgee closed 4 months ago

dannymcgee commented 4 months ago

This PR updates switch statement parsing to match the latest version of the WGSL spec.

A slight hack has been implemented to support the "combined default" syntax, e.g.:

switch x {
    // ...
    case 2, default {
        // ...
    }
}

Case selectors are now represented in the syntax tree as Exprs, so to accommodate this, the default keyword in a case like the one above will be parsed as an Expr::Ident(IdentExpr::Leaf "default" (Keyword (...)).

That's a little gross and makes the tree a little more awkward to traverse, but would only be exceptionally inconvenient if you were trying to do a full semantic validation — e.g., checking for the presence of exactly one default case would now be a more onerous task. That type of validation is currently beyond the scope of this project, so I'm not overly concerned about it.