src/Pure/Isar/method.ML
changeset 27813 96fbe385a0d0
parent 27751 22c32eb18c23
child 29004 a5a91f387791
equal deleted inserted replaced
27812:af8edf3ab68c 27813:96fbe385a0d0
   111   val goal_args_ctxt: (Args.T list -> 'a * Args.T list) ->
   111   val goal_args_ctxt: (Args.T list -> 'a * Args.T list) ->
   112     (Proof.context -> 'a -> int -> tactic) -> src -> Proof.context -> method
   112     (Proof.context -> 'a -> int -> tactic) -> src -> Proof.context -> method
   113   val goal_args_ctxt': (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list)) ->
   113   val goal_args_ctxt': (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list)) ->
   114     (Proof.context -> 'a -> int -> tactic) -> src -> Proof.context -> method
   114     (Proof.context -> 'a -> int -> tactic) -> src -> Proof.context -> method
   115   val parse: OuterLex.token list -> text * OuterLex.token list
   115   val parse: OuterLex.token list -> text * OuterLex.token list
   116   val parse_args: Args.T list -> text * Args.T list
       
   117 end;
   116 end;
   118 
   117 
   119 structure Method: METHOD =
   118 structure Method: METHOD =
   120 struct
   119 struct
   121 
   120 
   468 
   467 
   469 
   468 
   470 
   469 
   471 (** concrete syntax **)
   470 (** concrete syntax **)
   472 
   471 
       
   472 structure P = OuterParse;
       
   473 
       
   474 
   473 (* basic *)
   475 (* basic *)
   474 
   476 
   475 fun syntax scan = Args.context_syntax "method" scan;
   477 fun syntax scan = Args.context_syntax "method" scan;
   476 
   478 
   477 fun simple_args scan f src ctxt : method =
   479 fun simple_args scan f src ctxt : method =
   523 val elimN = "elim";
   525 val elimN = "elim";
   524 val destN = "dest";
   526 val destN = "dest";
   525 val ruleN = "rule";
   527 val ruleN = "rule";
   526 
   528 
   527 fun modifier name kind kind' att =
   529 fun modifier name kind kind' att =
   528   Args.$$$ name |-- (kind >> K NONE || kind' |-- Args.nat --| Args.colon >> SOME)
   530   Args.$$$ name |-- (kind >> K NONE || kind' |-- P.nat --| Args.colon >> SOME)
   529     >> (pair (I: Proof.context -> Proof.context) o att);
   531     >> (pair (I: Proof.context -> Proof.context) o att);
   530 
   532 
   531 val iprover_modifiers =
   533 val iprover_modifiers =
   532  [modifier destN Args.bang_colon Args.bang ContextRules.dest_bang,
   534  [modifier destN Args.bang_colon Args.bang ContextRules.dest_bang,
   533   modifier destN Args.colon (Scan.succeed ()) ContextRules.dest,
   535   modifier destN Args.colon (Scan.succeed ()) ContextRules.dest,
   538   Args.del -- Args.colon >> K (I, ContextRules.rule_del)];
   540   Args.del -- Args.colon >> K (I, ContextRules.rule_del)];
   539 
   541 
   540 in
   542 in
   541 
   543 
   542 val iprover_meth =
   544 val iprover_meth =
   543   bang_sectioned_args' iprover_modifiers (Scan.lift (Scan.option Args.nat))
   545   bang_sectioned_args' iprover_modifiers (Scan.lift (Scan.option P.nat))
   544     (fn n => fn prems => fn ctxt => METHOD (fn facts =>
   546     (fn n => fn prems => fn ctxt => METHOD (fn facts =>
   545       HEADGOAL (insert_tac (prems @ facts) THEN'
   547       HEADGOAL (insert_tac (prems @ facts) THEN'
   546       ObjectLogic.atomize_prems_tac THEN' iprover_tac ctxt n)));
   548       ObjectLogic.atomize_prems_tac THEN' iprover_tac ctxt n)));
   547 
   549 
   548 end;
   550 end;
   549 
   551 
   550 
   552 
   551 (* tactic syntax *)
   553 (* tactic syntax *)
   552 
   554 
   553 fun nat_thms_args f = uncurry f oo
   555 fun nat_thms_args f = uncurry f oo
   554   (fst oo syntax (Scan.lift (Scan.optional (Args.parens Args.nat) 0) -- Attrib.thms));
   556   (fst oo syntax (Scan.lift (Scan.optional (Args.parens P.nat) 0) -- Attrib.thms));
   555 
   557 
   556 fun goal_args' args tac src ctxt = fst (syntax (Args.goal_spec HEADGOAL -- args >>
   558 fun goal_args' args tac src ctxt = fst (syntax (Args.goal_spec HEADGOAL -- args >>
   557   (fn (quant, s) => SIMPLE_METHOD'' quant (tac s))) src ctxt);
   559   (fn (quant, s) => SIMPLE_METHOD'' quant (tac s))) src ctxt);
   558 
   560 
   559 fun goal_args args tac = goal_args' (Scan.lift args) tac;
   561 fun goal_args args tac = goal_args' (Scan.lift args) tac;
   561 fun goal_args_ctxt' args tac src ctxt =
   563 fun goal_args_ctxt' args tac src ctxt =
   562   fst (syntax (Args.goal_spec HEADGOAL -- args >>
   564   fst (syntax (Args.goal_spec HEADGOAL -- args >>
   563   (fn (quant, s) => SIMPLE_METHOD'' quant (tac ctxt s))) src ctxt);
   565   (fn (quant, s) => SIMPLE_METHOD'' quant (tac ctxt s))) src ctxt);
   564 
   566 
   565 fun goal_args_ctxt args tac = goal_args_ctxt' (Scan.lift args) tac;
   567 fun goal_args_ctxt args tac = goal_args_ctxt' (Scan.lift args) tac;
       
   568 
       
   569 
       
   570 (* outer parser *)
       
   571 
       
   572 fun is_symid_meth s =
       
   573   s <> "|" andalso s <> "?" andalso s <> "+" andalso OuterLex.ident_or_symbolic s;
       
   574 
       
   575 local
       
   576 
       
   577 fun meth4 x =
       
   578  (P.position (P.xname >> rpair []) >> (Source o Args.src) ||
       
   579   P.$$$ "(" |-- P.!!! (meth0 --| P.$$$ ")")) x
       
   580 and meth3 x =
       
   581  (meth4 --| P.$$$ "?" >> Try ||
       
   582   meth4 --| P.$$$ "+" >> Repeat1 ||
       
   583   meth4 -- (P.$$$ "[" |-- Scan.optional P.nat 1 --| P.$$$ "]") >> (SelectGoals o swap) ||
       
   584   meth4) x
       
   585 and meth2 x =
       
   586  (P.position (P.xname -- Args.parse1 is_symid_meth) >> (Source o Args.src) ||
       
   587   meth3) x
       
   588 and meth1 x = (P.enum1 "," meth2 >> (fn [m] => m | ms => Then ms)) x
       
   589 and meth0 x = (P.enum1 "|" meth1 >> (fn [m] => m | ms => Orelse ms)) x;
       
   590 
       
   591 in val parse = meth3 end;
   566 
   592 
   567 
   593 
   568 (* theory setup *)
   594 (* theory setup *)
   569 
   595 
   570 val _ = Context.>> (Context.map_theory
   596 val _ = Context.>> (Context.map_theory
   587     ("this", no_args this, "apply current facts as rules"),
   613     ("this", no_args this, "apply current facts as rules"),
   588     ("fact", thms_ctxt_args fact, "composition by facts from context"),
   614     ("fact", thms_ctxt_args fact, "composition by facts from context"),
   589     ("assumption", ctxt_args assumption, "proof by assumption, preferring facts"),
   615     ("assumption", ctxt_args assumption, "proof by assumption, preferring facts"),
   590     ("rename_tac", goal_args (Scan.repeat1 Args.name) Tactic.rename_tac,
   616     ("rename_tac", goal_args (Scan.repeat1 Args.name) Tactic.rename_tac,
   591       "rename parameters of goal"),
   617       "rename parameters of goal"),
   592     ("rotate_tac", goal_args (Scan.optional Args.int 1) Tactic.rotate_tac,
   618     ("rotate_tac", goal_args (Scan.optional P.int 1) Tactic.rotate_tac,
   593       "rotate assumptions of goal"),
   619       "rotate assumptions of goal"),
   594     ("tactic", simple_args (Args.position Args.name) tactic, "ML tactic as proof method"),
   620     ("tactic", simple_args (P.position Args.name) tactic, "ML tactic as proof method"),
   595     ("raw_tactic", simple_args (Args.position Args.name) raw_tactic,
   621     ("raw_tactic", simple_args (P.position Args.name) raw_tactic,
   596       "ML tactic as raw proof method")]));
   622       "ML tactic as raw proof method")]));
   597 
       
   598 
       
   599 (* outer parser *)
       
   600 
       
   601 structure T = OuterLex;
       
   602 structure P = OuterParse;
       
   603 
       
   604 fun is_symid_meth s =
       
   605   s <> "|" andalso s <> "?" andalso s <> "+" andalso T.is_sid s;
       
   606 
       
   607 local
       
   608 
       
   609 fun meth4 x =
       
   610  (P.position (P.xname >> rpair []) >> (Source o Args.src) ||
       
   611   P.$$$ "(" |-- P.!!! (meth0 --| P.$$$ ")")) x
       
   612 and meth3 x =
       
   613  (meth4 --| P.$$$ "?" >> Try ||
       
   614   meth4 --| P.$$$ "+" >> Repeat1 ||
       
   615   meth4 -- (P.$$$ "[" |-- Scan.optional P.nat 1 --| P.$$$ "]") >> (SelectGoals o swap) ||
       
   616   meth4) x
       
   617 and meth2 x =
       
   618  (P.position (P.xname -- P.generic_args1 is_symid_meth) >> (Source o Args.src) ||
       
   619   meth3) x
       
   620 and meth1 x = (P.enum1 "," meth2 >> (fn [m] => m | ms => Then ms)) x
       
   621 and meth0 x = (P.enum1 "|" meth1 >> (fn [m] => m | ms => Orelse ms)) x;
       
   622 
       
   623 in val parse = meth3 end;
       
   624 
       
   625 
       
   626 (* args parser *)
       
   627 
       
   628 local
       
   629 
       
   630 fun enum1 sep scan = scan ::: Scan.repeat (Args.$$$ sep |-- scan);
       
   631 
       
   632 fun meth4 x =
       
   633  (Args.position (Args.name >> rpair []) >> (Source o Args.src) ||
       
   634   Args.$$$ "(" |-- Args.!!! (meth0 --| Args.$$$ ")")) x
       
   635 and meth3 x =
       
   636  (meth4 --| Args.$$$ "?" >> Try ||
       
   637   meth4 --| Args.$$$ "+" >> Repeat1 ||
       
   638   meth4 -- (Args.$$$ "[" |-- Scan.optional Args.nat 1 --| Args.$$$ "]") >> (SelectGoals o swap) ||
       
   639   meth4) x
       
   640 and meth2 x =
       
   641  (Args.position (Args.name -- Args.generic_args1 is_symid_meth) >> (Source o Args.src) ||
       
   642   meth3) x
       
   643 and meth1 x = (enum1 "," meth2 >> (fn [m] => m | ms => Then ms)) x
       
   644 and meth0 x = (enum1 "|" meth1 >> (fn [m] => m | ms => Orelse ms)) x;
       
   645 
       
   646 in val parse_args = meth3 end;
       
   647 
   623 
   648 
   624 
   649 (*final declarations of this structure!*)
   625 (*final declarations of this structure!*)
   650 val unfold = unfold_meth;
   626 val unfold = unfold_meth;
   651 val fold = fold_meth;
   627 val fold = fold_meth;