Skip to content

Commit 5e47d78

Browse files
Fix an error on empty tokens, fix wrongly ordered vertices in graph.
Also make sidebar list items display same text as vertices.
1 parent 7fc7037 commit 5e47d78

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

Graphs/TokenVertex.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace GrunCS.Graphs
22
{
3+
using System;
34
using Antlr4.Runtime;
45
using Antlr4.Runtime.Tree;
56

@@ -41,9 +42,7 @@ public override string Text
4142
{
4243
get
4344
{
44-
string text = this.Token.Text;
45-
46-
if (string.IsNullOrWhiteSpace(text) && !text.Contains("\n"))
45+
if (string.IsNullOrWhiteSpace(this.Token.Text) && (this.Token.Text == null || !this.Token.Text.Contains("\n")))
4746
{
4847
return $"<{MainWindow.LexerSymbolicNames[this.Token.Type]}>";
4948
}

MainWindow.xaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" />
2323
<controls:ZoomControl Grid.Column="2" Zoom="1" ZoomBoxOpacity="0.5" Mode="Fill">
2424
<graphs:TokenGraphLayout x:Name="GraphLayout" Margin="10" Graph="{Binding Path=Graph}"
25-
LayoutAlgorithmType="EfficientSugiyama" OverlapRemovalAlgorithmType="FSA">
25+
LayoutAlgorithmType="EfficientSugiyama">
2626
<graphs:TokenGraphLayout.LayoutParameters>
2727
<layout:EfficientSugiyamaLayoutParameters
2828
EdgeRouting="Orthogonal"
29-
OptimizeWidth="True"
30-
PositionMode="0"></layout:EfficientSugiyamaLayoutParameters>
29+
PositionMode="0"
30+
LayerDistance="17"
31+
MinimizeEdgeLength="True"></layout:EfficientSugiyamaLayoutParameters>
3132
</graphs:TokenGraphLayout.LayoutParameters>
3233
</graphs:TokenGraphLayout>
3334
</controls:ZoomControl>

MainWindow.xaml.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Data;
66
using System.IO;
77
using System.Reflection;
8+
using System.Windows;
89
using System.Windows.Controls;
910
using System.Windows.Input;
1011
using System.Windows.Media;
@@ -48,12 +49,22 @@ private TreeViewItem Traverse(ITree tree, Parser parser)
4849
}
4950
else if (tree.Payload is IToken)
5051
{
51-
text = ((IToken) tree.Payload).Text.Replace("\n", "\\n");
52+
var token = (IToken) tree.Payload;
53+
54+
if (string.IsNullOrWhiteSpace(token.Text) && (token.Text == null || !token.Text.Contains("\n")))
55+
{
56+
text = $"<{MainWindow.LexerSymbolicNames[token.Type]}>";
57+
}
58+
else
59+
{
60+
text = token.Text.Replace("\n", "\\n");
61+
}
5262
}
5363

5464
var result = new TreeViewItem
5565
{
56-
Header = text
66+
Header = text,
67+
FontWeight = tree is IRuleNode ? FontWeights.Bold : FontWeights.Normal
5768
};
5869

5970
if (tree is IErrorNode)

MainWindowViewModel.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
2727
{
2828
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
2929
}
30-
31-
32-
33-
3430

31+
3532
private PayloadVertex DrawTraverse(TokenGraph graph, ITree tree, Parser parser)
3633
{
3734
PayloadVertex vertex;

0 commit comments

Comments
 (0)