private static string GetCommandLocation(IChildNode node) { var sb = new StringBuilder(); switch (node) { case GroupNode group: { IParentNode current = group; while (current is IChildNode child) { sb.Insert(0, "::"); sb.Insert(0, child.Key); current = child.Parent; } break; } case CommandNode command: { sb.Append(command.GroupType.FullName); sb.Append("::"); sb.Append(command.CommandMethod.Name); break; } } return(sb.ToString()); }
/// <summary> /// Determines whether a node matches the current state of the tokenizer. /// </summary> /// <param name="node">The node.</param> /// <param name="tokenizer">The tokenizer.</param> /// <param name="searchOptions">A set of search options.</param> /// <returns>true if the node matches; otherwise, false.</returns> private bool IsNodeMatch(IChildNode node, TokenizingEnumerator tokenizer, TreeSearchOptions searchOptions) { if (!tokenizer.MoveNext()) { return(false); } if (tokenizer.Current.Type != TokenType.Value) { return(false); } if (tokenizer.Current.Value.Equals(node.Key, searchOptions.KeyComparison)) { return(true); } foreach (var alias in node.Aliases) { if (tokenizer.Current.Value.Equals(alias, searchOptions.KeyComparison)) { return(true); } } return(false); }
private static CreateCommandResult ToOption ( IChildNode child, [NotNullWhen(true)] out IApplicationCommandOption?option, ulong depth = 0 ) { option = null; switch (child) { case CommandNode command: { var createParameterOptions = CreateCommandParameterOptions(command, out var parameterOptions); if (!createParameterOptions.IsSuccess) { return(createParameterOptions); } option = new ApplicationCommandOption ( SubCommand, command.Key, command.Shape.Description, default, default, default, new Optional <IReadOnlyList <IApplicationCommandOption> >(parameterOptions) ); return(CreateCommandResult.FromSuccess()); }
public static string CalcShiftLevel(IChildNode node, string shift = "") { if (node.Parent == null) { return(shift); } return(CalcShiftLevel(node.Parent, shift + '\t')); }
/// <summary> /// Determines whether a node matches the given path component. /// </summary> /// <param name="node">The node.</param> /// <param name="pathComponent">The pathComponent.</param> /// <param name="searchOptions">A set of search options.</param> /// <returns>true if the node matches; otherwise, false.</returns> private bool IsNodeMatch(IChildNode node, ReadOnlySpan <char> pathComponent, TreeSearchOptions searchOptions) { if (pathComponent.Equals(node.Key, searchOptions.KeyComparison)) { return(true); } foreach (var alias in node.Aliases) { if (pathComponent.Equals(alias, searchOptions.KeyComparison)) { return(true); } } return(false); }
private void BuildArrayAccess(IChildNode currentNodeIndex, List <int> indexes, List <Tuple <Expression, IEnumerable <Expression> > > expressions) { foreach (IChildNode item in currentNodeIndex.Nodes) { indexes.Add(item.Index); if (item.Nodes.Count > 0) { BuildArrayAccess(item, indexes, expressions); } else { var leaf = item as ILeafNode <Expression>; var tuple = CreateIndexExpression(leaf, indexes); expressions.Add(tuple); } indexes.RemoveAt(indexes.Count - 1); } }
/// <summary> /// Determines whether a node matches the current state of the enumerator. /// </summary> /// <param name="node">The node.</param> /// <param name="enumerator">The tokenizer.</param> /// <param name="searchOptions">A set of search options.</param> /// <returns>true if the node matches; otherwise, false.</returns> private bool IsNodeMatch(IChildNode node, SpanSplitEnumerator enumerator, TreeSearchOptions searchOptions) { if (!enumerator.MoveNext()) { return(false); } if (enumerator.Current.Equals(node.Key, searchOptions.KeyComparison)) { return(true); } foreach (var alias in node.Aliases) { if (enumerator.Current.Equals(alias, searchOptions.KeyComparison)) { return(true); } } return(false); }
private void BuildArrayAccess(IChildNode currentNodeIndex, List<int> indexes, List<Tuple<Expression, IEnumerable<Expression>>> expressions) { foreach (IChildNode item in currentNodeIndex.Nodes) { indexes.Add(item.Index); if (item.Nodes.Count > 0) { BuildArrayAccess(item, indexes, expressions); } else { var leaf = item as ILeafNode<Expression>; var tuple = CreateIndexExpression(leaf, indexes); expressions.Add(tuple); } indexes.RemoveAt(indexes.Count - 1); } }