doc-src/rail.ML
changeset 32805 9b535493ac8d
parent 32449 696d64ed85da
child 36973 b0033a307d1f
equal deleted inserted replaced
32804:ca430e6aee1c 32805:9b535493ac8d
    97     (idx ^
    97     (idx ^
    98     (Output.output name
    98     (Output.output name
    99       |> (if markup = "" then I else enclose ("\\" ^ markup ^ "{") "}")
    99       |> (if markup = "" then I else enclose ("\\" ^ markup ^ "{") "}")
   100       |> (if ! ThyOutput.quotes then quote else I)
   100       |> (if ! ThyOutput.quotes then quote else I)
   101       |> (if ! ThyOutput.display then enclose "\\begin{isabelle}%\n" "%\n\\end{isabelle}"
   101       |> (if ! ThyOutput.display then enclose "\\begin{isabelle}%\n" "%\n\\end{isabelle}"
   102 	  else hyper o enclose "\\mbox{\\isa{" "}}")), style)
   102           else hyper o enclose "\\mbox{\\isa{" "}}")), style)
   103   else ("Bad " ^ kind ^ " " ^ name, false)
   103   else ("Bad " ^ kind ^ " " ^ name, false)
   104   end;
   104   end;
   105 end;
   105 end;
   106 
   106 
   107 val blanks =
   107 val blanks =
   145   (Scan.one is_identifier_start :::
   145   (Scan.one is_identifier_start :::
   146     Scan.repeat (Scan.one is_identifier_rest || ($$ "\\" |-- $$ "'"))
   146     Scan.repeat (Scan.one is_identifier_rest || ($$ "\\" |-- $$ "'"))
   147   ) >> (Identifier o enclose "\\isa{" "}" o Output.output o implode) ||
   147   ) >> (Identifier o enclose "\\isa{" "}" o Output.output o implode) ||
   148   scan_link >> (decode_link ctxt) >>
   148   scan_link >> (decode_link ctxt) >>
   149     (fn (txt, style) =>
   149     (fn (txt, style) =>
   150 	if style then Special_Identifier(txt)
   150         if style then Special_Identifier(txt)
   151 	else Identifier(txt))
   151         else Identifier(txt))
   152 end;
   152 end;
   153 
   153 
   154 fun scan_anot ctxt =
   154 fun scan_anot ctxt =
   155   let val scan_anot =
   155   let val scan_anot =
   156     Scan.many (fn s =>
   156     Scan.many (fn s =>
   167 fun scan_text ctxt =
   167 fun scan_text ctxt =
   168   let
   168   let
   169     val text_sq =
   169     val text_sq =
   170       Scan.repeat (
   170       Scan.repeat (
   171         Scan.one (fn s =>
   171         Scan.one (fn s =>
   172 	  s <> "\n" andalso
   172           s <> "\n" andalso
   173 	  s <> "\t" andalso
   173           s <> "\t" andalso
   174 	  s <> "'" andalso
   174           s <> "'" andalso
   175 	  s <> "\\" andalso
   175           s <> "\\" andalso
   176 	  Symbol.is_regular s) ||
   176           Symbol.is_regular s) ||
   177 	($$ "\\" |-- $$ "'")
   177         ($$ "\\" |-- $$ "'")
   178       ) >> implode
   178       ) >> implode
   179   fun quoted scan = $$ "'" |-- scan --| $$ "'";
   179   fun quoted scan = $$ "'" |-- scan --| $$ "'";
   180   in
   180   in
   181   quoted scan_link >> (fst o (decode_link ctxt)) ||
   181   quoted scan_link >> (fst o (decode_link ctxt)) ||
   182   quoted text_sq >> (enclose "\\isa{" "}" o Output.output)
   182   quoted text_sq >> (enclose "\\isa{" "}" o Output.output)
   303 and parse_body1 x =
   303 and parse_body1 x =
   304   (
   304   (
   305   parse_body2 -- ($$$ "*" |-- !!! "body4e expected" (parse_body4e)) >>
   305   parse_body2 -- ($$$ "*" |-- !!! "body4e expected" (parse_body4e)) >>
   306     (fn (body1, body2) =>
   306     (fn (body1, body2) =>
   307       if is_empty body2 then
   307       if is_empty body2 then
   308 	add_body(PLUS, new_empty_body, rev_body body1)
   308         add_body(PLUS, new_empty_body, rev_body body1)
   309       else
   309       else
   310 	add_body(BAR, new_empty_body, add_body (PLUS, body1, rev_body body2)) ) ||
   310         add_body(BAR, new_empty_body, add_body (PLUS, body1, rev_body body2)) ) ||
   311   parse_body2 -- ($$$ "+" |-- !!! "body4e expected" (parse_body4e)) >>
   311   parse_body2 -- ($$$ "+" |-- !!! "body4e expected" (parse_body4e)) >>
   312     (fn (body1, body2) => new_body (PLUS, body1, rev_body body2) ) ||
   312     (fn (body1, body2) => new_body (PLUS, body1, rev_body body2) ) ||
   313   parse_body2e
   313   parse_body2e
   314   ) x
   314   ) x
   315 and parse_body2e x =
   315 and parse_body2e x =
   363 fun getynext (Body_Pos(_,_,_,_,_,_,ynext)) = ynext;
   363 fun getynext (Body_Pos(_,_,_,_,_,_,ynext)) = ynext;
   364 
   364 
   365 fun position_body (body as Body(kind, text, annot, id, bodies), ystart) =
   365 fun position_body (body as Body(kind, text, annot, id, bodies), ystart) =
   366   let fun max (x,y) = if x > y then x else y
   366   let fun max (x,y) = if x > y then x else y
   367     fun set_body_position (Body(kind, text, annot, id, bodies), ystart, ynext) =
   367     fun set_body_position (Body(kind, text, annot, id, bodies), ystart, ynext) =
   368 	  Body_Pos(kind, text, annot, id, bodies, ystart, ynext)
   368           Body_Pos(kind, text, annot, id, bodies, ystart, ynext)
   369     fun pos_bodies_cat ([],_,ynext,liste) = (liste, ynext)
   369     fun pos_bodies_cat ([],_,ynext,liste) = (liste, ynext)
   370       | pos_bodies_cat (x::xs, ystart, ynext, liste) =
   370       | pos_bodies_cat (x::xs, ystart, ynext, liste) =
   371 	  if is_kind_of CR x then
   371           if is_kind_of CR x then
   372 	      (case set_body_position(x, ystart, ynext+1) of
   372               (case set_body_position(x, ystart, ynext+1) of
   373 		body as Body_Pos(_,_,_,_,_,_,ynext1) =>
   373                 body as Body_Pos(_,_,_,_,_,_,ynext1) =>
   374 		  pos_bodies_cat(xs, ynext1, max(ynext,ynext1), liste@[body])
   374                   pos_bodies_cat(xs, ynext1, max(ynext,ynext1), liste@[body])
   375 	      )
   375               )
   376 	  else
   376           else
   377 	      (case position_body(x, ystart) of
   377               (case position_body(x, ystart) of
   378 		body as Body_Pos(_,_,_,_,_,_,ynext1) =>
   378                 body as Body_Pos(_,_,_,_,_,_,ynext1) =>
   379 		  pos_bodies_cat(xs, ystart, max(ynext,ynext1), liste@[body])
   379                   pos_bodies_cat(xs, ystart, max(ynext,ynext1), liste@[body])
   380 	      )
   380               )
   381     fun pos_bodies_bar_plus ([],_,ynext,liste) = (liste, ynext)
   381     fun pos_bodies_bar_plus ([],_,ynext,liste) = (liste, ynext)
   382       | pos_bodies_bar_plus (x::xs, ystart, ynext, liste) =
   382       | pos_bodies_bar_plus (x::xs, ystart, ynext, liste) =
   383 	  (case position_body(x, ystart) of
   383           (case position_body(x, ystart) of
   384 	    body as Body_Pos(_,_,_,_,_,_,ynext1) =>
   384             body as Body_Pos(_,_,_,_,_,_,ynext1) =>
   385 	      pos_bodies_bar_plus(xs, ynext1, max(ynext,ynext1), liste@[body])
   385               pos_bodies_bar_plus(xs, ynext1, max(ynext,ynext1), liste@[body])
   386 	  )
   386           )
   387   in
   387   in
   388   (case kind of
   388   (case kind of
   389     CAT => (case pos_bodies_cat(bodies,ystart,ystart+1,[]) of
   389     CAT => (case pos_bodies_cat(bodies,ystart,ystart+1,[]) of
   390 	      (bodiesPos, ynext) =>
   390               (bodiesPos, ynext) =>
   391 		Body_Pos(kind, text, annot, id, bodiesPos, ystart, ynext))
   391                 Body_Pos(kind, text, annot, id, bodiesPos, ystart, ynext))
   392   | BAR => (case pos_bodies_bar_plus(bodies,ystart,ystart+1,[]) of
   392   | BAR => (case pos_bodies_bar_plus(bodies,ystart,ystart+1,[]) of
   393 	      (bodiesPos, ynext) =>
   393               (bodiesPos, ynext) =>
   394 		Body_Pos(kind, text, annot, id, bodiesPos, ystart, ynext))
   394                 Body_Pos(kind, text, annot, id, bodiesPos, ystart, ynext))
   395   | PLUS => (case pos_bodies_bar_plus(bodies,ystart,ystart+1,[]) of
   395   | PLUS => (case pos_bodies_bar_plus(bodies,ystart,ystart+1,[]) of
   396 	      (bodiesPos, ynext) =>
   396               (bodiesPos, ynext) =>
   397 		Body_Pos(kind, text, annot, id, bodiesPos, ystart, ynext))
   397                 Body_Pos(kind, text, annot, id, bodiesPos, ystart, ynext))
   398   | CR => set_body_position(body, ystart, ystart+3)
   398   | CR => set_body_position(body, ystart, ystart+3)
   399   | EMPTY => set_body_position(body, ystart, ystart+1)
   399   | EMPTY => set_body_position(body, ystart, ystart+1)
   400   | ANNOTE => set_body_position(body, ystart, ystart+1)
   400   | ANNOTE => set_body_position(body, ystart, ystart+1)
   401   | IDENT => set_body_position(body, ystart, ystart+1)
   401   | IDENT => set_body_position(body, ystart, ystart+1)
   402   | STRING => set_body_position(body, ystart, ystart+1)
   402   | STRING => set_body_position(body, ystart, ystart+1)
   404   end;
   404   end;
   405 
   405 
   406 fun format_body (Body_Pos(EMPTY,_,_,_,_,_,_), _) = ""
   406 fun format_body (Body_Pos(EMPTY,_,_,_,_,_,_), _) = ""
   407   | format_body (Body_Pos(CAT,_,_,_,bodies,_,_), cent) =
   407   | format_body (Body_Pos(CAT,_,_,_,bodies,_,_), cent) =
   408     let fun format_bodies([]) = ""
   408     let fun format_bodies([]) = ""
   409 	  | format_bodies(x::xs) = format_body (x, "") ^ format_bodies(xs)
   409           | format_bodies(x::xs) = format_body (x, "") ^ format_bodies(xs)
   410     in
   410     in
   411       format_bodies(bodies)
   411       format_bodies(bodies)
   412     end
   412     end
   413   | format_body (Body_Pos(BAR,_,_,_,bodies,_,_),cent) =
   413   | format_body (Body_Pos(BAR,_,_,_,bodies,_,_),cent) =
   414     let fun format_bodies([]) = "\\rail@endbar\n"
   414     let fun format_bodies([]) = "\\rail@endbar\n"
   415 	  | format_bodies(x::xs) =
   415           | format_bodies(x::xs) =
   416 	      "\\rail@nextbar{" ^ string_of_int(getystart(x)) ^"}\n" ^
   416               "\\rail@nextbar{" ^ string_of_int(getystart(x)) ^"}\n" ^
   417 	      format_body(x, "") ^ format_bodies(xs)
   417               format_body(x, "") ^ format_bodies(xs)
   418     in
   418     in
   419       "\\rail@bar\n" ^ format_body(hd(bodies), "") ^ format_bodies(tl(bodies))
   419       "\\rail@bar\n" ^ format_body(hd(bodies), "") ^ format_bodies(tl(bodies))
   420     end
   420     end
   421   | format_body (Body_Pos(PLUS,_,_,_,x::y::xs,_,_),cent) =
   421   | format_body (Body_Pos(PLUS,_,_,_,x::y::xs,_,_),cent) =
   422       "\\rail@plus\n" ^ format_body(x, cent) ^
   422       "\\rail@plus\n" ^ format_body(x, cent) ^