| 
34268
 | 
     1  | 
/*  Title:      Pure/Thy/thy_syntax.scala
  | 
| 
 | 
     2  | 
    Author:     Makarius
  | 
| 
 | 
     3  | 
  | 
| 
 | 
     4  | 
Superficial theory syntax: command spans.
  | 
| 
 | 
     5  | 
*/
  | 
| 
 | 
     6  | 
  | 
| 
 | 
     7  | 
package isabelle
  | 
| 
 | 
     8  | 
  | 
| 
 | 
     9  | 
  | 
| 
 | 
    10  | 
class Thy_Syntax
  | 
| 
 | 
    11  | 
{
 | 
| 
 | 
    12  | 
  private val parser = new Outer_Parse.Parser
  | 
| 
 | 
    13  | 
  {
 | 
| 
 | 
    14  | 
    override def filter_proper = false
  | 
| 
 | 
    15  | 
  | 
| 
 | 
    16  | 
    val command_span: Parser[Span] =
  | 
| 
 | 
    17  | 
    {
 | 
| 
 | 
    18  | 
      val whitespace = token("white space", tok => tok.is_space || tok.is_comment)
 | 
| 
 | 
    19  | 
      val command = token("command keyword", _.is_command)
 | 
| 
 | 
    20  | 
      val body = not(rep(whitespace) ~ (command | eof)) ~> not_eof
  | 
| 
 | 
    21  | 
      command ~ rep(body) ^^ { case x ~ ys => x :: ys } | rep1(whitespace) | rep1(body)
 | 
| 
 | 
    22  | 
    }
  | 
| 
 | 
    23  | 
  }
  | 
| 
 | 
    24  | 
  | 
| 
 | 
    25  | 
  type Span = List[Outer_Lex.Token]
  | 
| 
 | 
    26  | 
  | 
| 
 | 
    27  | 
  def parse_spans(toks: List[Outer_Lex.Token]): List[Span] =
  | 
| 
 | 
    28  | 
  {
 | 
| 
 | 
    29  | 
    import parser._
  | 
| 
 | 
    30  | 
  | 
| 
 | 
    31  | 
    parse(rep(command_span), Outer_Lex.reader(toks)) match {
 | 
| 
 | 
    32  | 
      case Success(spans, rest) if rest.atEnd => spans
  | 
| 
 | 
    33  | 
      case bad => error(bad.toString)
  | 
| 
 | 
    34  | 
    }
  | 
| 
 | 
    35  | 
  }
  | 
| 
 | 
    36  | 
}
  |