src/Pure/Thy/thy_syntax.scala
author wenzelm
Sat, 07 Aug 2010 22:09:52 +0200
changeset 38230 ed147003de4b
parent 36956 21be4832c362
child 38239 89a4d1028fb3
permissions -rw-r--r--
simplified type XML.Tree: embed Markup directly, avoid slightly odd triple; XML.cache_tree: actually store XML.Text as well; added Isabelle_Process.Result.properties;

/*  Title:      Pure/Thy/thy_syntax.scala
    Author:     Makarius

Superficial theory syntax: command spans.
*/

package isabelle


object Thy_Syntax
{
  private val parser = new Parse.Parser
  {
    override def filter_proper = false

    val command_span: Parser[Span] =
    {
      val whitespace = token("white space", _.is_ignored)
      val command = token("command keyword", _.is_command)
      val body = not(rep(whitespace) ~ (command | eof)) ~> not_eof
      command ~ rep(body) ^^ { case x ~ ys => x :: ys } | rep1(whitespace) | rep1(body)
    }
  }

  type Span = List[Token]

  def parse_spans(toks: List[Token]): List[Span] =
  {
    import parser._

    parse(rep(command_span), Token.reader(toks)) match {
      case Success(spans, rest) if rest.atEnd => spans
      case bad => error(bad.toString)
    }
  }
}