author | wenzelm |
Tue, 21 Oct 2014 19:20:48 +0200 | |
changeset 58750 | 1b4b005d73c1 |
parent 58749 | 83b0f633190e |
child 58752 | 2077bc9558cf |
permissions | -rw-r--r-- |
58748 | 1 |
/* Title: Tools/jEdit/src/structure_matching.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Structure matcher for Isabelle/Isar outer syntax. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle.jedit |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
12 |
import org.gjt.sp.jedit.textarea.{TextArea, StructureMatcher} |
|
13 |
||
14 |
||
15 |
object Structure_Matching |
|
16 |
{ |
|
17 |
object Isabelle_Matcher extends StructureMatcher |
|
18 |
{ |
|
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
19 |
def find_pair(text_area: TextArea): Option[(Text.Range, Text.Range)] = |
58748 | 20 |
{ |
21 |
val buffer = text_area.getBuffer |
|
22 |
val caret_line = text_area.getCaretLine |
|
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
23 |
val caret = text_area.getCaretPosition |
58748 | 24 |
|
25 |
PIDE.session.recent_syntax match { |
|
58750 | 26 |
case syntax: Outer_Syntax |
27 |
if syntax != Outer_Syntax.empty => |
|
28 |
||
29 |
val limit = PIDE.options.value.int("jedit_structure_limit") max 0 |
|
30 |
||
31 |
def iterator(line: Int, lim: Int = limit): Iterator[Text.Info[Token]] = |
|
32 |
Token_Markup.line_token_iterator(syntax, buffer, line, line + lim) |
|
33 |
||
34 |
def rev_iterator(line: Int, lim: Int = limit): Iterator[Text.Info[Token]] = |
|
35 |
Token_Markup.line_token_reverse_iterator(syntax, buffer, line, line - lim) |
|
36 |
||
37 |
iterator(caret_line, 1).find(info => info.range.touches(caret)) match { |
|
38 |
case Some(Text.Info(range1, tok)) if syntax.command_kind(tok, Keyword.qed_global) => |
|
39 |
rev_iterator(caret_line).dropWhile(info => caret <= info.range.stop). |
|
40 |
find(info => syntax.command_kind(info.info, Keyword.theory)) |
|
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
41 |
match { |
58750 | 42 |
case Some(Text.Info(range2, tok)) |
43 |
if syntax.command_kind(tok, Keyword.theory_goal) => Some((range1, range2)) |
|
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
44 |
case _ => None |
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
45 |
} |
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
46 |
case _ => None |
58748 | 47 |
} |
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
48 |
case _ => None |
58748 | 49 |
} |
50 |
} |
|
51 |
||
58749
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
52 |
def getMatch(text_area: TextArea): StructureMatcher.Match = |
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
53 |
find_pair(text_area) match { |
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
54 |
case Some((_, range)) => |
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
55 |
val line = text_area.getBuffer.getLineOfOffset(range.start) |
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
56 |
new StructureMatcher.Match(Structure_Matching.Isabelle_Matcher, |
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
57 |
line, range.start, line, range.stop) |
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
58 |
case None => null |
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
59 |
} |
83b0f633190e
some structure matching, based on line token iterators;
wenzelm
parents:
58748
diff
changeset
|
60 |
|
58748 | 61 |
def selectMatch(text_area: TextArea) |
62 |
{ |
|
63 |
// FIXME |
|
64 |
} |
|
65 |
} |
|
66 |
} |
|
67 |