src/Tools/jEdit/src/token_markup.scala
changeset 58809 3c34490ccd4c
parent 58802 3cc68ec558b0
child 59063 b3c45d0e4fe1
equal deleted inserted replaced
58806:bb5ab5fce93a 58809:3c34490ccd4c
   252           (i, tok) => i - tok.source.length)
   252           (i, tok) => i - tok.source.length)
   253       (i, tok) <- stops zip tokens.reverseIterator
   253       (i, tok) <- stops zip tokens.reverseIterator
   254     } yield Text.Info(Text.Range(i - tok.source.length, i), tok)
   254     } yield Text.Info(Text.Range(i - tok.source.length, i), tok)
   255 
   255 
   256 
   256 
   257   /* command span */
   257   /* command spans */
   258 
   258 
   259   def command_span(syntax: Outer_Syntax, buffer: JEditBuffer, offset: Text.Offset)
   259   def command_span(syntax: Outer_Syntax, buffer: JEditBuffer, offset: Text.Offset)
   260     : Option[Text.Info[Command_Span.Span]] =
   260     : Option[Text.Info[Command_Span.Span]] =
   261   {
   261   {
   262     if (JEdit_Lib.buffer_range(buffer).contains(offset)) {
   262     if (JEdit_Lib.buffer_range(buffer).contains(offset)) {
   279         map({ case (i, span) => Text.Info(Text.Range(i, i + span.length), span) }).
   279         map({ case (i, span) => Text.Info(Text.Range(i, i + span.length), span) }).
   280         find(_.range.contains(offset))
   280         find(_.range.contains(offset))
   281     }
   281     }
   282     else None
   282     else None
   283   }
   283   }
       
   284 
       
   285   private def _command_span_iterator(
       
   286       syntax: Outer_Syntax,
       
   287       buffer: JEditBuffer,
       
   288       offset: Text.Offset,
       
   289       next_offset: Text.Range => Text.Offset): Iterator[Text.Info[Command_Span.Span]] =
       
   290     new Iterator[Text.Info[Command_Span.Span]]
       
   291     {
       
   292       private var next_span = command_span(syntax, buffer, offset)
       
   293       def hasNext: Boolean = next_span.isDefined
       
   294       def next: Text.Info[Command_Span.Span] =
       
   295       {
       
   296         val span = next_span.getOrElse(Iterator.empty.next)
       
   297         next_span = command_span(syntax, buffer, next_offset(span.range))
       
   298         span
       
   299       }
       
   300     }
       
   301 
       
   302   def command_span_iterator(syntax: Outer_Syntax, buffer: JEditBuffer, offset: Text.Offset)
       
   303       : Iterator[Text.Info[Command_Span.Span]] =
       
   304     _command_span_iterator(syntax, buffer, offset max 0, range => range.stop)
       
   305 
       
   306   def command_span_reverse_iterator(syntax: Outer_Syntax, buffer: JEditBuffer, offset: Text.Offset)
       
   307       : Iterator[Text.Info[Command_Span.Span]] =
       
   308     _command_span_iterator(syntax, buffer,
       
   309       (offset min buffer.getLength) - 1, range => range.start - 1)
   284 
   310 
   285 
   311 
   286   /* token marker */
   312   /* token marker */
   287 
   313 
   288   class Marker(mode: String) extends TokenMarker
   314   class Marker(mode: String) extends TokenMarker