Skip to content

Commit

Permalink
feat: configurable optional semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
tydeu committed May 11, 2024
1 parent d2c496f commit 8da8169
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Alloy/C/Grammar.lean
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ It uses Microsoft's [C Language Syntax Summary][1], the C11 standard's

open Lean Parser

register_option Alloy.C.optSemicolon : Bool := {
defValue := true
descr := "Should semicolons be optional in Alloy C code?"
}

namespace Alloy.C

/-!
Expand Down Expand Up @@ -642,12 +647,15 @@ The semicolon terminator of a C statement/declaration.
The semicolon is made "optional" to help make partial statements
well-formed for better LSP support and to enable whitespace-based termination
in polyglot syntax.
in polyglot syntax. This behavior can be disabled via
`set_option Alloy.C.optSemicolon false`.
For the shim, the elaborator will always convert this into a real semicolon,
even if it has been elided in user code.
-/
syntax endSemi := ";"?
def endSemi : Parser := leading_parser
withFn (p := optional (symbol ";")) fun p c s =>
if optSemicolon.get c.options then p c s else symbolFn ";" c s

/-- Ensure the previous syntax ended with a semicolon token. -/
def checkSemi : Parser :=
Expand Down

0 comments on commit 8da8169

Please sign in to comment.