460 (* sections *) |
460 (* sections *) |
461 |
461 |
462 local |
462 local |
463 |
463 |
464 fun sect (modifier : modifier parser) = Scan.depend (fn context => |
464 fun sect (modifier : modifier parser) = Scan.depend (fn context => |
465 let |
465 Scan.ahead Parse.not_eof -- modifier -- Scan.repeat (Scan.unless modifier Parse.xthm) >> |
466 val ctxt = Context.proof_of context; |
466 (fn ((tok, {init, attribute, pos}), xthms) => |
467 fun prep_att src = |
|
468 let |
467 let |
469 val src' = Attrib.check_src ctxt src; |
468 val decl = |
470 val _ = List.app (Token.assign NONE) (Token.args_of_src src'); |
469 (case Token.get_value tok of |
471 in src' end; |
470 SOME (Token.Declaration decl) => decl |
472 val parse_thm = |
471 | _ => |
473 Parse.xthm >> (fn (a, bs) => (Proof_Context.get_fact ctxt a, map prep_att bs)); |
472 let |
474 in |
473 val ctxt = Context.proof_of context; |
475 Scan.ahead Parse.not_eof -- modifier -- Scan.repeat (Scan.unless modifier parse_thm) >> |
474 fun prep_att src = |
476 (fn ((tok, {init, attribute, pos}), thms) => |
475 let |
477 let |
476 val src' = Attrib.check_src ctxt src; |
478 val decl = |
477 val _ = List.app (Token.assign NONE) (Token.args_of_src src'); |
479 (case Token.get_value tok of |
478 in src' end; |
480 SOME (Token.Declaration decl) => decl |
479 val thms = |
481 | _ => |
480 map (fn (a, bs) => (Proof_Context.get_fact ctxt a, map prep_att bs)) xthms; |
482 let |
481 val facts = |
483 val facts = |
482 Attrib.partial_evaluation ctxt [((Binding.name "dummy", []), thms)] |
484 Attrib.partial_evaluation ctxt [((Binding.name "dummy", []), thms)] |
483 |> map (fn (_, bs) => ((Binding.empty, [Attrib.internal (K attribute)]), bs)); |
485 |> map (fn (_, bs) => ((Binding.empty, [Attrib.internal (K attribute)]), bs)); |
484 val _ = |
486 val _ = |
485 Context_Position.report ctxt (Token.pos_of tok) |
487 Context_Position.report ctxt (Token.pos_of tok) |
486 (Markup.entity Markup.method_modifierN "" |
488 (Markup.entity Markup.method_modifierN "" |
487 |> Markup.properties (Position.def_properties_of pos)); |
489 |> Markup.properties (Position.def_properties_of pos)); |
488 fun decl phi = |
490 fun decl phi = |
489 Context.mapping I init #> |
491 Context.mapping I init #> |
490 Attrib.generic_notes "" (Attrib.transform_facts phi facts) #> snd; |
492 Attrib.generic_notes "" (Attrib.transform_facts phi facts) #> snd; |
491 val _ = Token.assign (SOME (Token.Declaration decl)) tok; |
493 val _ = Token.assign (SOME (Token.Declaration decl)) tok; |
492 in decl end); |
494 in decl end); |
493 in (Morphism.form decl context, decl) end)); |
495 in (Morphism.form decl context, decl) end) |
|
496 end); |
|
497 |
494 |
498 in |
495 in |
499 |
496 |
500 val section = sect o Scan.first; |
497 val section = sect o Scan.first; |
501 val sections = Scan.repeat o section; |
498 val sections = Scan.repeat o section; |