/// <summary> /// Adds an option for a named node to follow this one in the parse tree the node is a part of /// </summary> /// <param name="matchItemsNamed">The name of the item to be matched</param> /// <param name="tag">The tag to associate with matched items</param> /// <param name="isValidEnd">Whether or not the element is a valid end to the parse tree</param> /// <returns>The ParseNodeDefinition that has been added</returns> public ParseNodeDefinition AddOption(string matchItemsNamed, string tag, bool isValidEnd) { var node = ParseNodeDefinition.Create(matchItemsNamed, tag, isValidEnd); _initialNodeOptions.Add(node); return(node); }
/// <summary> /// Attempts to follow a particular branch in the parse tree from a given starting point in a set of source parts /// </summary> /// <param name="parts">The set of source parts to attempt to match in</param> /// <param name="startIndex">The position to start the matching attempt at</param> /// <param name="required">The definition that must be matched for the branch to be followed</param> /// <param name="nodes">The set of nodes that have been matched so far</param> /// <returns>true if the branch was followed to completion, false otherwise</returns> private static bool FollowBranch(IList <ISourcePart> parts, int startIndex, ParseNodeDefinition required, ICollection <ParseNode> nodes) { if (parts[startIndex].Kind != required.MatchItemsNamed) { return(false); } nodes.Add(new ParseNode(parts[startIndex], required.Tag)); return(parts.Count > (startIndex + 1) && required.NextNodeOptions.Any(x => FollowBranch(parts, startIndex + 1, x, nodes)) || required.IsValidEnd); }
/// <summary> /// Links the given node as an option for a state to follow this one in the parse tree this node is a part of /// </summary> /// <param name="next">The node to add as an option</param> public void LinkTo(ParseNodeDefinition next) { _nextNodeOptions.Add(next); }