src/Pure/Thy/document_source.ML
author wenzelm
Fri, 08 Mar 2019 17:05:23 +0100
changeset 69876 b49bd228ac8a
child 69887 b9985133805d
permissions -rw-r--r--
clarified modules; uniform "tag" parser;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
69876
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/document_source.ML
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
     3
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
     4
Document source for presentation.
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
     5
*)
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
     6
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
     7
signature DOCUMENT_SOURCE =
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
     8
sig
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
     9
  val is_white: Token.T -> bool
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    10
  val is_black: Token.T -> bool
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    11
  val is_white_comment: Token.T -> bool
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    12
  val is_black_comment: Token.T -> bool
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    13
  val is_improper: Token.T -> bool
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    14
  val improper: Token.T list parser
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    15
  val improper_end: Token.T list parser
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    16
  val blank_end: Token.T list parser
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    17
  val tag: string parser
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    18
  val tags: string list parser
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    19
end;
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    20
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    21
structure Document_Source: DOCUMENT_SOURCE =
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    22
struct
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    23
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    24
(* white space and comments *)
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    25
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    26
(*NB: arranging white space around command spans is a black art*)
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    27
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    28
val is_white = Token.is_space orf Token.is_informal_comment;
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    29
val is_black = not o is_white;
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    30
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    31
val is_white_comment = Token.is_informal_comment;
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    32
val is_black_comment = Token.is_formal_comment;
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    33
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    34
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    35
val space_proper =
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    36
  Scan.one Token.is_blank -- Scan.many is_white_comment -- Scan.one is_black;
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    37
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    38
val is_improper = not o (is_black orf Token.is_begin_ignore orf Token.is_end_ignore);
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    39
val improper = Scan.many is_improper;
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    40
val improper_end = Scan.repeat (Scan.unless space_proper (Scan.one is_improper));
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    41
val blank_end = Scan.repeat (Scan.unless space_proper (Scan.one Token.is_blank));
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    42
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    43
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    44
(* tags *)
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    45
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    46
val tag_name = Parse.group (fn () => "document tag name") (Parse.short_ident || Parse.string);
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    47
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    48
val tag = (improper -- Parse.$$$ "%" -- improper) |-- Parse.!!! (tag_name --| blank_end);
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    49
val tags = Scan.repeat tag;
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    50
b49bd228ac8a clarified modules;
wenzelm
parents:
diff changeset
    51
end;