407 name --$$ "::" -- arity >> (pair "|> AxClass.add_inst_arity" o mk_triple2)) |
411 name --$$ "::" -- arity >> (pair "|> AxClass.add_inst_arity" o mk_triple2)) |
408 -- opt_witness |
412 -- opt_witness |
409 >> (fn ((x, y), z) => (cat_lines [x, y, z])); |
413 >> (fn ((x, y), z) => (cat_lines [x, y, z])); |
410 |
414 |
411 |
415 |
|
416 (* global *) |
|
417 |
|
418 val global_decl = empty >> K "\"/\""; |
|
419 |
|
420 |
412 |
421 |
413 (** theory syntax **) |
422 (** theory syntax **) |
414 |
423 |
415 type syntax = |
424 type syntax = |
416 lexicon * (token list -> (string * string) * token list) Symtab.table; |
425 lexicon * (token list -> (string * string) * token list) Symtab.table; |
433 val header = ident --$$ "=" -- enum1 "+" base >> mk_header; |
442 val header = ident --$$ "=" -- enum1 "+" base >> mk_header; |
434 |
443 |
435 |
444 |
436 (* extension *) |
445 (* extension *) |
437 |
446 |
438 fun mk_extension ((begin, txts), mltxt) = |
447 fun mk_extension (txts, mltxt) = |
439 let |
448 let |
440 val cat_sects = space_implode "\n\n" o filter_out (equal ""); |
449 val cat_sects = space_implode "\n\n" o filter_out (equal ""); |
441 val (extxts, postxts) = split_list txts; |
450 val (extxts, postxts) = split_list txts; |
442 in |
451 in |
443 (begin, cat_sects extxts, cat_sects postxts, mltxt) |
452 (cat_sects extxts, cat_sects postxts, mltxt) |
444 end; |
453 end; |
445 |
454 |
446 fun sect tab ((Keyword, s, n) :: toks) = |
455 fun sect tab ((Keyword, s, n) :: toks) = |
447 (case Symtab.lookup (tab, s) of |
456 (case Symtab.lookup (tab, s) of |
448 Some parse => !! parse toks |
457 Some parse => !! parse toks |
449 | None => syn_err "section" s n) |
458 | None => syn_err "section" s n) |
450 | sect _ ((_, s, n) :: _) = syn_err "section" s n |
459 | sect _ ((_, s, n) :: _) = syn_err "section" s n |
451 | sect _ [] = eof_err (); |
460 | sect _ [] = eof_err (); |
452 |
461 |
453 val opt_begin = |
|
454 optional ("begin" $$-- optional name "" >> Some) None; |
|
455 |
|
456 fun extension sectab = "+" $$-- !! |
462 fun extension sectab = "+" $$-- !! |
457 (opt_begin -- (repeat (sect sectab) --$$ "end") -- |
463 (repeat (sect sectab) --$$ "end" -- optional ("ML" $$-- verbatim) "") |
458 optional ("ML" $$-- verbatim) "") >> mk_extension; |
464 >> mk_extension; |
459 |
465 |
460 fun opt_extension sectab = optional (extension sectab) (None, "", "", ""); |
466 fun opt_extension sectab = optional (extension sectab) ("", "", ""); |
461 |
467 |
462 |
468 |
463 (* theory definition *) |
469 (* theory definition *) |
464 |
470 |
465 fun mk_structure tname ((thy_name, old_thys), (begin, extxt, postxt, mltxt)) = |
471 fun mk_structure tname ((thy_name, old_thys), (extxt, postxt, mltxt)) = |
466 if thy_name <> tname then |
472 if thy_name <> tname then |
467 error ("Filename \"" ^ tname ^ ".thy\" and theory name " |
473 error ("Filename \"" ^ tname ^ ".thy\" and theory name " |
468 ^ quote thy_name ^ " are different") |
474 ^ quote thy_name ^ " are different") |
469 else |
475 else |
470 "val thy = " ^ old_thys ^ ";\n\n\ |
476 "val thy = " ^ old_thys ^ ";\n\n\ |
476 \in\n\ |
482 \in\n\ |
477 \\n" |
483 \\n" |
478 ^ mltxt ^ "\n\ |
484 ^ mltxt ^ "\n\ |
479 \\n\ |
485 \\n\ |
480 \val thy = thy\n\ |
486 \val thy = thy\n\ |
481 \\n\ |
487 \\n" ^ |
482 \|> Theory.add_path \"/\"\n" ^ |
488 (if ! global_names then "" else "|> Theory.add_path " ^ quote tname ^ "\n") ^ |
483 (case begin of |
|
484 None => (warning ("Flat name space for theory " ^ tname ^ "? Consider begin ..."); "") |
|
485 | Some "" => "|> Theory.add_path " ^ quote tname ^ "\n" |
|
486 | Some path => "|> Theory.add_path " ^ path ^ "\n") ^ |
|
487 "\n\ |
489 "\n\ |
488 \|> Theory.add_trfuns\n" |
490 \|> Theory.add_trfuns\n" |
489 ^ trfun_args ^ "\n\ |
491 ^ trfun_args ^ "\n\ |
490 \|> Theory.add_trfunsT typed_print_translation \n\ |
492 \|> Theory.add_trfunsT typed_print_translation \n\ |
491 \|> Theory.add_tokentrfuns token_translation \n\ |
493 \|> Theory.add_tokentrfuns token_translation \n\ |
526 fun section name pretxt parse = |
528 fun section name pretxt parse = |
527 axm_section name pretxt (parse >> rpair []); |
529 axm_section name pretxt (parse >> rpair []); |
528 |
530 |
529 |
531 |
530 val pure_keywords = |
532 val pure_keywords = |
531 ["end", "ML", "mixfix", "infixr", "infixl", "begin", "binder", "output", "=", |
533 ["end", "ML", "mixfix", "infixr", "infixl", "binder", "global", |
532 "+", ",", "<", "{", "}", "(", ")", "[", "]", "::", "==", "=>", "<="]; |
534 "output", "=", "+", ",", "<", "{", "}", "(", ")", "[", "]", "::", |
|
535 "==", "=>", "<="]; |
533 |
536 |
534 val pure_sections = |
537 val pure_sections = |
535 [section "classes" "|> Theory.add_classes" class_decls, |
538 [section "classes" "|> Theory.add_classes" class_decls, |
536 section "default" "|> Theory.add_defsort" sort, |
539 section "default" "|> Theory.add_defsort" sort, |
537 section "types" "" type_decls, |
540 section "types" "" type_decls, |
543 axm_section "defs" "|> Theory.add_defs" axiom_decls, |
546 axm_section "defs" "|> Theory.add_defs" axiom_decls, |
544 section "oracle" "|> Theory.add_oracle" oracle_decl, |
547 section "oracle" "|> Theory.add_oracle" oracle_decl, |
545 axm_section "constdefs" "|> Theory.add_consts" constaxiom_decls, |
548 axm_section "constdefs" "|> Theory.add_consts" constaxiom_decls, |
546 axm_section "axclass" "|> AxClass.add_axclass" axclass_decl, |
549 axm_section "axclass" "|> AxClass.add_axclass" axclass_decl, |
547 section "instance" "" instance_decl, |
550 section "instance" "" instance_decl, |
548 section "path" "|> Theory.add_path" name]; |
551 section "path" "|> Theory.add_path" name, |
|
552 section "global" "|> Theory.add_path" global_decl]; |
549 |
553 |
550 |
554 |
551 end; |
555 end; |