src/Pure/PIDE/document.scala
changeset 46178 1c5c88f6feb5
parent 46152 793cecd4ffc0
child 46198 cd040c5772de
equal deleted inserted replaced
46177:adac34829e10 46178:1c5c88f6feb5
   237     def command_state(command: Command): Command.State
   237     def command_state(command: Command): Command.State
   238     def convert(i: Text.Offset): Text.Offset
   238     def convert(i: Text.Offset): Text.Offset
   239     def convert(range: Text.Range): Text.Range
   239     def convert(range: Text.Range): Text.Range
   240     def revert(i: Text.Offset): Text.Offset
   240     def revert(i: Text.Offset): Text.Offset
   241     def revert(range: Text.Range): Text.Range
   241     def revert(range: Text.Range): Text.Range
   242     def cumulate_markup[A](range: Text.Range)(body: Markup_Tree.Cumulate[A]): Stream[Text.Info[A]]
   242     def cumulate_markup[A](range: Text.Range, info: A, elements: Option[Set[String]],
   243     def select_markup[A](range: Text.Range)(body: Markup_Tree.Select[A])
   243       result: PartialFunction[(A, Text.Markup), A]): Stream[Text.Info[A]]
   244       : Stream[Text.Info[Option[A]]]
   244     def select_markup[A](range: Text.Range, elements: Option[Set[String]],
       
   245       result: PartialFunction[Text.Markup, A]): Stream[Text.Info[Option[A]]]
   245   }
   246   }
   246 
   247 
   247   type Assign =
   248   type Assign =
   248    (List[(Document.Command_ID, Option[Document.Exec_ID])],  // exec state assignment
   249    (List[(Document.Command_ID, Option[Document.Exec_ID])],  // exec state assignment
   249     List[(String, Option[Document.Command_ID])])  // last exec
   250     List[(String, Option[Document.Command_ID])])  // last exec
   469         def convert(offset: Text.Offset) = (offset /: edits)((i, edit) => edit.convert(i))
   470         def convert(offset: Text.Offset) = (offset /: edits)((i, edit) => edit.convert(i))
   470         def revert(offset: Text.Offset) = (offset /: reverse_edits)((i, edit) => edit.revert(i))
   471         def revert(offset: Text.Offset) = (offset /: reverse_edits)((i, edit) => edit.revert(i))
   471         def convert(range: Text.Range) = (range /: edits)((r, edit) => edit.convert(r))
   472         def convert(range: Text.Range) = (range /: edits)((r, edit) => edit.convert(r))
   472         def revert(range: Text.Range) = (range /: reverse_edits)((r, edit) => edit.revert(r))
   473         def revert(range: Text.Range) = (range /: reverse_edits)((r, edit) => edit.revert(r))
   473 
   474 
   474         def cumulate_markup[A](range: Text.Range)(body: Markup_Tree.Cumulate[A])
   475         def cumulate_markup[A](range: Text.Range, info: A, elements: Option[Set[String]],
   475           : Stream[Text.Info[A]] =
   476           result: PartialFunction[(A, Text.Markup), A]): Stream[Text.Info[A]] =
   476         {
   477         {
   477           val info = body.info
       
   478           val result = body.result
       
   479 
       
   480           val former_range = revert(range)
   478           val former_range = revert(range)
   481           for {
   479           for {
   482             (command, command_start) <- node.command_range(former_range).toStream
   480             (command, command_start) <- node.command_range(former_range).toStream
   483             Text.Info(r0, a) <- command_state(command).markup.
   481             Text.Info(r0, a) <- command_state(command).markup.
   484               cumulate((former_range - command_start).restrict(command.range))(
   482               cumulate[A]((former_range - command_start).restrict(command.range), info, elements,
   485                 Markup_Tree.Cumulate[A](info,
   483                 {
   486                   {
   484                   case (a, Text.Info(r0, b))
   487                     case (a, Text.Info(r0, b))
   485                   if result.isDefinedAt((a, Text.Info(convert(r0 + command_start), b))) =>
   488                     if result.isDefinedAt((a, Text.Info(convert(r0 + command_start), b))) =>
   486                     result((a, Text.Info(convert(r0 + command_start), b)))
   489                       result((a, Text.Info(convert(r0 + command_start), b)))
   487                 })
   490                   },
       
   491                   body.elements))
       
   492           } yield Text.Info(convert(r0 + command_start), a)
   488           } yield Text.Info(convert(r0 + command_start), a)
   493         }
   489         }
   494 
   490 
   495         def select_markup[A](range: Text.Range)(body: Markup_Tree.Select[A])
   491         def select_markup[A](range: Text.Range, elements: Option[Set[String]],
   496           : Stream[Text.Info[Option[A]]] =
   492           result: PartialFunction[Text.Markup, A]): Stream[Text.Info[Option[A]]] =
   497         {
   493         {
   498           val result = body.result
       
   499           val result1 =
   494           val result1 =
   500             new PartialFunction[(Option[A], Text.Markup), Option[A]] {
   495             new PartialFunction[(Option[A], Text.Markup), Option[A]] {
   501               def isDefinedAt(arg: (Option[A], Text.Markup)): Boolean = result.isDefinedAt(arg._2)
   496               def isDefinedAt(arg: (Option[A], Text.Markup)): Boolean = result.isDefinedAt(arg._2)
   502               def apply(arg: (Option[A], Text.Markup)): Option[A] = Some(result(arg._2))
   497               def apply(arg: (Option[A], Text.Markup)): Option[A] = Some(result(arg._2))
   503             }
   498             }
   504           cumulate_markup(range)(Markup_Tree.Cumulate[Option[A]](None, result1, body.elements))
   499           cumulate_markup(range, None, elements, result1)
   505         }
   500         }
   506       }
   501       }
   507     }
   502     }
   508   }
   503   }
   509 }
   504 }