Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions CSharp.CDTk/Analysis/Analysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,7 @@ internal CategoricalSemanticDiagram Parse(string input)
// Infer a start rule: a non-token rule that is never referenced as a child
private Rule InferStartRule()
{
var all = _grammar.GetAllRules().Select(r => r.ResolvedRule).Distinct().ToList();
var allSet = new HashSet<Rule>(all);
var referenced = new HashSet<Rule>();

foreach (var rule in all)
{
var visited = new HashSet<Rule>();
CollectReferencedNamedRules(rule, allSet, referenced, visited, rule);
}

var candidate = all.FirstOrDefault(r => !referenced.Contains(r) && r.Type != Rule.RuleType.Token);
if (candidate != null)
return candidate;

candidate = all.FirstOrDefault(r => r.Type != Rule.RuleType.Token);
if (candidate != null)
return candidate;

return all.First();
return _grammar.GetStartRule().ResolvedRule;
}

// Recursively walk the rule tree and add any named rules (from allSet) found
Expand Down
Loading