src/Pure/Thy/sessions.ML
author wenzelm
Sat, 26 May 2018 19:40:02 +0200
changeset 68292 7ca0c23179e6
parent 67220 0049bed35f5a
child 68808 5467858e9419
permissions -rw-r--r--
support 'export_files' in session ROOT;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
67215
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/sessions.ML
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
     3
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
     4
Support for session ROOT syntax.
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
     5
*)
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
     6
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
     7
signature SESSIONS =
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
     8
sig
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
     9
  val root_name: string
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    10
  val theory_name: string
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    11
  val command_parser: (Toplevel.transition -> Toplevel.transition) parser
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    12
end;
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    13
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    14
structure Sessions: SESSIONS =
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    15
struct
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    16
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    17
val root_name = "ROOT";
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    18
val theory_name = "Pure.Sessions";
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    19
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    20
local
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    21
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    22
val global =
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    23
  Parse.$$$ "(" -- Parse.!!! (Parse.$$$ "global" -- Parse.$$$ ")") >> K true || Scan.succeed false;
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    24
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    25
val theory_entry = Parse.position Parse.theory_name --| global;
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    26
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    27
val theories =
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    28
  Parse.$$$ "theories" |-- Parse.!!! (Scan.optional Parse.options [] -- Scan.repeat1 theory_entry);
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    29
68292
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    30
val in_path =
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    31
  Parse.$$$ "(" |-- Parse.!!! (Parse.$$$ "in" |-- Parse.position Parse.path --| Parse.$$$ ")");
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    32
67215
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    33
val document_files =
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    34
  Parse.$$$ "document_files" |--
68292
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    35
    Parse.!!! (Scan.optional in_path ("document", Position.none)
67215
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    36
      -- Scan.repeat1 (Parse.position Parse.path));
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    37
68292
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    38
val export_files =
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    39
  Parse.$$$ "export_files" |--
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    40
    Parse.!!! (Scan.optional in_path ("export", Position.none) -- Scan.repeat1 Parse.name);
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    41
67215
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    42
in
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    43
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    44
val command_parser =
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    45
  Parse.session_name --
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    46
  Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Scan.repeat1 Parse.name --| Parse.$$$ ")")) [] --
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    47
  Scan.optional (Parse.$$$ "in" |-- Parse.!!! (Parse.position Parse.path)) (".", Position.none) --
67220
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    48
  (Parse.$$$ "=" |--
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    49
    Parse.!!! (Scan.option (Parse.position Parse.session_name --| Parse.!!! (Parse.$$$ "+")) --
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    50
      Scan.optional (Parse.$$$ "description" |-- Parse.!!! (Parse.input Parse.text)) Input.empty --
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    51
      Scan.optional (Parse.$$$ "options" |-- Parse.!!! Parse.options) [] --
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    52
      Scan.optional (Parse.$$$ "sessions" |--
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    53
        Parse.!!! (Scan.repeat1 (Parse.position Parse.session_name))) [] --
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    54
      Scan.repeat theories --
68292
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    55
      Scan.repeat document_files --
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    56
      Scan.repeat export_files))
67220
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    57
  >> (fn (((session, _), dir),
68292
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    58
          (((((((parent, descr), options), sessions), theories), document_files), export_files))) =>
67215
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    59
    Toplevel.keep (fn state =>
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    60
      let
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    61
        val ctxt = Toplevel.context_of state;
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    62
        val thy = Toplevel.theory_of state;
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    63
        val session_dir = Resources.check_dir ctxt (Resources.master_directory thy) dir;
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    64
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    65
        val _ =
67220
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    66
          (the_list parent @ sessions) |> List.app (fn arg =>
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    67
            ignore (Resources.check_session ctxt arg)
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    68
              handle ERROR msg => Output.error_message msg);
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    69
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    70
        val _ =
67215
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    71
          Context_Position.report ctxt
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    72
            (Position.range_position (Symbol_Pos.range (Input.source_explode descr)))
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    73
            Markup.comment;
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    74
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    75
        val _ =
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    76
          (options @ maps #1 theories) |> List.app (fn (x, y) =>
67220
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    77
            ignore (Completion.check_option_value ctxt x y (Options.default ()))
0049bed35f5a more markup;
wenzelm
parents: 67215
diff changeset
    78
              handle ERROR msg => Output.error_message msg);
67215
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    79
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    80
        val _ =
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    81
          maps #2 theories |> List.app (fn (s, pos) =>
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    82
            let
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    83
              val {node_name, theory_name, ...} =
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    84
                Resources.import_name session session_dir s
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    85
                  handle ERROR msg => error (msg ^ Position.here pos);
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    86
              val theory_path = the_default node_name (Resources.known_theory theory_name);
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    87
              val _ = Resources.check_file ctxt Path.current (Path.implode theory_path, pos);
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    88
            in () end);
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    89
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    90
        val _ =
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    91
          document_files |> List.app (fn (doc_dir, doc_files) =>
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    92
            let
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    93
              val dir = Resources.check_dir ctxt session_dir doc_dir;
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    94
              val _ = List.app (ignore o Resources.check_file ctxt dir) doc_files;
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
    95
            in () end);
68292
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    96
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    97
        val _ =
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    98
          export_files |> List.app (fn (export_dir, _) =>
7ca0c23179e6 support 'export_files' in session ROOT;
wenzelm
parents: 67220
diff changeset
    99
            ignore (Resources.check_path ctxt session_dir export_dir));
67215
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
   100
      in () end));
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
   101
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
   102
end;
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
   103
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents:
diff changeset
   104
end;