From 04397243594890983f3dccaf627bc54b9e90d5a8 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 20 Aug 2024 18:37:18 -0700 Subject: [PATCH] Simplify SymbolType (was OfSymbolType) --- bootstrap/bin/hocc/Parse.hmh | 50 +++++++++++++++---------------- bootstrap/bin/hocc/Parse.ml | 58 +++++++++++++++++------------------- bootstrap/bin/hocc/spec.ml | 4 +-- 3 files changed, 54 insertions(+), 58 deletions(-) diff --git a/bootstrap/bin/hocc/Parse.hmh b/bootstrap/bin/hocc/Parse.hmh index 304fecfb..90888118 100644 --- a/bootstrap/bin/hocc/Parse.hmh +++ b/bootstrap/bin/hocc/Parse.hmh @@ -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} @@ -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} @@ -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 ::= @@ -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_} @@ -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" @@ -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 @@ -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_ diff --git a/bootstrap/bin/hocc/Parse.ml b/bootstrap/bin/hocc/Parse.ml index 1b868d53..2e7cc37d 100644 --- a/bootstrap/bin/hocc/Parse.ml +++ b/bootstrap/bin/hocc/Parse.ml @@ -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} @@ -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} @@ -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]); @@ -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 @@ -11820,7 +11820,7 @@ include struct | PrecType _ -> 43L | Prec _ -> 44L | SymbolTypeQualifier _ -> 45L - | OfSymbolType _ -> 46L + | SymbolType _ -> 46L | OfSymbolType0 _ -> 47L | PrecRef _ -> 48L | TokenAlias _ -> 49L @@ -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 () @@ -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 () @@ -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" @@ -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 @@ -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_ diff --git a/bootstrap/bin/hocc/spec.ml b/bootstrap/bin/hocc/spec.ml index c040ae15..7e019b71 100644 --- a/bootstrap/bin/hocc/spec.ml +++ b/bootstrap/bin/hocc/spec.ml @@ -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 @@ -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_)