Skip to content

Commit 3087eef

Browse files
committed
Added support for getter and setter (yet only manually tested)
1 parent c9094ae commit 3087eef

File tree

1 file changed

+35
-23
lines changed

1 file changed

+35
-23
lines changed

Parser/Parser.cs

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public static File ParseCore(string filePath, CharacterPositionFinder finder, En
5050

5151
foreach (var child in rootNode.Children.Where(_ => _.Kind != SyntaxKind.EndOfFileToken))
5252
{
53-
var node = ParseNode(child, finder);
53+
var node = ParseNodeForType(child, finder);
5454
file.Children.Add(node);
5555
}
5656

5757
return file;
5858
}
5959

60-
private static ContainerOrTerminalNode ParseNode(Node node, CharacterPositionFinder finder)
60+
private static ContainerOrTerminalNode ParseNodeForType(Node node, CharacterPositionFinder finder)
6161
{
6262
switch (node)
6363
{
@@ -82,6 +82,32 @@ private static ContainerOrTerminalNode ParseNode(Node node, CharacterPositionFin
8282
}
8383
}
8484

85+
private static ContainerOrTerminalNode ParseNodeForKind(Node node, CharacterPositionFinder finder)
86+
{
87+
switch (node.Kind)
88+
{
89+
case SyntaxKind.EndOfFileToken:
90+
case SyntaxKind.Identifier:
91+
case SyntaxKind.ExportKeyword:
92+
case SyntaxKind.HeritageClause:
93+
case SyntaxKind.Decorator:
94+
return null;
95+
96+
case SyntaxKind.GetAccessor:
97+
case SyntaxKind.SetAccessor:
98+
case SyntaxKind.Constructor:
99+
case SyntaxKind.PropertyDeclaration:
100+
case SyntaxKind.MethodDeclaration:
101+
{
102+
return ParseTerminalNode(node, finder);
103+
}
104+
105+
default:
106+
Tracer.Trace($"Cannot handle '{node.Kind}'");
107+
return null;
108+
}
109+
}
110+
85111
private static ContainerOrTerminalNode ParseClassDeclaration(ClassDeclaration node, CharacterPositionFinder finder)
86112
{
87113
var headerSpan = GetHeaderSpan(node, finder);
@@ -98,27 +124,10 @@ private static ContainerOrTerminalNode ParseClassDeclaration(ClassDeclaration no
98124

99125
foreach (var child in node.Children)
100126
{
101-
switch (child.Kind)
127+
var item = ParseNodeForKind(child, finder);
128+
if (item != null)
102129
{
103-
case SyntaxKind.EndOfFileToken:
104-
case SyntaxKind.Identifier:
105-
case SyntaxKind.ExportKeyword:
106-
case SyntaxKind.HeritageClause:
107-
case SyntaxKind.Decorator:
108-
continue;
109-
110-
case SyntaxKind.Constructor:
111-
case SyntaxKind.PropertyDeclaration:
112-
case SyntaxKind.MethodDeclaration:
113-
{
114-
var item = ParseTerminalNode(child, finder);
115-
container.Children.Add(item);
116-
continue;
117-
}
118-
119-
default:
120-
Tracer.Trace($"Cannot handle '{child.Kind}'");
121-
continue;
130+
container.Children.Add(item);
122131
}
123132
}
124133

@@ -259,7 +268,7 @@ private static ContainerOrTerminalNode ParseDescribeTestExpression(CallExpressio
259268
}
260269

261270
default:
262-
Tracer.Trace($"Cannot handle '{child.Kind}'");
271+
Tracer.Trace($"Cannot handle '{child.Kind}'"); // TODO RKN: GetAccessor
263272
break;
264273
}
265274
}
@@ -359,6 +368,9 @@ private static string GetType(Node node)
359368
case SyntaxKind.MethodDeclaration: return "method";
360369
case SyntaxKind.PropertyDeclaration: return "property";
361370
case SyntaxKind.VariableDeclaration: return node.Parent.Flags == NodeFlags.Const ? "const" : "variable";
371+
case SyntaxKind.GetAccessor: return "getter";
372+
case SyntaxKind.SetAccessor: return "setter";
373+
362374
default:
363375
return kind.ToString();
364376
}

0 commit comments

Comments
 (0)