src/Pure/Isar/outer_syntax.scala
changeset 68729 3a02b424d5fb
parent 67005 11fca474d87a
child 71601 97ccf48c2f0c
equal deleted inserted replaced
68728:c07f6fa02c59 68729:3a02b424d5fb
   159 
   159 
   160   def parse_spans(toks: List[Token]): List[Command_Span.Span] =
   160   def parse_spans(toks: List[Token]): List[Command_Span.Span] =
   161   {
   161   {
   162     val result = new mutable.ListBuffer[Command_Span.Span]
   162     val result = new mutable.ListBuffer[Command_Span.Span]
   163     val content = new mutable.ListBuffer[Token]
   163     val content = new mutable.ListBuffer[Token]
   164     val improper = new mutable.ListBuffer[Token]
   164     val ignored = new mutable.ListBuffer[Token]
   165 
   165 
   166     def ship(span: List[Token])
   166     def ship(span: List[Token])
   167     {
   167     {
   168       val kind =
   168       val kind =
   169         if (span.forall(_.is_improper)) Command_Span.Ignored_Span
   169         if (span.forall(_.is_ignored)) Command_Span.Ignored_Span
   170         else if (span.exists(_.is_error)) Command_Span.Malformed_Span
   170         else if (span.exists(_.is_error)) Command_Span.Malformed_Span
   171         else
   171         else
   172           span.find(_.is_command) match {
   172           span.find(_.is_command) match {
   173             case None => Command_Span.Malformed_Span
   173             case None => Command_Span.Malformed_Span
   174             case Some(cmd) =>
   174             case Some(cmd) =>
   184     }
   184     }
   185 
   185 
   186     def flush()
   186     def flush()
   187     {
   187     {
   188       if (content.nonEmpty) { ship(content.toList); content.clear }
   188       if (content.nonEmpty) { ship(content.toList); content.clear }
   189       if (improper.nonEmpty) { ship(improper.toList); improper.clear }
   189       if (ignored.nonEmpty) { ship(ignored.toList); ignored.clear }
   190     }
   190     }
   191 
   191 
   192     for (tok <- toks) {
   192     for (tok <- toks) {
   193       if (tok.is_improper) improper += tok
   193       if (tok.is_ignored) ignored += tok
   194       else if (keywords.is_before_command(tok) ||
   194       else if (keywords.is_before_command(tok) ||
   195         tok.is_command &&
   195         tok.is_command &&
   196           (!content.exists(keywords.is_before_command(_)) || content.exists(_.is_command)))
   196           (!content.exists(keywords.is_before_command(_)) || content.exists(_.is_command)))
   197       { flush(); content += tok }
   197       { flush(); content += tok }
   198       else { content ++= improper; improper.clear; content += tok }
   198       else { content ++= ignored; ignored.clear; content += tok }
   199     }
   199     }
   200     flush()
   200     flush()
   201 
   201 
   202     result.toList
   202     result.toList
   203   }
   203   }