Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locating identifiers in tactics (including ltac2, ssr) #13103

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Using located identifiers in ssrvernac and ssrparser grammars.
  • Loading branch information
herbelin committed Oct 28, 2020
commit 5facd932395c436cd84886a9fb5a47f02088f5ad
49 changes: 25 additions & 24 deletions plugins/ssr/ssrparser.mlg
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ open Pcoq.Prim
ARGUMENT EXTEND ssrhyp TYPED AS ssrhyprep PRINTED BY { pr_ssrhyp }
INTERPRETED BY { interp_hyp }
GLOBALIZED BY { intern_hyp }
| [ ident(id) ] -> { SsrHyp (Loc.tag ~loc id) }
| [ identref(id) ] -> { SsrHyp (Loc.tag ~loc id.CAst.v) }
END

{
Expand All @@ -178,27 +178,27 @@ let wit_ssrhoirep = add_genarg "ssrhoirep" (fun env sigma -> pr_hoi)

let intern_ssrhoi ist = function
| Hyp h -> Hyp (intern_hyp ist h)
| Id (SsrHyp (_, id)) as hyp ->
let _ = Tacintern.intern_genarg ist (in_gen (rawwit wit_ident) id) in
| Id (SsrHyp (loc, id)) as hyp ->
let _ = Tacintern.intern_genarg ist (in_gen (rawwit wit_identref) (CAst.make ?loc id)) in
hyp

let interp_ssrhoi ist gl = function
| Hyp h -> let s, h' = interp_hyp ist gl h in s, Hyp h'
| Id (SsrHyp (loc, id)) ->
let s, id' = interp_wit wit_ident ist gl id in
s, Id (SsrHyp (loc, id'))
let s, id' = interp_wit wit_identref ist gl (CAst.make ?loc id) in
s, Id (SsrHyp (loc, id'.CAst.v))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this diff hunk supports @ppedrot thesis. Here the loc is already in the AST, the copy in the ident is just getting in the way. It would feel more natural to pass loc to interp_wit frankly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that it is expected that interp_wit takes a loc since it goes from user-facing syntax to "abstract" syntax (the first line of the diff). What is more questionable (and what @ppedrot questions, afaiu) is that interp_wit continues to return the loc (the second line of the diff).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant is that if you don't put the loc in the ident in the fist place, then interp_wit is not going to return it, you can still pass the loc as you pass ist and gl if you need to


}

ARGUMENT EXTEND ssrhoi_hyp TYPED AS ssrhoirep PRINTED BY { pr_ssrhoi }
INTERPRETED BY { interp_ssrhoi }
GLOBALIZED BY { intern_ssrhoi }
| [ ident(id) ] -> { Hyp (SsrHyp(Loc.tag ~loc id)) }
| [ identref(id) ] -> { Hyp (SsrHyp(Loc.tag ~loc id.CAst.v)) }
END
ARGUMENT EXTEND ssrhoi_id TYPED AS ssrhoirep PRINTED BY { pr_ssrhoi }
INTERPRETED BY { interp_ssrhoi }
GLOBALIZED BY { intern_ssrhoi }
| [ ident(id) ] -> { Id (SsrHyp(Loc.tag ~loc id)) }
| [ identref(id) ] -> { Id (SsrHyp(Loc.tag ~loc id.CAst.v)) }
END

(** Rewriting direction *)
Expand Down Expand Up @@ -781,8 +781,8 @@ ARGUMENT EXTEND ssripat TYPED AS ssripatrep list PRINTED BY { pr_ssripats }
| [ "-/" integer(n) "/" integer (m) "=" ] ->
{ [IPatNoop;IPatSimpl(SimplCut(n,m))] }
| [ ssrfwdview(v) ] -> { [IPatView v] }
| [ "[" ":" ident_list(idl) "]" ] -> { [IPatAbstractVars idl] }
| [ "[:" ident_list(idl) "]" ] -> { [IPatAbstractVars idl] }
| [ "[" ":" identref_list(idl) "]" ] -> { [IPatAbstractVars (List.map (fun {CAst.v=id} -> id) idl)] }
| [ "[:" identref_list(idl) "]" ] -> { [IPatAbstractVars (List.map (fun {CAst.v=id} -> id) idl)] }
END

ARGUMENT EXTEND ssripats TYPED AS ssripat PRINTED BY { pr_ssripats }
Expand Down Expand Up @@ -836,10 +836,10 @@ END
GRAMMAR EXTEND Gram
GLOBAL: ssrcpat;
hat: [
[ "^"; id = ident -> { Prefix id }
| "^"; "~"; id = ident -> { SuffixId id }
[ "^"; id = identref -> { Prefix id.CAst.v }
| "^"; "~"; id = identref -> { SuffixId id.CAst.v }
| "^"; "~"; n = natural -> { SuffixNum n }
| "^~"; id = ident -> { SuffixId id }
| "^~"; id = identref -> { SuffixId id.CAst.v }
| "^~"; n = natural -> { SuffixNum n }
]];
ssrcpat: [
Expand Down Expand Up @@ -973,13 +973,13 @@ end
(** Defined identifier *)
let pr_ssrfwdid id = pr_spc () ++ pr_id id

let pr_ssrfwdidx _ _ _ = pr_ssrfwdid
let pr_ssrfwdidx _ _ _ id = pr_ssrfwdid id.CAst.v

}

(* We use a primitive parser for the head identifier of forward *)
(* tactis to avoid syntactic conflicts with basic Coq tactics. *)
ARGUMENT EXTEND ssrfwdid TYPED AS ident PRINTED BY { pr_ssrfwdidx }
ARGUMENT EXTEND ssrfwdid TYPED AS identref PRINTED BY { pr_ssrfwdidx }
END

{
Expand All @@ -994,7 +994,7 @@ let test_ssrfwdid =

GRAMMAR EXTEND Gram
GLOBAL: ssrfwdid;
ssrfwdid: [[ test_ssrfwdid; id = Prim.ident -> { id } ]];
ssrfwdid: [[ test_ssrfwdid; id = identref -> { id } ]];
END


Expand Down Expand Up @@ -1295,7 +1295,7 @@ let pr_ssrbvar env sigma prc _ _ v = prc env sigma v
}

ARGUMENT EXTEND ssrbvar TYPED AS constr PRINTED BY { pr_ssrbvar env sigma }
| [ ident(id) ] -> { mkCVar ~loc id }
| [ identref(id) ] -> { mkCVar ~loc id.CAst.v }
| [ "_" ] -> { mkCHole (Some loc) }
END

Expand Down Expand Up @@ -1379,7 +1379,8 @@ let pr_ssrstruct _ _ _ = function

}

ARGUMENT EXTEND ssrstruct TYPED AS ident option PRINTED BY { pr_ssrstruct }
ARGUMENT EXTEND ssrstruct TYPED AS ident option
PRINTED BY { pr_ssrstruct }
| [ "{" "struct" ident(id) "}" ] -> { Some id }
| [ ] -> { None }
END
Expand Down Expand Up @@ -1590,7 +1591,7 @@ let ssrorelse = Entry.create "ssrorelse"
GRAMMAR EXTEND Gram
GLOBAL: ssrorelse ssrseqarg;
ssrseqidx: [
[ test_ssrseqvar; id = Prim.ident -> { ArgVar (CAst.make ~loc id) }
[ test_ssrseqvar; id = identref -> { ArgVar id }
| n = Prim.natural -> { ArgArg (check_index ~loc n) }
] ];
ssrswap: [[ IDENT "first" -> { loc, true } | IDENT "last" -> { loc, false } ]];
Expand Down Expand Up @@ -1646,15 +1647,15 @@ let ssr_id_of_string loc s =
else Feedback.msg_warning (str (
"The name " ^ s ^ " fits the _xxx_ format used for anonymous variables.\n"
^ "Scripts with explicit references to anonymous variables are fragile."))
end; Id.of_string s
end; CAst.make ~loc (Id.of_string s)

let ssr_null_entry = Pcoq.Entry.of_parser "ssr_null" (fun _ _ -> ())

}

GRAMMAR EXTEND Gram
GLOBAL: Prim.ident;
Prim.ident: [[ s = IDENT; ssr_null_entry -> { ssr_id_of_string loc s } ]];
GLOBAL: Prim.identref;
Prim.identref: [[ s = IDENT; ssr_null_entry -> { ssr_id_of_string loc s } ]];
END

{
Expand Down Expand Up @@ -1965,7 +1966,7 @@ let test_ssreqid =
GRAMMAR EXTEND Gram
GLOBAL: ssreqid;
ssreqpat: [
[ id = Prim.ident -> { IPatId id }
[ id = Prim.identref -> { IPatId id.CAst.v }
| "_" -> { IPatAnon Drop }
| "?" -> { IPatAnon (One None) }
| "+" -> { IPatAnon Temporary }
Expand Down Expand Up @@ -2427,7 +2428,7 @@ END
TACTIC EXTEND ssrpose
| [ "pose" ssrfixfwd(ffwd) ] -> { ssrposetac ffwd }
| [ "pose" ssrcofixfwd(ffwd) ] -> { ssrposetac ffwd }
| [ "pose" ssrfwdid(id) ssrposefwd(fwd) ] -> { ssrposetac (id, fwd) }
| [ "pose" ssrfwdid(id) ssrposefwd(fwd) ] -> { ssrposetac (id.CAst.v, fwd) }
END

(** The "set" tactic *)
Expand All @@ -2436,7 +2437,7 @@ END

TACTIC EXTEND ssrset
| [ "set" ssrfwdid(id) ssrsetfwd(fwd) ssrclauses(clauses) ] ->
{ tclCLAUSES (ssrsettac id fwd) clauses }
{ tclCLAUSES (ssrsettac id.CAst.v fwd) clauses }
END

(** The "have" tactic *)
Expand Down
2 changes: 1 addition & 1 deletion plugins/ssr/ssrparser.mli
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ val wit_ssrhintarg :

val wit_ssrexactarg : ssrapplyarg Genarg.uniform_genarg_type
val wit_ssrcongrarg : ((int * ssrterm) * cpattern ssragens) Genarg.uniform_genarg_type
val wit_ssrfwdid : Names.Id.t Genarg.uniform_genarg_type
val wit_ssrfwdid : Names.lident Genarg.uniform_genarg_type

val wit_ssrsetfwd :
((ssrfwdfmt * (cpattern * ast_closure_term option)) * ssrdocc) Genarg.uniform_genarg_type
Expand Down
8 changes: 4 additions & 4 deletions plugins/ssr/ssrvernac.mlg
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ END
GRAMMAR EXTEND Gram
GLOBAL: hloc;
hloc: [
[ "in"; "("; "Type"; "of"; id = ident; ")" ->
{ Tacexpr.HypLocation (CAst.make id, Locus.InHypTypeOnly) }
| "in"; "("; IDENT "Value"; "of"; id = ident; ")" ->
{ Tacexpr.HypLocation (CAst.make id, Locus.InHypValueOnly) }
[ "in"; "("; "Type"; "of"; id = identref; ")" ->
{ Tacexpr.HypLocation (id, Locus.InHypTypeOnly) }
| "in"; "("; IDENT "Value"; "of"; id = identref; ")" ->
{ Tacexpr.HypLocation (id, Locus.InHypValueOnly) }
] ];
END

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy