src/Pure/General/comment.scala
changeset 75393 87ebf5a50283
parent 69891 def3ec9cdb7e
equal deleted inserted replaced
75388:b3ca4a6ed74b 75393:87ebf5a50283
     5 */
     5 */
     6 
     6 
     7 package isabelle
     7 package isabelle
     8 
     8 
     9 
     9 
    10 object Comment
    10 object Comment {
    11 {
    11   object Kind extends Enumeration {
    12   object Kind extends Enumeration
       
    13   {
       
    14     val COMMENT = Value("formal comment")
    12     val COMMENT = Value("formal comment")
    15     val CANCEL = Value("canceled text")
    13     val CANCEL = Value("canceled text")
    16     val LATEX = Value("embedded LaTeX")
    14     val LATEX = Value("embedded LaTeX")
    17     val MARKER = Value("document marker")
    15     val MARKER = Value("document marker")
    18   }
    16   }
    24       Symbol.marker, Symbol.marker_decoded)
    22       Symbol.marker, Symbol.marker_decoded)
    25 
    23 
    26   lazy val symbols_blanks: Set[Symbol.Symbol] =
    24   lazy val symbols_blanks: Set[Symbol.Symbol] =
    27     Set(Symbol.comment, Symbol.comment_decoded)
    25     Set(Symbol.comment, Symbol.comment_decoded)
    28 
    26 
    29   def content(source: String): String =
    27   def content(source: String): String = {
    30   {
       
    31     def err(): Nothing = error("Malformed formal comment: " + quote(source))
    28     def err(): Nothing = error("Malformed formal comment: " + quote(source))
    32 
    29 
    33     Symbol.explode(source) match {
    30     Symbol.explode(source) match {
    34       case sym :: rest if symbols_blanks(sym) =>
    31       case sym :: rest if symbols_blanks(sym) =>
    35         val body = if (symbols_blanks(sym)) rest.dropWhile(Symbol.is_blank) else rest
    32         val body = if (symbols_blanks(sym)) rest.dropWhile(Symbol.is_blank) else rest
    37         catch { case ERROR(_) => err() }
    34         catch { case ERROR(_) => err() }
    38       case _ => err()
    35       case _ => err()
    39     }
    36     }
    40   }
    37   }
    41 
    38 
    42   trait Parsers extends Scan.Parsers
    39   trait Parsers extends Scan.Parsers {
    43   {
       
    44    def comment_prefix: Parser[String] =
    40    def comment_prefix: Parser[String] =
    45      one(symbols_blanks) ~ many(Symbol.is_blank) ^^ { case a ~ b => a + b.mkString } |
    41      one(symbols_blanks) ~ many(Symbol.is_blank) ^^ { case a ~ b => a + b.mkString } |
    46      one(symbols)
    42      one(symbols)
    47 
    43 
    48    def comment_cartouche: Parser[String] =
    44    def comment_cartouche: Parser[String] =
    49       comment_prefix ~ cartouche ^^ { case a ~ b => a + b }
    45       comment_prefix ~ cartouche ^^ { case a ~ b => a + b }
    50 
    46 
    51     def comment_cartouche_line(ctxt: Scan.Line_Context): Parser[(String, Scan.Line_Context)] =
    47     def comment_cartouche_line(ctxt: Scan.Line_Context): Parser[(String, Scan.Line_Context)] = {
    52     {
       
    53       def cartouche_context(d: Int): Scan.Line_Context =
    48       def cartouche_context(d: Int): Scan.Line_Context =
    54         if (d == 0) Scan.Finished else Scan.Cartouche_Comment(d)
    49         if (d == 0) Scan.Finished else Scan.Cartouche_Comment(d)
    55 
    50 
    56       ctxt match {
    51       ctxt match {
    57         case Scan.Finished =>
    52         case Scan.Finished =>