src/Pure/Thy/thy_syntax.ML
changeset 43621 e8858190cccd
parent 43430 1ed88ddf1268
child 44352 176e0fb6906b
equal deleted inserted replaced
43620:43a195a0279b 43621:e8858190cccd
    19   val span_range: span -> Position.range
    19   val span_range: span -> Position.range
    20   val span_source: (Token.T, 'a) Source.source -> (span, (Token.T, 'a) Source.source) Source.source
    20   val span_source: (Token.T, 'a) Source.source -> (span, (Token.T, 'a) Source.source) Source.source
    21   val parse_spans: Scan.lexicon * Scan.lexicon -> Position.T -> string -> span list
    21   val parse_spans: Scan.lexicon * Scan.lexicon -> Position.T -> string -> span list
    22   val present_span: span -> Output.output
    22   val present_span: span -> Output.output
    23   val report_span: span -> unit
    23   val report_span: span -> unit
    24   val atom_source: (span, 'a) Source.source ->
    24   type element = {head: span, proof: span list, proper_proof: bool}
    25     (span * span list * bool, (span, 'a) Source.source) Source.source
    25   val element_source: (span, 'a) Source.source ->
       
    26     (element, (span, 'a) Source.source) Source.source
    26 end;
    27 end;
    27 
    28 
    28 structure Thy_Syntax: THY_SYNTAX =
    29 structure Thy_Syntax: THY_SYNTAX =
    29 struct
    30 struct
    30 
    31 
   157 
   158 
   158 end;
   159 end;
   159 
   160 
   160 
   161 
   161 
   162 
   162 (** specification atoms: commands with optional proof **)
   163 (** specification elements: commands with optional proof **)
       
   164 
       
   165 type element = {head: span, proof: span list, proper_proof: bool};
       
   166 
       
   167 fun make_element head proof proper_proof =
       
   168   {head = head, proof = proof, proper_proof = proper_proof};
       
   169 
   163 
   170 
   164 (* scanning spans *)
   171 (* scanning spans *)
   165 
   172 
   166 val eof = Span (Command "", []);
   173 val eof = Span (Command "", []);
   167 
   174 
   171 val not_eof = not o is_eof;
   178 val not_eof = not o is_eof;
   172 
   179 
   173 val stopper = Scan.stopper (K eof) is_eof;
   180 val stopper = Scan.stopper (K eof) is_eof;
   174 
   181 
   175 
   182 
   176 (* atom_source *)
   183 (* element_source *)
   177 
   184 
   178 local
   185 local
   179 
   186 
   180 fun command_with pred = Scan.one (fn (Span (Command name, _)) => pred name | _ => false);
   187 fun command_with pred = Scan.one (fn (Span (Command name, _)) => pred name | _ => false);
   181 
   188 
   185     command_with Keyword.is_qed_global >> pair ~1 ||
   192     command_with Keyword.is_qed_global >> pair ~1 ||
   186     command_with Keyword.is_proof_goal >> pair (d + 1) ||
   193     command_with Keyword.is_proof_goal >> pair (d + 1) ||
   187     (if d = 0 then Scan.fail else command_with Keyword.is_qed >> pair (d - 1)) ||
   194     (if d = 0 then Scan.fail else command_with Keyword.is_qed >> pair (d - 1)) ||
   188     Scan.unless (command_with Keyword.is_theory) (Scan.one not_eof) >> pair d)) -- Scan.state);
   195     Scan.unless (command_with Keyword.is_theory) (Scan.one not_eof) >> pair d)) -- Scan.state);
   189 
   196 
   190 val atom =
   197 val element =
   191   command_with Keyword.is_theory_goal -- proof >> (fn (a, (bs, d)) => (a, bs, d >= 0)) ||
   198   command_with Keyword.is_theory_goal -- proof
   192   Scan.one not_eof >> (fn a => (a, [], true));
   199     >> (fn (a, (bs, d)) => make_element a bs (d >= 0)) ||
   193 
   200   Scan.one not_eof >> (fn a => make_element a [] true);
   194 in
   201 
   195 
   202 in
   196 fun atom_source src = Source.source stopper (Scan.bulk atom) NONE src;
   203 
   197 
   204 fun element_source src = Source.source stopper (Scan.bulk element) NONE src;
   198 end;
   205 
   199 
   206 end;
   200 end;
   207 
       
   208 end;