-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCSemanticParser.cs
104 lines (86 loc) · 3.26 KB
/
CSemanticParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
This file is part of TorqueDev.
TorqueDev is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TorqueDev is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TorqueDev. If not, see <http://www.gnu.org/licenses>
EXCEPTIONS TO THE GPL: TorqueDev links in a number of third party libraries,
which are exempt from the license. If you want to write closed-source
third party modules that you are going to link into TorqueDev, you may do so
without restriction. I acknowledge that this technically allows for
one to bypass the open source provisions of the GPL, but the real goal
is to keep the core of TorqueDev free and open. The rest is up to you.
*/
using System;
using System.Collections;
using System.Diagnostics;
using ActiproSoftware.SyntaxEditor;
namespace TSDev
{
/// <summary>
/// Summary description for CSemantecParser.
/// </summary>
internal class CSemanticParser : ActiproSoftware.SyntaxEditor.SemanticDefaultParser {
public CSemanticParser() {
}
public override AutomaticOutliningSupportType AutomaticOutliningSupportType {
get {
return AutomaticOutliningSupportType.SingleLanguageOnly;
}
}
public override void GetTokenOutliningAction(TokenStream tokenStream, ref string outliningKey, ref OutliningNodeAction tokenAction) {
Token token = tokenStream.Peek();
if ((token.Key == "OpenCurlyBraceToken" || token.Key == "CloseCurlyBraceToken") && g.Config.b_Ed_CodeFold == false)
return;
switch (token.Key) {
case "OpenCurlyBraceToken":
outliningKey = "CodeBlock";
tokenAction = OutliningNodeAction.Start;
break;
case "CloseCurlyBraceToken":
outliningKey = "CodeBlock";
tokenAction = OutliningNodeAction.End;
break;
case "RegionStartToken":
outliningKey = "CodeRegion";
tokenAction = OutliningNodeAction.Start;
break;
case "RegionEndToken":
outliningKey = "CodeRegion";
tokenAction = OutliningNodeAction.End;
break;
}
}
public override void PostParse(Document document, DocumentModification modification) {
if (modification.HasFlag(DocumentModificationFlags.ProgrammaticTextParse)) {
if (g.Config.bAutoCollapse)
document.Outlining.RootNode.CollapseDescendants("CodeRegion");
}
}
public override void SetOutliningNodeCollapsedText(OutliningNode node) {
TokenCollection tokens = node.Document.Tokens;
int tokenIndex = tokens.IndexOf(node.StartOffset);
switch(tokens[tokenIndex].Key) {
case "RegionStartToken":
string collapsedText = "";
while(++tokenIndex < tokens.Count) {
if (tokens[tokenIndex].Key == "RegionTokenEnd")
break;
collapsedText += tokens.Document.GetTokenText(tokens[tokenIndex]);
}
if (collapsedText != "")
collapsedText = " " + collapsedText.Trim() + " ";
else
collapsedText = " ... ";
node.CollapsedText = collapsedText;
break;
}
}
}
}