author | wenzelm |
Tue, 21 Oct 2014 13:56:42 +0200 | |
changeset 58747 | c680f181b32e |
parent 58743 | c07a59140fee |
child 59075 | 9f87eb298b75 |
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 |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
15 |
import javax.swing.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 |
{ |
58747 | 35 |
protected var _name = text |
36 |
protected var _start = int_to_pos(range.start) |
|
37 |
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
|
38 |
override def getIcon: Icon = null |
53973
78bbe75c8437
enforce IsabelleText font for better symbol coverage, especially on Windows;
wenzelm
parents:
53281
diff
changeset
|
39 |
override def getShortString: String = |
55825 | 40 |
"<html><span style=\"font-family: " + Font_Info.main_family() + ";\">" + |
58747 | 41 |
(if (keyword != "" && _name.startsWith(keyword)) |
42 |
"<b>" + HTML.encode(keyword) + "</b>" + HTML.encode(_name.substring(keyword.length)) |
|
43 |
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
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
override def setEnd(end: Position) = _end = end |
57912 | 51 |
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
|
52 |
} |
51618
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
53 |
|
58747 | 54 |
class Asset(name: String, range: Text.Range) extends Keyword_Asset("", name, range) |
55 |
||
51618
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
56 |
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
|
57 |
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
|
58 |
{ |
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
59 |
for ((_, entry) <- tree.branches) { |
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
parent.add(node) |
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
63 |
} |
a3577cd80c41
tuned signature -- avoid intrusion of slightly odd Swing structures into pure Markup_Tree;
wenzelm
parents:
51493
diff
changeset
|
64 |
} |
36738
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
65 |
} |
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
66 |
|
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
67 |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
68 |
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
|
69 |
{ |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
70 |
override def supportsCompletion = false |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
71 |
|
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
72 |
|
34417
bce2f2ea9819
misc tuning and adaption according to original IsabelleParser --
wenzelm
parents:
34408
diff
changeset
|
73 |
/* parsing */ |
bce2f2ea9819
misc tuning and adaption according to original IsabelleParser --
wenzelm
parents:
34408
diff
changeset
|
74 |
|
36759 | 75 |
@volatile protected var stopped = false |
34503 | 76 |
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
|
77 |
|
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
78 |
def parser(buffer: Buffer, syntax: Outer_Syntax, data: SideKickParsedData): Boolean = false |
36759 | 79 |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
80 |
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
|
81 |
{ |
34417
bce2f2ea9819
misc tuning and adaption according to original IsabelleParser --
wenzelm
parents:
34408
diff
changeset
|
82 |
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
|
83 |
|
38640 | 84 |
// FIXME lock buffer (!??) |
58526 | 85 |
val data = Isabelle_Sidekick.root_data(buffer) |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
86 |
val syntax = Isabelle.mode_syntax(name) |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
87 |
val ok = |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
88 |
if (syntax.isDefined) { |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
89 |
val ok = parser(buffer, syntax.get, data) |
58526 | 90 |
if (stopped) { data.root.add(new DefaultMutableTreeNode("<stopped>")); true } |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
91 |
else ok |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
92 |
} |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
93 |
else false |
58526 | 94 |
if (!ok) data.root.add(new DefaultMutableTreeNode("<ignored>")) |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
95 |
|
34417
bce2f2ea9819
misc tuning and adaption according to original IsabelleParser --
wenzelm
parents:
34408
diff
changeset
|
96 |
data |
bce2f2ea9819
misc tuning and adaption according to original IsabelleParser --
wenzelm
parents:
34408
diff
changeset
|
97 |
} |
34393 | 98 |
} |
36738
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
99 |
|
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
100 |
|
48718 | 101 |
class Isabelle_Sidekick_Structure( |
102 |
name: String, |
|
103 |
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
|
104 |
extends Isabelle_Sidekick(name) |
36759 | 105 |
{ |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
106 |
override def parser(buffer: Buffer, syntax: Outer_Syntax, data: SideKickParsedData): Boolean = |
36759 | 107 |
{ |
58743 | 108 |
def make_tree( |
109 |
parent: DefaultMutableTreeNode, |
|
110 |
offset: Text.Offset, |
|
111 |
documents: List[Outer_Syntax.Document]) |
|
112 |
{ |
|
113 |
(offset /: documents) { case (i, document) => |
|
114 |
document match { |
|
58747 | 115 |
case Outer_Syntax.Document_Block(name, text, body) => |
116 |
val range = Text.Range(i, i + document.length) |
|
58743 | 117 |
val node = |
118 |
new DefaultMutableTreeNode( |
|
58747 | 119 |
new Isabelle_Sidekick.Keyword_Asset(name, Library.first_line(text), range)) |
58743 | 120 |
parent.add(node) |
121 |
make_tree(node, i, body) |
|
122 |
case _ => |
|
123 |
} |
|
124 |
i + document.length |
|
40455
e035dad8eca2
default Sidekick parser based on section headings;
wenzelm
parents:
40452
diff
changeset
|
125 |
} |
58743 | 126 |
} |
40455
e035dad8eca2
default Sidekick parser based on section headings;
wenzelm
parents:
40452
diff
changeset
|
127 |
|
48718 | 128 |
node_name(buffer) match { |
129 |
case Some(name) => |
|
58743 | 130 |
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
|
131 |
true |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
132 |
case None => false |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
133 |
} |
36759 | 134 |
} |
135 |
} |
|
36738
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
136 |
|
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
137 |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
138 |
class Isabelle_Sidekick_Default extends |
56208 | 139 |
Isabelle_Sidekick_Structure("isabelle", PIDE.resources.theory_node_name) |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
140 |
|
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
141 |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
142 |
class Isabelle_Sidekick_Options extends |
54515 | 143 |
Isabelle_Sidekick_Structure("isabelle-options", _ => Some(Document.Node.Name("options"))) |
48718 | 144 |
|
145 |
||
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
146 |
class Isabelle_Sidekick_Root extends |
54515 | 147 |
Isabelle_Sidekick_Structure("isabelle-root", _ => Some(Document.Node.Name("ROOT"))) |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
148 |
|
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
149 |
|
53281
251e1a2aa792
clarified SideKick parser name, which serves as quasi "mode" here;
wenzelm
parents:
53274
diff
changeset
|
150 |
class Isabelle_Sidekick_Markup extends Isabelle_Sidekick("isabelle-markup") |
36759 | 151 |
{ |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
152 |
override def parser(buffer: Buffer, syntax: Outer_Syntax, data: SideKickParsedData): Boolean = |
36759 | 153 |
{ |
55513
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
154 |
val opt_snapshot = |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56814
diff
changeset
|
155 |
GUI_Thread.now { |
55513
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
156 |
Document_Model(buffer) match { |
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
157 |
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
|
158 |
case _ => None |
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
159 |
} |
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
160 |
} |
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
161 |
opt_snapshot match { |
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
162 |
case Some(snapshot) => |
56373
0605d90be6fc
tuned signature -- more explicit iterator terminology;
wenzelm
parents:
56301
diff
changeset
|
163 |
for ((command, command_start) <- snapshot.node.command_iterator() if !stopped) { |
55650 | 164 |
val markup = |
56301
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56299
diff
changeset
|
165 |
snapshot.state.command_markup( |
1da7b4c33db9
more frugal merge of markup trees: filter wrt. subsequent query;
wenzelm
parents:
56299
diff
changeset
|
166 |
snapshot.version, command, Command.Markup_Index.markup, |
56743 | 167 |
command.range, Markup.Elements.full) |
58526 | 168 |
Isabelle_Sidekick.swing_markup_tree(markup, data.root, |
169 |
(info: Text.Info[List[XML.Elem]]) => |
|
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
170 |
{ |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
171 |
val range = info.range + command_start |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
172 |
val content = command.source(info.range).replace('\n', ' ') |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
173 |
val info_text = |
51493
59d8a1031c00
allow fractional pretty margin -- avoid premature rounding;
wenzelm
parents:
50725
diff
changeset
|
174 |
Pretty.formatted(Library.separate(Pretty.FBreak, info.info), margin = 40.0) |
59d8a1031c00
allow fractional pretty margin -- avoid premature rounding;
wenzelm
parents:
50725
diff
changeset
|
175 |
.mkString |
36738
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
176 |
|
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
177 |
new DefaultMutableTreeNode( |
58747 | 178 |
new Isabelle_Sidekick.Asset(command.toString, range) { |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
179 |
override def getShortString: String = content |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
180 |
override def getLongString: String = info_text |
57912 | 181 |
override def toString: String = quote(content) + " " + range.toString |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
182 |
}) |
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
|
183 |
}) |
48717
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
184 |
} |
622251b2b0f1
clarified Sidekick configuration, including minor modes;
wenzelm
parents:
47749
diff
changeset
|
185 |
true |
55513
6d21415e3909
recovered Isabelle_Sidekick_Markup from 9c53198dbb1c: snapshot requires Swing_Thread;
wenzelm
parents:
55432
diff
changeset
|
186 |
case None => false |
36759 | 187 |
} |
188 |
} |
|
189 |
} |
|
36738
dce592144219
support several sidekick parsers -- very basic default parser;
wenzelm
parents:
36737
diff
changeset
|
190 |
|
52539 | 191 |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
192 |
class Isabelle_Sidekick_News extends Isabelle_Sidekick("isabelle-news") |
52539 | 193 |
{ |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
194 |
private val Heading1 = """^New in (.*)\w*$""".r |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53233
diff
changeset
|
195 |
private val Heading2 = """^\*\*\*\w*(.*)\w*\*\*\*\w*$""".r |
52539 | 196 |
|
197 |
private def make_node(s: String, start: Text.Offset, stop: Text.Offset): DefaultMutableTreeNode = |
|
58747 | 198 |
new DefaultMutableTreeNode(new Isabelle_Sidekick.Asset(s, Text.Range(start, stop))) |
52539 | 199 |
|
200 |
override def parser(buffer: Buffer, syntax: Outer_Syntax, data: SideKickParsedData): Boolean = |
|
201 |
{ |
|
202 |
var offset = 0 |
|
58542 | 203 |
var end_offset = 0 |
204 |
||
205 |
var start1: Option[(Int, String, Vector[DefaultMutableTreeNode])] = None |
|
206 |
var start2: Option[(Int, String)] = None |
|
207 |
||
208 |
def close1: Unit = |
|
209 |
start1 match { |
|
210 |
case Some((start_offset, s, body)) => |
|
211 |
val node = make_node(s, start_offset, end_offset) |
|
212 |
body.foreach(node.add(_)) |
|
213 |
data.root.add(node) |
|
214 |
start1 = None |
|
215 |
case None => |
|
216 |
} |
|
217 |
||
218 |
def close2: Unit = |
|
219 |
start2 match { |
|
220 |
case Some((start_offset, s)) => |
|
221 |
start1 match { |
|
222 |
case Some((start_offset1, s1, body)) => |
|
223 |
val node = make_node(s, start_offset, end_offset) |
|
224 |
start1 = Some((start_offset1, s1, body :+ node)) |
|
225 |
case None => |
|
226 |
} |
|
227 |
start2 = None |
|
228 |
case None => |
|
229 |
} |
|
52539 | 230 |
|
231 |
for (line <- split_lines(JEdit_Lib.buffer_text(buffer)) if !stopped) { |
|
232 |
line match { |
|
58542 | 233 |
case Heading1(s) => close2; close1; start1 = Some((offset, s, Vector())) |
234 |
case Heading2(s) => close2; start2 = Some((offset, s)) |
|
52539 | 235 |
case _ => |
236 |
} |
|
237 |
offset += line.length + 1 |
|
58542 | 238 |
if (!line.forall(Character.isSpaceChar(_))) end_offset = offset |
52539 | 239 |
} |
58542 | 240 |
if (!stopped) { close2; close1 } |
52539 | 241 |
|
242 |
true |
|
243 |
} |
|
244 |
} |
|
245 |