Skip to content

Commit

Permalink
Simplify SymbolType (was OfSymbolType)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Evans committed Aug 21, 2024
1 parent 4c55b8f commit 0439724
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 58 deletions.
50 changes: 24 additions & 26 deletions bootstrap/bin/hocc/Parse.hmh
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ type nonterm_ident =
| SymbolTypeQualifier of {cident: token_cident;
symbol_type_qualifier_tl: nonterm_symbol_type_qualifier}
| SymbolTypeQualifierEpsilon
and nonterm_of_symbol_type =
| OfSymbolType of {of_: token_of; symbol_type_qualifier: nonterm_symbol_type_qualifier;
and nonterm_symbol_type =
| SymbolType of {symbol_type_qualifier: nonterm_symbol_type_qualifier;
symbol_type: token_uident}
and nonterm_of_symbol_type0 =
| OfSymbolType0OfSymbolType of {of_symbol_type: nonterm_of_symbol_type}
| OfSymbolType0SymbolType of {symbol_type: nonterm_symbol_type}
| OfSymbolType0Epsilon
and nonterm_prec_ref =
| PrecRefUident of {uident: token_uident}
Expand Down Expand Up @@ -231,7 +231,7 @@ type nonterm_ident =
| NontermProds of {nonterm_type: nonterm_nonterm_type; cident: token_cident;
prec_ref: nonterm_prec_ref; cce: Scan.Token.t; prods: nonterm_prods}
| NontermReductions of {nonterm_type: nonterm_nonterm_type; cident: token_cident;
of_symbol_type: nonterm_of_symbol_type; prec_ref: nonterm_prec_ref; cce: Scan.Token.t;
symbol_type: nonterm_symbol_type; prec_ref: nonterm_prec_ref; cce: Scan.Token.t;
reductions: nonterm_reductions}
and nonterm_stmt =
| StmtPrec of {prec_: nonterm_prec}
Expand Down Expand Up @@ -338,12 +338,12 @@ include hocc
SymbolTypeQualifier {cident; symbol_type_qualifier_tl}
| epsilon -> SymbolTypeQualifierEpsilon

nonterm OfSymbolType of nonterm_of_symbol_type ::=
| of_:"of" symbol_type_qualifier:SymbolTypeQualifier symbol_type:UIDENT ->
OfSymbolType {of_; symbol_type_qualifier; symbol_type}
nonterm SymbolType of nonterm_symbol_type ::=
| "of" symbol_type_qualifier:SymbolTypeQualifier symbol_type:UIDENT ->
SymbolType {symbol_type_qualifier; symbol_type}

nonterm OfSymbolType0 of nonterm_of_symbol_type0 ::=
| of_symbol_type:OfSymbolType -> OfSymbolType0OfSymbolType {of_symbol_type}
| symbol_type:SymbolType -> OfSymbolType0SymbolType {symbol_type}
| epsilon -> OfSymbolType0Epsilon

nonterm PrecRef of nonterm_prec_ref ::=
Expand Down Expand Up @@ -516,10 +516,10 @@ include hocc
| nonterm_type:NontermType cident:CIDENT prec_ref:PrecRef cce:"::=" prods:Prods ->
let COLON_COLON_EQ {token_=cce} = cce in
NontermProds {nonterm_type; cident; prec_ref; cce; prods}
| nonterm_type:NontermType cident:CIDENT of_symbol_type:OfSymbolType prec_ref:PrecRef
| nonterm_type:NontermType cident:CIDENT symbol_type:SymbolType prec_ref:PrecRef
cce:"::=" reductions:Reductions ->
let COLON_COLON_EQ {token_=cce} = cce in
NontermReductions {nonterm_type; cident; of_symbol_type; prec_ref; cce; reductions}
NontermReductions {nonterm_type; cident; symbol_type; prec_ref; cce; reductions}

nonterm Stmt of nonterm_stmt ::=
| prec_:Prec -> StmtPrec {prec_}
Expand Down Expand Up @@ -1172,31 +1172,29 @@ let rec pp_token_hocc (HOCC {token_}) formatter =
| SymbolTypeQualifierEpsilon ->
formatter |> Fmt.fmt "SymbolTypeQualifierEpsilon"

and fmt_of_symbol_type ?(alt=Fmt.alt_default) ?(width=Fmt.width_default) of_symbol_type
and fmt_symbol_type ?(alt=Fmt.alt_default) ?(width=Fmt.width_default) symbol_type
formatter =
let width' = width + 4L in
match of_symbol_type with
| OfSymbolType {of_; symbol_type_qualifier; symbol_type} ->
formatter |> Fmt.fmt "OfSymbolType "
match symbol_type with
| SymbolType {symbol_type_qualifier; symbol_type} ->
formatter |> Fmt.fmt "SymbolType "
|> fmt_lcurly ~alt ~width
|> Fmt.fmt "of_=" |> pp_token_of of_
|> fmt_semi ~alt ~width
|> Fmt.fmt "symbol_type_qualifier="
|> fmt_symbol_type_qualifier ~alt ~width:width' symbol_type_qualifier
|> fmt_semi ~alt ~width
|> Fmt.fmt "symbol_type=" |> pp_token_uident symbol_type
|> fmt_rcurly ~alt ~width
and pp_of_symbol_type of_symbol_type formatter =
fmt_of_symbol_type of_symbol_type formatter
and pp_symbol_type symbol_type formatter =
fmt_symbol_type symbol_type formatter

and fmt_of_symbol_type0 ?(alt=Fmt.alt_default) ?(width=Fmt.width_default) of_symbol_type0
formatter =
let width' = width + 4L in
match of_symbol_type0 with
| OfSymbolType0OfSymbolType {of_symbol_type} ->
formatter |> Fmt.fmt "OfSymbolType0OfSymbolType "
| OfSymbolType0SymbolType {symbol_type} ->
formatter |> Fmt.fmt "OfSymbolType0SymbolType "
|> fmt_lcurly ~alt ~width
|> Fmt.fmt "of_symbol_type=" |> fmt_of_symbol_type ~alt ~width:width' of_symbol_type
|> Fmt.fmt "symbol_type=" |> fmt_symbol_type ~alt ~width:width' symbol_type
|> fmt_rcurly ~alt ~width
| OfSymbolType0Epsilon ->
formatter |> Fmt.fmt "OfSymbolType0Epsilon"
Expand Down Expand Up @@ -1607,14 +1605,14 @@ let rec pp_token_hocc (HOCC {token_}) formatter =
|> fmt_semi ~alt ~width
|> Fmt.fmt "prods=" |> fmt_prods ~alt ~width:width' prods
|> fmt_rcurly ~alt ~width
| NontermReductions {nonterm_type; cident; of_symbol_type; prec_ref; cce; reductions} ->
| NontermReductions {nonterm_type; cident; symbol_type; prec_ref; cce; reductions} ->
formatter |> Fmt.fmt "NontermReductions "
|> fmt_lcurly ~alt ~width
|> Fmt.fmt "nonterm_type=" |> pp_nonterm_type nonterm_type
|> fmt_semi ~alt ~width
|> Fmt.fmt "cident=" |> pp_token_cident cident
|> fmt_semi ~alt ~width
|> Fmt.fmt "of_symbol_type=" |> fmt_of_symbol_type ~alt ~width:width' of_symbol_type
|> Fmt.fmt "symbol_type=" |> fmt_symbol_type ~alt ~width:width' symbol_type
|> fmt_semi ~alt ~width
|> Fmt.fmt "prec_ref=" |> fmt_prec_ref ~alt ~width:width' prec_ref
|> fmt_semi ~alt ~width
Expand Down Expand Up @@ -1848,10 +1846,10 @@ let postlude_base_of_hocc (Hocc {stmts=Stmts {stmt; stmts_tl}; _}) =
and of_prec_rels = function
| PrecRelsPrecs {precs} -> Some (of_precs precs)
| PrecRelsEpsilon -> None
and of_of_symbol_type = function
| OfSymbolType {symbol_type=UIDENT {token_}; _} -> token_
and of_symbol_type = function
| SymbolType {symbol_type=UIDENT {token_}; _} -> token_
and of_of_symbol_type0 = function
| OfSymbolType0OfSymbolType {of_symbol_type} -> Some (of_of_symbol_type of_symbol_type)
| OfSymbolType0SymbolType {symbol_type} -> Some (of_symbol_type symbol_type)
| OfSymbolType0Epsilon -> None
and of_prec_ref = function
| PrecRefUident {uident=UIDENT {token_}} -> Some token_
Expand Down
58 changes: 28 additions & 30 deletions bootstrap/bin/hocc/Parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ type nonterm_ident =
| SymbolTypeQualifier of {cident: token_cident;
symbol_type_qualifier_tl: nonterm_symbol_type_qualifier}
| SymbolTypeQualifierEpsilon
and nonterm_of_symbol_type =
| OfSymbolType of {of_: token_of; symbol_type_qualifier: nonterm_symbol_type_qualifier;
and nonterm_symbol_type =
| SymbolType of {symbol_type_qualifier: nonterm_symbol_type_qualifier;
symbol_type: token_uident}
and nonterm_of_symbol_type0 =
| OfSymbolType0OfSymbolType of {of_symbol_type: nonterm_of_symbol_type}
| OfSymbolType0SymbolType of {symbol_type: nonterm_symbol_type}
| OfSymbolType0Epsilon
and nonterm_prec_ref =
| PrecRefUident of {uident: token_uident}
Expand Down Expand Up @@ -224,7 +224,7 @@ type nonterm_ident =
| NontermProds of {nonterm_type: nonterm_nonterm_type; cident: token_cident;
prec_ref: nonterm_prec_ref; cce: Scan.Token.t; prods: nonterm_prods}
| NontermReductions of {nonterm_type: nonterm_nonterm_type; cident: token_cident;
of_symbol_type: nonterm_of_symbol_type; prec_ref: nonterm_prec_ref; cce: Scan.Token.t;
symbol_type: nonterm_symbol_type; prec_ref: nonterm_prec_ref; cce: Scan.Token.t;
reductions: nonterm_reductions}
and nonterm_stmt =
| StmtPrec of {prec_: nonterm_prec}
Expand Down Expand Up @@ -830,7 +830,7 @@ include struct
Array.get 13L prods;
]) ~first:(Ordset.of_list (module Uns) [0L; 12L])
~follow:(Ordset.singleton (module Uns) 11L);
Symbol.init ~index:46L ~name:"OfSymbolType"
Symbol.init ~index:46L ~name:"SymbolType"
~prec:None ~alias:None ~start:false
~prods:(Ordset.singleton (module Prod) (Array.get 14L prods)) ~first:(Ordset.singleton (module Uns) 16L)
~follow:(Ordset.of_list (module Uns) [10L; 15L; 24L; 26L]);
Expand Down Expand Up @@ -11775,7 +11775,7 @@ include struct
| PrecType of nonterm_prec_type
| Prec of nonterm_prec
| SymbolTypeQualifier of nonterm_symbol_type_qualifier
| OfSymbolType of nonterm_of_symbol_type
| SymbolType of nonterm_symbol_type
| OfSymbolType0 of nonterm_of_symbol_type0
| PrecRef of nonterm_prec_ref
| TokenAlias of nonterm_token_alias
Expand Down Expand Up @@ -11820,7 +11820,7 @@ include struct
| PrecType _ -> 43L
| Prec _ -> 44L
| SymbolTypeQualifier _ -> 45L
| OfSymbolType _ -> 46L
| SymbolType _ -> 46L
| OfSymbolType0 _ -> 47L
| PrecRef _ -> 48L
| TokenAlias _ -> 49L
Expand Down Expand Up @@ -12130,21 +12130,21 @@ SymbolTypeQualifierEpsilon
(* 14 *) (function
| Elm.{symbol=Symbol.Token (UIDENT symbol_type); _}
:: Elm.{symbol=Symbol.Nonterm (SymbolTypeQualifier symbol_type_qualifier); _}
:: Elm.{symbol=Symbol.Token (OF of_); _}
:: tl__hocc__ -> Symbol.Nonterm (OfSymbolType (
:: _
:: tl__hocc__ -> Symbol.Nonterm (SymbolType (
(*______________________________________________________________________________*)
(* #343 "./Parse.hmh" *)
OfSymbolType {of_; symbol_type_qualifier; symbol_type}
SymbolType {symbol_type_qualifier; symbol_type}
(*‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾*)
)), tl__hocc__
| _ -> not_reached ()
);
(* 15 *) (function
| Elm.{symbol=Symbol.Nonterm (OfSymbolType of_symbol_type); _}
| Elm.{symbol=Symbol.Nonterm (SymbolType symbol_type); _}
:: tl__hocc__ -> Symbol.Nonterm (OfSymbolType0 (
(*______________________________________________________________________________*)
(* #346 "./Parse.hmh" *)
OfSymbolType0OfSymbolType {of_symbol_type}
OfSymbolType0SymbolType {symbol_type}
(*‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾*)
)), tl__hocc__
| _ -> not_reached ()
Expand Down Expand Up @@ -12782,14 +12782,14 @@ let COLON_COLON_EQ {token_=cce} = cce in
| Elm.{symbol=Symbol.Nonterm (Reductions reductions); _}
:: Elm.{symbol=Symbol.Token (COLON_COLON_EQ cce); _}
:: Elm.{symbol=Symbol.Nonterm (PrecRef prec_ref); _}
:: Elm.{symbol=Symbol.Nonterm (OfSymbolType of_symbol_type); _}
:: Elm.{symbol=Symbol.Nonterm (SymbolType symbol_type); _}
:: Elm.{symbol=Symbol.Token (CIDENT cident); _}
:: Elm.{symbol=Symbol.Nonterm (NontermType nonterm_type); _}
:: tl__hocc__ -> Symbol.Nonterm (Nonterm (
(*______________________________________________________________________________*)
(* #521 "./Parse.hmh" *)
let COLON_COLON_EQ {token_=cce} = cce in
NontermReductions {nonterm_type; cident; of_symbol_type; prec_ref; cce; reductions}
NontermReductions {nonterm_type; cident; symbol_type; prec_ref; cce; reductions}
(*‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾*)
)), tl__hocc__
| _ -> not_reached ()
Expand Down Expand Up @@ -13863,31 +13863,29 @@ let rec pp_token_hocc (HOCC {token_}) formatter =
| SymbolTypeQualifierEpsilon ->
formatter |> Fmt.fmt "SymbolTypeQualifierEpsilon"

and fmt_of_symbol_type ?(alt=Fmt.alt_default) ?(width=Fmt.width_default) of_symbol_type
and fmt_symbol_type ?(alt=Fmt.alt_default) ?(width=Fmt.width_default) symbol_type
formatter =
let width' = width + 4L in
match of_symbol_type with
| OfSymbolType {of_; symbol_type_qualifier; symbol_type} ->
formatter |> Fmt.fmt "OfSymbolType "
match symbol_type with
| SymbolType {symbol_type_qualifier; symbol_type} ->
formatter |> Fmt.fmt "SymbolType "
|> fmt_lcurly ~alt ~width
|> Fmt.fmt "of_=" |> pp_token_of of_
|> fmt_semi ~alt ~width
|> Fmt.fmt "symbol_type_qualifier="
|> fmt_symbol_type_qualifier ~alt ~width:width' symbol_type_qualifier
|> fmt_semi ~alt ~width
|> Fmt.fmt "symbol_type=" |> pp_token_uident symbol_type
|> fmt_rcurly ~alt ~width
and pp_of_symbol_type of_symbol_type formatter =
fmt_of_symbol_type of_symbol_type formatter
and pp_symbol_type symbol_type formatter =
fmt_symbol_type symbol_type formatter

and fmt_of_symbol_type0 ?(alt=Fmt.alt_default) ?(width=Fmt.width_default) of_symbol_type0
formatter =
let width' = width + 4L in
match of_symbol_type0 with
| OfSymbolType0OfSymbolType {of_symbol_type} ->
formatter |> Fmt.fmt "OfSymbolType0OfSymbolType "
| OfSymbolType0SymbolType {symbol_type} ->
formatter |> Fmt.fmt "OfSymbolType0SymbolType "
|> fmt_lcurly ~alt ~width
|> Fmt.fmt "of_symbol_type=" |> fmt_of_symbol_type ~alt ~width:width' of_symbol_type
|> Fmt.fmt "symbol_type=" |> fmt_symbol_type ~alt ~width:width' symbol_type
|> fmt_rcurly ~alt ~width
| OfSymbolType0Epsilon ->
formatter |> Fmt.fmt "OfSymbolType0Epsilon"
Expand Down Expand Up @@ -14298,14 +14296,14 @@ let rec pp_token_hocc (HOCC {token_}) formatter =
|> fmt_semi ~alt ~width
|> Fmt.fmt "prods=" |> fmt_prods ~alt ~width:width' prods
|> fmt_rcurly ~alt ~width
| NontermReductions {nonterm_type; cident; of_symbol_type; prec_ref; cce; reductions} ->
| NontermReductions {nonterm_type; cident; symbol_type; prec_ref; cce; reductions} ->
formatter |> Fmt.fmt "NontermReductions "
|> fmt_lcurly ~alt ~width
|> Fmt.fmt "nonterm_type=" |> pp_nonterm_type nonterm_type
|> fmt_semi ~alt ~width
|> Fmt.fmt "cident=" |> pp_token_cident cident
|> fmt_semi ~alt ~width
|> Fmt.fmt "of_symbol_type=" |> fmt_of_symbol_type ~alt ~width:width' of_symbol_type
|> Fmt.fmt "symbol_type=" |> fmt_symbol_type ~alt ~width:width' symbol_type
|> fmt_semi ~alt ~width
|> Fmt.fmt "prec_ref=" |> fmt_prec_ref ~alt ~width:width' prec_ref
|> fmt_semi ~alt ~width
Expand Down Expand Up @@ -14539,10 +14537,10 @@ let postlude_base_of_hocc (Hocc {stmts=Stmts {stmt; stmts_tl}; _}) =
and of_prec_rels = function
| PrecRelsPrecs {precs} -> Some (of_precs precs)
| PrecRelsEpsilon -> None
and of_of_symbol_type = function
| OfSymbolType {symbol_type=UIDENT {token_}; _} -> token_
and of_symbol_type = function
| SymbolType {symbol_type=UIDENT {token_}; _} -> token_
and of_of_symbol_type0 = function
| OfSymbolType0OfSymbolType {of_symbol_type} -> Some (of_of_symbol_type of_symbol_type)
| OfSymbolType0SymbolType {symbol_type} -> Some (of_symbol_type symbol_type)
| OfSymbolType0Epsilon -> None
and of_prec_ref = function
| PrecRefUident {uident=UIDENT {token_}} -> Some token_
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/bin/hocc/spec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ let tokens_init io precs hmh =
-> begin
let name = string_of_token cident in
let stype = match of_symbol_type0 with
| OfSymbolType0OfSymbolType {of_symbol_type=OfSymbolType {
| OfSymbolType0SymbolType {symbol_type=SymbolType {
symbol_type_qualifier; symbol_type=UIDENT {token_=type_}; _}} -> begin
SymbolType.explicit (string_of_token type_)
|> qualify_symbol_type symbol_type_qualifier
Expand Down Expand Up @@ -244,7 +244,7 @@ let symbol_infos_init io symbols hmh =
let name, stype = match nonterm with
| Parse.NontermProds {cident=CIDENT {token_=nonterm_cident}; _} ->
string_of_token nonterm_cident, SymbolType.implicit
| NontermReductions {cident=CIDENT {token_=nonterm_cident}; of_symbol_type=OfSymbolType {
| NontermReductions {cident=CIDENT {token_=nonterm_cident}; symbol_type=SymbolType {
symbol_type_qualifier; symbol_type=UIDENT {token_=type_}; _}; _} -> begin
let name = string_of_token nonterm_cident in
let stype = SymbolType.explicit (string_of_token type_)
Expand Down

0 comments on commit 0439724

Please sign in to comment.