From 7cfc4e5146be5666419451bdd516f1f3f264d24a Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Sun, 25 Jan 2015 14:42:51 +0100 Subject: Imported Upstream version 8.5~beta1+dfsg --- ide/sentence.ml | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 ide/sentence.ml (limited to 'ide/sentence.ml') diff --git a/ide/sentence.ml b/ide/sentence.ml new file mode 100644 index 00000000..dd6b10a4 --- /dev/null +++ b/ide/sentence.ml @@ -0,0 +1,126 @@ +(************************************************************************) +(* v * The Coq Proof Assistant / The Coq Development Team *) +(* + (* This shouldn't happen frequently. Either: + - we are at eof, with indeed an unfinished sentence. + - we have just inserted an opening of comment or string. + - the inserted text ends with a "." that interacts with the "." + found by [grab_ending_dot] to form a non-ending "..". + In any case, we retag up to eof, since this isn't that costly. *) + if not stop#is_end then + let eoi = buffer#get_iter_at_mark (`NAME "stop_of_input") in + try split_slice_lax buffer start eoi + with Coq_lex.Unterminated -> () + with StartError -> + buffer#apply_tag ~start:soi ~stop:soi#forward_char Tags.Script.error + +let tag_all buffer = + let soi = buffer#get_iter_at_mark (`NAME "start_of_input") in + let eoi = buffer#get_iter_at_mark (`NAME "stop_of_input") in + try split_slice_lax buffer soi eoi + with Coq_lex.Unterminated -> () + +(** Search a sentence around some position *) + +let find buffer (start:GText.iter) = + let soi = buffer#get_iter_at_mark (`NAME "start_of_input") in + try + let start = grab_sentence_start start soi in + let stop = grab_sentence_stop start in + (* Is this phrase non-empty and complete ? *) + if stop#compare start > 0 && is_sentence_end stop#backward_char + then Some (start,stop) + else None + with StartError -> None -- cgit v1.2.3