src/Pure/Isar/outer_syntax.scala
changeset 57905 c0c5652e796e
parent 57901 e1abca2527da
child 57906 020df63dd0a9
equal deleted inserted replaced
57904:922273b7bf8a 57905:c0c5652e796e
   150     }
   150     }
   151     (toks.toList, ctxt)
   151     (toks.toList, ctxt)
   152   }
   152   }
   153 
   153 
   154 
   154 
       
   155   /* parse_spans */
       
   156 
       
   157   def parse_spans(toks: List[Token]): List[Command_Span.Span] =
       
   158   {
       
   159     val result = new mutable.ListBuffer[Command_Span.Span]
       
   160     val content = new mutable.ListBuffer[Token]
       
   161     val improper = new mutable.ListBuffer[Token]
       
   162 
       
   163     def ship(span: List[Token])
       
   164     {
       
   165       val kind =
       
   166         if (!span.isEmpty && span.head.is_command && !span.exists(_.is_error))
       
   167           Command_Span.Command_Span(span.head.source)
       
   168         else if (span.forall(_.is_improper)) Command_Span.Ignored_Span
       
   169         else Command_Span.Malformed_Span
       
   170       result += Command_Span.Span(kind, span)
       
   171     }
       
   172 
       
   173     def flush()
       
   174     {
       
   175       if (!content.isEmpty) { ship(content.toList); content.clear }
       
   176       if (!improper.isEmpty) { ship(improper.toList); improper.clear }
       
   177     }
       
   178 
       
   179     for (tok <- toks) {
       
   180       if (tok.is_command) { flush(); content += tok }
       
   181       else if (tok.is_improper) improper += tok
       
   182       else { content ++= improper; improper.clear; content += tok }
       
   183     }
       
   184     flush()
       
   185 
       
   186     result.toList
       
   187   }
       
   188 
       
   189 
   155   /* language context */
   190   /* language context */
   156 
   191 
   157   def set_language_context(context: Completion.Language_Context): Outer_Syntax =
   192   def set_language_context(context: Completion.Language_Context): Outer_Syntax =
   158     new Outer_Syntax(keywords, lexicon, completion, context, has_tokens)
   193     new Outer_Syntax(keywords, lexicon, completion, context, has_tokens)
   159 
   194