author | wenzelm |
Tue, 23 Dec 2014 16:00:38 +0100 | |
changeset 59183 | ec83638b6bfb |
parent 59091 | 4c8205fe3644 |
child 59286 | ac74eedb910a |
permissions | -rw-r--r-- |
43282
5d294220ca43
moved sources -- eliminated Netbeans artifact of jedit package directory;
wenzelm
parents:
40792
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/isabelle_sidekick.scala |
36760 | 2 |
Author: Fabian Immler, TU Munich |
3 |
Author: Makarius |
|
4 |
||
5 |
SideKick parsers for Isabelle proof documents. |
|
6 |
*/ |
|
34393 | 7 |
|
34426
81f93e0f13b4
renamed isabelle.prover.IsabelleSKParser to isabelle.jedit.IsabelleSideKickParser;
wenzelm
parents:
34417
diff
changeset
|
8 |
package isabelle.jedit |
34393 | 9 |
|
34760 | 10 |
|
36015 | 11 |
import isabelle._ |
12 |
||
34393 | 13 |
import javax.swing.tree.DefaultMutableTreeNode |
34701
80b0add08eef
IsabelleSideKickParser: incorporate former MarkupNode.markup2default_node, observe stopped flag;
wenzelm
parents:
34669
diff
changeset
|
14 |
import javax.swing.text.Position |
59183
ec83638b6bfb
imitate font more carefully: err on smaller size;
wenzelm
parents:
59091
diff
changeset
|
15 |
import javax.swing.{JLabel, Icon} |
34417
bce2f2ea9819
misc tuning and adaption according to original IsabelleParser --
wenzelm
parents:
34408
diff
changeset
|
16 |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
17 |
import org.gjt.sp.jedit.Buffer |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
18 |
import sidekick.{SideKickParser, SideKickParsedData, IAsset} |
34701
80b0add08eef
IsabelleSideKickParser: incorporate former MarkupNode.markup2default_node, observe stopped flag;
wenzelm
parents:
34669
diff
changeset
|
19 |
|
34393 | 20 |
|
36738
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
21 |
object Isabelle_Sidekick |
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
22 |
{ |
40477 | 23 |
def int_to_pos(offset: Text.Offset): Position = |
57912 | 24 |
new Position { def getOffset = offset; override def toString: String = offset.toString } |
40452
45e7c2889d2f
misc tuning and simplification, using Isabelle_Sidekick.Asset (not sidekick.Asset, which is dynamically dispatched to slightly different semantics);
wenzelm
parents:
39624
diff
changeset
|
25 |
|
58526 | 26 |
def root_data(buffer: Buffer): SideKickParsedData = |
27 |
{ |
|
28 |
val data = new SideKickParsedData(buffer.getName) |
|
29 |
data.getAsset(data.root).setEnd(int_to_pos(buffer.getLength)) |
|
30 |
data |
|
31 |
} |
|
32 |
||
58747 | 33 |
class Keyword_Asset(keyword: String, text: String, range: Text.Range) extends IAsset |
40452
45e7c2889d2f
misc tuning and simplification, using Isabelle_Sidekick.Asset (not sidekick.Asset, which is dynamically dispatched to slightly different semantics);
wenzelm
parents:
39624
diff
changeset
|
34 |
{ |
59183
ec83638b6bfb
imitate font more carefully: err on smaller size;
wenzelm
parents:
59091
diff
changeset
|
35 |
private val css = GUI.imitate_font_css(Font_Info.main_family(), (new JLabel).getFont) |
ec83638b6bfb
imitate font more carefully: err on smaller size;
wenzelm
parents:
59091
diff
changeset
|
36 |
|
58747 | 37 |
protected var _name = text |
38 |
protected var _start = int_to_pos(range.start) |
|
39 |
protected var _end = int_to_pos(range.stop) |
|
40452
45e7c2889d2f
misc tuning and simplification, using Isabelle_Sidekick.Asset (not sidekick.Asset, which is dynamically dispatched to slightly different semantics);
wenzelm
parents:
39624
diff
changeset
|
40 |
override def getIcon: Icon = null |
53973
78bbe75c8437
enforce IsabelleText font for better symbol coverage, especially on Windows;
wenzelm
parents:
53281
diff
changeset
|
41 |
override def getShortString: String = |
59183
ec83638b6bfb
imitate font more carefully: err on smaller size;
wenzelm
parents:
59091
diff
changeset
|
42 |
"<html><span style=\"" + css + "\">" + |
58747 | 43 |
(if (keyword != "" && _name.startsWith(keyword)) |
44 |
"<b>" + HTML.encode(keyword) + "</b>" + HTML.encode(_name.substring(keyword.length)) |
|
45 |
else HTML.encode(_name)) + "</span></html>" |
|
40452
45e7c2889d2f
misc tuning and simplification, using Isabelle_Sidekick.Asset (not sidekick.Asset, which is dynamically dispatched to slightly different semantics);
wenzelm
parents:
39624
diff
changeset
|
46 |
override def getLongString: String = _name |
45e7c2889d2f
misc tuning and simplification, using Isabelle_Sidekick.Asset (not sidekick.Asset, which is dynamically dispatched to slightly different semantics);
wenzelm
parents:
39624
diff
changeset
|
47 |
override def getName: String = _name |
45e7c2889d2f
misc tuning and simplification, using Isabelle_Sidekick.Asset (not sidekick.Asset, which is dynamically dispatched to slightly different semantics);
wenzelm
parents:
39624
diff
changeset
|
48 |
override def setName(name: String) = _name = name |
45e7c2889d2f
misc tuning and simplification, using Isabelle_Sidekick.Asset (not sidekick.Asset, which is dynamically dispatched to slightly different semantics);
wenzelm
parents:
39624
diff
changeset
|
49 |
override def getStart: Position = _start |
45e7c2889d2f
misc tuning and simplification, using Isabelle_Sidekick.Asset (not sidekick.Asset, which is dynamically dispatched to slightly different semantics);
wenzelm
parents:
39624
diff
changeset
|
50 |
override def setStart(start: Position) = _start = start |
45e7c2889d2f
misc tuning and simplification, using Isabelle_Sidekick.Asset (not sidekick.Asset, which is dynamically dispatched to slightly different semantics);
wenzelm
parents:
39624
diff
changeset
|
51 |
override def getEnd: Position = _end |
45e7c2889d2f
misc tuning and simplification, using Isabelle_Sidekick.Asset (not sidekick.Asset, which is dynamically dispatched to slightly different semantics);
wenzelm
parents:
39624
diff
changeset
|
52 |
override def setEnd(end: Position) = _end = end |
57912 | 53 |
override def toString: String = _name |
40452
45e7c2889d2f
misc tuning and simplification, using Isabelle_Sidekick.Asset (not sidekick.Asset, which is dynamically dispatched to slightly different semantics);
wenzelm
parents:
39624
diff
changeset
|
54 |
} |
51618
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
55 |
|
58747 | 56 |
class Asset(name: String, range: Text.Range) extends Keyword_Asset("", name, range) |
57 |
||
51618
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
58 |
def swing_markup_tree(tree: Markup_Tree, parent: DefaultMutableTreeNode, |
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
59 |
swing_node: Text.Info[List[XML.Elem]] => DefaultMutableTreeNode) |
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
60 |
{ |
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
61 |
for ((_, entry) <- tree.branches) { |
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
62 |
val node = swing_node(Text.Info(entry.range, entry.markup)) |
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
63 |
swing_markup_tree(entry.subtree, node, swing_node) |
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
64 |
parent.add(node) |
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
65 |
} |
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
66 |
} |
36738
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
67 |
} |
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
68 |
|
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
69 |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
70 |
class Isabelle_Sidekick(name: String) extends SideKickParser(name) |
34625
799a40faa4f1
completion: decode symbols only if isabelle encoding is active (to prevent unicode chars written back to file);
wenzelm
parents:
34612
diff
changeset
|
71 |
{ |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
72 |
override def supportsCompletion = false |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
73 |
|
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
74 |
|
34417
bce2f2ea9819
misc tuning and adaption according to original IsabelleParser --
wenzelm
parents:
34408
diff
changeset
|
75 |
/* parsing */ |
bce2f2ea9819
misc tuning and adaption according to original IsabelleParser --
wenzelm
parents:
34408
diff
changeset
|
76 |
|
36759 | 77 |
@volatile protected var stopped = false |
34503 | 78 |
override def stop() = { stopped = true } |
34401
44241a37b74a
structure of markup-tree in scala, keep track of swing-nodes in background
immler@in.tum.de
parents:
34393
diff
changeset
|
79 |
|
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
80 |
def parser(buffer: Buffer, syntax: Outer_Syntax, data: SideKickParsedData): Boolean = false |
36759 | 81 |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
82 |
def parse(buffer: Buffer, error_source: errorlist.DefaultErrorSource): SideKickParsedData = |
34625
799a40faa4f1
completion: decode symbols only if isabelle encoding is active (to prevent unicode chars written back to file);
wenzelm
parents:
34612
diff
changeset
|
83 |
{ |
34417
bce2f2ea9819
misc tuning and adaption according to original IsabelleParser --
wenzelm
parents:
34408
diff
changeset
|
84 |
stopped = false |
34625
799a40faa4f1
completion: decode symbols only if isabelle encoding is active (to prevent unicode chars written back to file);
wenzelm
parents:
34612
diff
changeset
|
85 |
|
38640 | 86 |
// FIXME lock buffer (!??) |
58526 | 87 |
val data = Isabelle_Sidekick.root_data(buffer) |
59091 | 88 |
val syntax = GUI_Thread.now { Isabelle.buffer_syntax(buffer) } |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
89 |
val ok = |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
90 |
if (syntax.isDefined) { |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
91 |
val ok = parser(buffer, syntax.get, data) |
58526 | 92 |
if (stopped) { data.root.add(new DefaultMutableTreeNode("<stopped>")); true } |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
93 |
else ok |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
94 |
} |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
95 |
else false |
58526 | 96 |
if (!ok) data.root.add(new DefaultMutableTreeNode("<ignored>")) |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
97 |
|
34417
bce2f2ea9819
misc tuning and adaption according to original IsabelleParser --
wenzelm
parents:
34408
diff
changeset
|
98 |
data |
bce2f2ea9819
misc tuning and adaption according to original IsabelleParser --
wenzelm
parents:
34408
diff
changeset
|
99 |
} |
34393 | 100 |
} |
36738
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
101 |
|
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
102 |
|
48718 | 103 |
class Isabelle_Sidekick_Structure( |
104 |
name: String, |
|
105 |
node_name: Buffer => Option[Document.Node.Name]) |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
106 |
extends Isabelle_Sidekick(name) |
36759 | 107 |
{ |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
108 |
override def parser(buffer: Buffer, syntax: Outer_Syntax, data: SideKickParsedData): Boolean = |
36759 | 109 |
{ |
58743 | 110 |
def make_tree( |
111 |
parent: DefaultMutableTreeNode, |
|
112 |
offset: Text.Offset, |
|
113 |
documents: List[Outer_Syntax.Document]) |
|
114 |
{ |
|
115 |
(offset /: documents) { case (i, document) => |
|
116 |
document match { |
|
58747 | 117 |
case Outer_Syntax.Document_Block(name, text, body) => |
118 |
val range = Text.Range(i, i + document.length) |
|
58743 | 119 |
val node = |
120 |
new DefaultMutableTreeNode( |
|
58747 | 121 |
new Isabelle_Sidekick.Keyword_Asset(name, Library.first_line(text), range)) |
58743 | 122 |
parent.add(node) |
123 |
make_tree(node, i, body) |
|
124 |
case _ => |
|
125 |
} |
|
126 |
i + document.length |
|
40455
e035dad8eca2
default Sidekick parser based on section headings;
wenzelm
parents:
40452
diff
changeset
|
127 |
} |
58743 | 128 |
} |
40455
e035dad8eca2
default Sidekick parser based on section headings;
wenzelm
parents:
40452
diff
changeset
|
129 |
|
48718 | 130 |
node_name(buffer) match { |
131 |
case Some(name) => |
|
58743 | 132 |
make_tree(data.root, 0, syntax.parse_document(name, JEdit_Lib.buffer_text(buffer))) |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
133 |
true |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
134 |
case None => false |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
135 |
} |
36759 | 136 |
} |
137 |
} |
|
36738
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
138 |
|
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
139 |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
140 |
class Isabelle_Sidekick_Default extends |
56208 | 141 |
Isabelle_Sidekick_Structure("isabelle", PIDE.resources.theory_node_name) |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
142 |
|
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
143 |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
144 |
class Isabelle_Sidekick_Options extends |
54515 | 145 |
Isabelle_Sidekick_Structure("isabelle-options", _ => Some(Document.Node.Name("options"))) |
48718 | 146 |
|
147 |
||
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
148 |
class Isabelle_Sidekick_Root extends |
54515 | 149 |
Isabelle_Sidekick_Structure("isabelle-root", _ => Some(Document.Node.Name("ROOT"))) |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
150 |
|
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
151 |
|
53281
251e1a2aa792
clarified SideKick parser name, which serves as quasi "mode" here;
wenzelm
parents:
53274
diff
changeset
|
152 |
class Isabelle_Sidekick_Markup extends Isabelle_Sidekick("isabelle-markup") |
36759 | 153 |
{ |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
154 |
override def parser(buffer: Buffer, syntax: Outer_Syntax, data: SideKickParsedData): Boolean = |
36759 | 155 |
{ |
55513
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
156 |
val opt_snapshot = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56814
diff
changeset
|
157 |
GUI_Thread.now { |
59077
7e0d3da6e6d8
node-specific syntax, with base_syntax as default;
wenzelm
parents:
59075
diff
changeset
|
158 |
PIDE.document_model(buffer) match { |
55513
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
159 |
case Some(model) if model.is_theory => Some(model.snapshot) |
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
160 |
case _ => None |
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
161 |
} |
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
162 |
} |
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
163 |
opt_snapshot match { |
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
164 |
case Some(snapshot) => |
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56301
diff
changeset
|
165 |
for ((command, command_start) <- snapshot.node.command_iterator() if !stopped) { |
55650 | 166 |
val markup = |
56301
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56299
diff
changeset
|
167 |
snapshot.state.command_markup( |
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56299
diff
changeset
|
168 |
snapshot.version, command, Command.Markup_Index.markup, |
56743 | 169 |
command.range, Markup.Elements.full) |
58526 | 170 |
Isabelle_Sidekick.swing_markup_tree(markup, data.root, |
171 |
(info: Text.Info[List[XML.Elem]]) => |
|
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
172 |
{ |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
173 |
val range = info.range + command_start |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
174 |
val content = command.source(info.range).replace('\n', ' ') |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
175 |
val info_text = |
51493
59d8a1031c00
allow fractional pretty margin -- avoid premature rounding;
wenzelm
parents:
50725
diff
changeset
|
176 |
Pretty.formatted(Library.separate(Pretty.FBreak, info.info), margin = 40.0) |
59d8a1031c00
allow fractional pretty margin -- avoid premature rounding;
wenzelm
parents:
50725
diff
changeset
|
177 |
.mkString |
36738
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
178 |
|
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
179 |
new DefaultMutableTreeNode( |
58747 | 180 |
new Isabelle_Sidekick.Asset(command.toString, range) { |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
181 |
override def getShortString: String = content |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
182 |
override def getLongString: String = info_text |
57912 | 183 |
override def toString: String = quote(content) + " " + range.toString |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
184 |
}) |
40452
45e7c2889d2f
misc tuning and simplification, using Isabelle_Sidekick.Asset (not sidekick.Asset, which is dynamically dispatched to slightly different semantics);
wenzelm
parents:
39624
diff
changeset
|
185 |
}) |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
186 |
} |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
187 |
true |
55513
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
188 |
case None => false |
36759 | 189 |
} |
190 |
} |
|
191 |
} |
|
36738
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
192 |
|
52539 | 193 |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
194 |
class Isabelle_Sidekick_News extends Isabelle_Sidekick("isabelle-news") |
52539 | 195 |
{ |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
196 |
private val Heading1 = """^New in (.*)\w*$""".r |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
197 |
private val Heading2 = """^\*\*\*\w*(.*)\w*\*\*\*\w*$""".r |
52539 | 198 |
|
199 |
private def make_node(s: String, start: Text.Offset, stop: Text.Offset): DefaultMutableTreeNode = |
|
58747 | 200 |
new DefaultMutableTreeNode(new Isabelle_Sidekick.Asset(s, Text.Range(start, stop))) |
52539 | 201 |
|
202 |
override def parser(buffer: Buffer, syntax: Outer_Syntax, data: SideKickParsedData): Boolean = |
|
203 |
{ |
|
204 |
var offset = 0 |
|
58542 | 205 |
var end_offset = 0 |
206 |
||
207 |
var start1: Option[(Int, String, Vector[DefaultMutableTreeNode])] = None |
|
208 |
var start2: Option[(Int, String)] = None |
|
209 |
||
210 |
def close1: Unit = |
|
211 |
start1 match { |
|
212 |
case Some((start_offset, s, body)) => |
|
213 |
val node = make_node(s, start_offset, end_offset) |
|
214 |
body.foreach(node.add(_)) |
|
215 |
data.root.add(node) |
|
216 |
start1 = None |
|
217 |
case None => |
|
218 |
} |
|
219 |
||
220 |
def close2: Unit = |
|
221 |
start2 match { |
|
222 |
case Some((start_offset, s)) => |
|
223 |
start1 match { |
|
224 |
case Some((start_offset1, s1, body)) => |
|
225 |
val node = make_node(s, start_offset, end_offset) |
|
226 |
start1 = Some((start_offset1, s1, body :+ node)) |
|
227 |
case None => |
|
228 |
} |
|
229 |
start2 = None |
|
230 |
case None => |
|
231 |
} |
|
52539 | 232 |
|
233 |
for (line <- split_lines(JEdit_Lib.buffer_text(buffer)) if !stopped) { |
|
234 |
line match { |
|
58542 | 235 |
case Heading1(s) => close2; close1; start1 = Some((offset, s, Vector())) |
236 |
case Heading2(s) => close2; start2 = Some((offset, s)) |
|
52539 | 237 |
case _ => |
238 |
} |
|
239 |
offset += line.length + 1 |
|
58542 | 240 |
if (!line.forall(Character.isSpaceChar(_))) end_offset = offset |
52539 | 241 |
} |
58542 | 242 |
if (!stopped) { close2; close1 } |
52539 | 243 |
|
244 |
true |
|
245 |
} |
|
246 |
} |
|
247 |