src/Pure/Thy/bibtex.scala
changeset 77010 fead2b33acdc
parent 77007 19a7046f90f9
child 77011 3e48f8c6afc9
equal deleted inserted replaced
77009:2342b4cc118f 77010:fead2b33acdc
   383     def is_open: Boolean =
   383     def is_open: Boolean =
   384       kind == Token.Kind.KEYWORD && (source == "{" || source == "(")
   384       kind == Token.Kind.KEYWORD && (source == "{" || source == "(")
   385   }
   385   }
   386 
   386 
   387   case class Chunk(kind: String, tokens: List[Token]) {
   387   case class Chunk(kind: String, tokens: List[Token]) {
   388     val source = tokens.map(_.source).mkString
   388     val source: String = tokens.map(_.source).mkString
   389 
   389 
   390     private val content: Option[List[Token]] =
   390     private val content: Option[List[Token]] =
   391       tokens match {
   391       tokens match {
   392         case Token(Token.Kind.KEYWORD, "@") :: body if body.nonEmpty =>
   392         case Token(Token.Kind.KEYWORD, "@") :: body if body.nonEmpty =>
   393           (body.init.filterNot(_.is_ignored), body.last) match {
   393           (body.init.filterNot(_.is_ignored), body.last) match {
   431   case class Item_Start(kind: String) extends Line_Context
   431   case class Item_Start(kind: String) extends Line_Context
   432   case class Item_Open(kind: String, end: String) extends Line_Context
   432   case class Item_Open(kind: String, end: String) extends Line_Context
   433   case class Item(kind: String, end: String, delim: Delimited) extends Line_Context
   433   case class Item(kind: String, end: String, delim: Delimited) extends Line_Context
   434 
   434 
   435   case class Delimited(quoted: Boolean, depth: Int)
   435   case class Delimited(quoted: Boolean, depth: Int)
   436   val Closed = Delimited(false, 0)
   436   val Closed: Delimited = Delimited(false, 0)
   437 
   437 
   438   private def token(kind: Token.Kind.Value)(source: String): Token = Token(kind, source)
   438   private def token(kind: Token.Kind.Value)(source: String): Token = Token(kind, source)
   439   private def keyword(source: String): Token = Token(Token.Kind.KEYWORD, source)
   439   private def keyword(source: String): Token = Token(Token.Kind.KEYWORD, source)
   440 
   440 
   441 
   441 
   467     private def delimited_depth(delim: Delimited): Parser[(String, Delimited)] =
   467     private def delimited_depth(delim: Delimited): Parser[(String, Delimited)] =
   468       new Parser[(String, Delimited)] {
   468       new Parser[(String, Delimited)] {
   469         require(if (delim.quoted) delim.depth > 0 else delim.depth >= 0,
   469         require(if (delim.quoted) delim.depth > 0 else delim.depth >= 0,
   470           "bad delimiter depth")
   470           "bad delimiter depth")
   471 
   471 
   472         def apply(in: Input) = {
   472         def apply(in: Input): ParseResult[(String, Delimited)] = {
   473           val start = in.offset
   473           val start = in.offset
   474           val end = in.source.length
   474           val end = in.source.length
   475 
   475 
   476           var i = start
   476           var i = start
   477           var q = delim.quoted
   477           var q = delim.quoted
   524     private val identifier =
   524     private val identifier =
   525       """[\x21-\x7f&&[^"#%'(),={}0-9]][\x21-\x7f&&[^"#%'(),={}]]*""".r
   525       """[\x21-\x7f&&[^"#%'(),={}0-9]][\x21-\x7f&&[^"#%'(),={}]]*""".r
   526 
   526 
   527     private val ident = identifier ^^ token(Token.Kind.IDENT)
   527     private val ident = identifier ^^ token(Token.Kind.IDENT)
   528 
   528 
   529     val other_token = "[=#,]".r ^^ keyword | (nat | (ident | space))
   529     val other_token: Parser[Token] = "[=#,]".r ^^ keyword | (nat | (ident | space))
   530 
   530 
   531 
   531 
   532     /* body */
   532     /* body */
   533 
   533 
   534     private val body =
   534     private val body =