本文整理汇总了C#中ParseTree.GetParents方法的典型用法代码示例。如果您正苦于以下问题:C# ParseTree.GetParents方法的具体用法?C# ParseTree.GetParents怎么用?C# ParseTree.GetParents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParseTree
的用法示例。
在下文中一共展示了ParseTree.GetParents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSegmentTree
/// <summary>
/// Get ancestors of a segment until a group is reached, excluding the parent group.
/// </summary>
/// <param name="segment">
/// The segment grammar.
/// </param>
/// <param name="lastFoundSegment">
/// The last segment that was found.
/// </param>
/// <returns>
/// List of segment ancestors.
/// </returns>
private static IEnumerable<ParseTree> GetSegmentTree(ParseTree segment, ParseTree lastFoundSegment)
{
var result = new List<ParseTree>();
// Do only for segments with parent different than message
if (!segment.Parent.IsMessage && segment.IsSegment)
{
// Trigger segments, e.g. the first segment in a group
if (segment.IsTrigger && segment.Parent != null && segment.Parent.IsGroup)
{
// A->G->S
if (segment.Parent.Parent != null && segment.Parent.Parent.IsAll)
{
var lastFoundParents =
lastFoundSegment.GetParents(
s => s.Parent != null && !s.Parent.IsMessage)
.Where(p => !p.IsChoice)
.ToList();
var segmentParents =
segment.GetParents(s => s.Parent != null && !s.Parent.IsGroup && !s.Parent.IsMessage)
.Where(p => !p.IsChoice)
.ToList();
if (
!lastFoundParents.Where(p => p.IsAll)
.Select(n => n.Name)
.Intersect(segmentParents.Where(p => p.IsAll).Select(n => n.Name))
.Any() &&
!lastFoundParents.Where(p => p.IsGroup)
.Select(n => n.Name)
.Intersect(segmentParents.Where(p => p.IsGroup).Select(n => n.Name))
.Any())
{
result.Add(segment.Parent.Parent);
}
}
// A->U->G->S
if (segment.Parent.Parent != null && segment.Parent.Parent.IsLoopOfLoops)
{
var lastFoundGroupName = lastFoundSegment.Parent.IsGroup || lastFoundSegment.Parent.IsMessage
? lastFoundSegment.Parent.Name
: lastFoundSegment.Parent.Parent.Name;
if (lastFoundGroupName != segment.Parent.Name)
{
result.Add(segment.Parent.Parent.Parent);
result.Add(segment.Parent.Parent);
}
}
// G->S
result.Add(segment.Parent);
}
else
{
// A->S or I->S
if ((segment.Parent.IsAll || segment.Parent.IsChoice) &&
lastFoundSegment.Parent.Name != segment.Parent.Name)
{
result.Add(segment.Parent);
}
}
}
result.Add(segment);
return result;
}