| author | wenzelm | 
| Sun, 07 May 2017 13:20:24 +0200 | |
| changeset 65751 | 426d4bf3b9bb | 
| parent 64824 | 330ec9bc4b75 | 
| child 65874 | bd45c8ebc214 | 
| permissions | -rw-r--r-- | 
| 59720 | 1 | /* Title: Pure/General/antiquote.scala | 
| 55511 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 2 | Author: Makarius | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 3 | |
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 4 | Antiquotations within plain text. | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 5 | */ | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 6 | |
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 7 | package isabelle | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 8 | |
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 9 | |
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 10 | object Antiquote | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 11 | {
 | 
| 61492 | 12 |   sealed abstract class Antiquote { def source: String }
 | 
| 55511 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 13 | case class Text(source: String) extends Antiquote | 
| 61471 | 14 | case class Control(source: String) extends Antiquote | 
| 55511 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 15 | case class Antiq(source: String) extends Antiquote | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 16 | |
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 17 | |
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 18 | /* parsers */ | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 19 | |
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 20 | object Parsers extends Parsers | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 21 | |
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 22 | trait Parsers extends Scan.Parsers | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 23 |   {
 | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 24 | private val txt: Parser[String] = | 
| 61491 
97261e6c1d42
another antiquotation short form: undecorated cartouche as alias for @{text};
 wenzelm parents: 
61481diff
changeset | 25 | rep1(many1(s => !Symbol.is_control(s) && !Symbol.is_open(s) && s != "@") | | 
| 61471 | 26 |         "@" <~ guard(opt_term(one(s => s != "{")))) ^^ (x => x.mkString)
 | 
| 27 | ||
| 28 | val control: Parser[String] = | |
| 61595 | 29 |       opt(one(Symbol.is_control)) ~ cartouche ^^ { case Some(x) ~ y => x + y case None ~ x => x } |
 | 
| 30 | one(Symbol.is_control) | |
| 55511 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 31 | |
| 55512 | 32 | val antiq_other: Parser[String] = | 
| 33 | many1(s => s != "\"" && s != "`" && s != "}" && !Symbol.is_open(s) && !Symbol.is_close(s)) | |
| 34 | ||
| 35 | private val antiq_body: Parser[String] = | |
| 36 |       quoted("\"") | (quoted("`") | (cartouche | antiq_other))
 | |
| 55511 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 37 | |
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 38 | val antiq: Parser[String] = | 
| 55512 | 39 |       "@{" ~ rep(antiq_body) ~ "}" ^^ { case x ~ y ~ z => x + y.mkString + z }
 | 
| 55511 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 40 | |
| 55512 | 41 | val antiquote: Parser[Antiquote] = | 
| 61481 | 42 | txt ^^ (x => Text(x)) | (control ^^ (x => Control(x)) | antiq ^^ (x => Antiq(x))) | 
| 55511 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 43 | } | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 44 | |
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 45 | |
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 46 | /* read */ | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 47 | |
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 48 | def read(input: CharSequence): List[Antiquote] = | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 49 |   {
 | 
| 64824 | 50 |     Parsers.parseAll(Parsers.rep(Parsers.antiquote), Scan.char_reader(input)) match {
 | 
| 55511 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 51 | case Parsers.Success(xs, _) => xs | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 52 | case Parsers.NoSuccess(_, next) => | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 53 |         error("Malformed quotation/antiquotation source" +
 | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 54 | Position.here(Position.Line(next.pos.line))) | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 55 | } | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 56 | } | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 57 | } | 
| 
984e210d412e
antiquotations within plain text: Scala version in accordance to ML;
 wenzelm parents: diff
changeset | 58 |