Skip to content

Commit

Permalink
Fix some binding pattern grammar nits
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Evans committed Aug 23, 2024
1 parent 57ad68a commit 1a0232a
Show file tree
Hide file tree
Showing 3 changed files with 2,149 additions and 1,633 deletions.
41 changes: 34 additions & 7 deletions bootstrap/bin/hocc/Parse.hmh
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ type nonterm_precs_tl =
| ProdParamBinding of {binding: nonterm_binding; prod_param_symbol: nonterm_prod_param_symbol}
| ProdParamPattern of {lparen: token_lparen; pattern: nonterm_pattern; rparen: token_rparen;
prod_param_symbol: nonterm_prod_param_symbol}
| ProdParamFields of {lcurly: token_lcurly; fields: nonterm_pattern_fields; rcurly: token_rcurly;
prod_param_symbol: nonterm_prod_param_symbol}
| ProdParam of {prod_param_symbol: nonterm_prod_param_symbol}
and nonterm_prod_params_tl =
| ProdParamsTlProdParam of {prod_param: nonterm_prod_param;
Expand Down Expand Up @@ -480,24 +482,27 @@ include hocc
| "(" pattern:Pattern ")"
| CIDENT pattern:Pattern prec pCIDENT
| ModulePath "." "(" pattern:Pattern ")"
| ModulePath "." "{" pattern:Pattern "}"
-> PatternPattern {pattern}
| pattern_a:Pattern "," pattern_b:Pattern prec pCOMMA
-> PatternComma {pattern_a; pattern_b}
| "{" fields:PatternFields SemiSuffix "}"
| ModulePath "." "{" fields:PatternFields SemiSuffix "}"
-> PatternFields {fields}

nonterm ProdParamSymbol of nonterm_prod_param_symbol ::=
| cident:CIDENT -> ProdParamSymbolCident {cident}
| alias:ISTRING -> ProdParamSymbolAlias {alias}

nonterm ProdParam of nonterm_prod_param ::=
| binding:Binding ":" prod_param_symbol:ProdParamSymbol ->
ProdParamBinding {binding; prod_param_symbol}
| lparen:"(" pattern:Pattern rparen:")" ":" prod_param_symbol:ProdParamSymbol ->
ProdParamPattern {lparen; pattern; rparen; prod_param_symbol}
| prod_param_symbol:ProdParamSymbol ->
ProdParam {prod_param_symbol}
| binding:Binding ":" prod_param_symbol:ProdParamSymbol
-> ProdParamBinding {binding; prod_param_symbol}
| lparen:"(" pattern:Pattern rparen:")" ":" prod_param_symbol:ProdParamSymbol
-> ProdParamPattern {lparen; pattern; rparen; prod_param_symbol}
| lcurly:"{" fields:PatternFields SemiSuffix rcurly:"}" ":" prod_param_symbol:ProdParamSymbol
-> ProdParamFields {lcurly; fields; rcurly; prod_param_symbol}
| "_" prod_param_symbol:ProdParamSymbol
| prod_param_symbol:ProdParamSymbol
-> ProdParam {prod_param_symbol}

nonterm ProdParamsTl of nonterm_prod_params_tl ::=
| prod_param:ProdParam prod_params_tl:ProdParamsTl ->
Expand Down Expand Up @@ -809,13 +814,22 @@ let source_of_token_lparen = function
let source_of_token_rparen = function
| RPAREN {token_} -> token_source token_

let source_of_token_lcurly = function
| LCURLY {token_} -> token_source token_

let source_of_token_rcurly = function
| RCURLY {token_} -> token_source token_

let rec source_of_binding = function
| Binding {uident} -> source_of_token_uident uident
and source_of_prod_param_binding = function
| ProdParamBinding {binding; _} -> source_of_binding binding
| ProdParamPattern {lparen; rparen; _} ->
source_of_token_lparen lparen
|> join_sources (source_of_token_rparen rparen)
| ProdParamFields {lcurly; rcurly; _} ->
source_of_token_lcurly lcurly
|> join_sources (source_of_token_rcurly rcurly)
| ProdParam _ -> None

(**************************************************************************************************)
Expand Down Expand Up @@ -1517,6 +1531,18 @@ let rec pp_token_hocc (HOCC {token_}) formatter =
|> Fmt.fmt "prod_param_symbol="
|> fmt_prod_param_symbol ~alt ~width:width' prod_param_symbol
|> fmt_rcurly ~alt ~width
| ProdParamFields {lcurly; fields; rcurly; prod_param_symbol} ->
formatter |> Fmt.fmt "ProdParamFields "
|> fmt_lcurly ~alt ~width
|> Fmt.fmt "lcurly=" |> pp_token_lcurly lcurly
|> fmt_semi ~alt ~width
|> Fmt.fmt "fields=" |> fmt_pattern_fields ~alt ~width:width' fields
|> fmt_semi ~alt ~width
|> Fmt.fmt "rcurly=" |> pp_token_rcurly rcurly
|> fmt_semi ~alt ~width
|> Fmt.fmt "prod_param_symbol="
|> fmt_prod_param_symbol ~alt ~width:width' prod_param_symbol
|> fmt_rcurly ~alt ~width
| ProdParam {prod_param_symbol} ->
formatter |> Fmt.fmt "ProdParam "
|> fmt_lcurly ~alt ~width
Expand Down Expand Up @@ -1930,6 +1956,7 @@ let postlude_base_of_hocc (Hocc {stmts=Stmts {stmt; stmts_tl}; _}) =
and of_prod_param = function
| ProdParamBinding {prod_param_symbol; _}
| ProdParamPattern {prod_param_symbol; _}
| ProdParamFields {prod_param_symbol; _}
| ProdParam {prod_param_symbol} -> of_prod_param_symbol prod_param_symbol
and of_prod_params_tl = function
| ProdParamsTlProdParam {prod_param; prod_params_tl} -> begin
Expand Down
Loading

0 comments on commit 1a0232a

Please sign in to comment.