func (a *ArgumentCommandNode) Parse(ctx *CommandContext, rd *StringReader) error {
	start := rd.Cursor
	result, err := a.argType.Parse(rd)
	if err != nil {
		return fmt.Errorf("error parsing argument: %w", err)
	}
	parsed := &ParsedArgument{
		Range:  &StringRange{Start: start, End: rd.Cursor},
		Result: result,
	}
	ctx.withArgument(a.name, parsed)
	ctx.withNode(a, parsed.Range)
	return nil
}
Parse parses the argument from an input reader.
package brigodier
import (
	"context"
	"errors"
	"fmt"
	"sort"
)
func (d *Dispatcher) Parse(ctx context.Context, command string) *ParseResults {
	return d.ParseReader(ctx, &StringReader{String: command})
}
func (d *Dispatcher) ParseReader(ctx context.Context, command *StringReader) *ParseResults {
	return d.parseNodes(command, &d.Root, &CommandContext{
		Context:  ctx,
		RootNode: &d.Root,
		Range:    StringRange{Start: command.Cursor, End: command.Cursor},
		cursor:   command.Cursor,
	})
}
type ParseResults struct {
	Context *CommandContext
	Reader  *StringReader
	Errs    map[CommandNode]error
}
type CommandContext struct {
	context.Context
	Arguments map[string]*ParsedArgument
	RootNode  CommandNode
	Child     *CommandContext
	Command   Command
	Nodes     []*ParsedCommandNode
	Range     StringRange
	Modifier  RedirectModifier
	Forks     bool
	Input     string
	cursor int
}
func (c *CommandContext) build(input string) *CommandContext {
	var child *CommandContext
	if c.Child != nil {
		child = c.Child.build(input)
	}
	return &CommandContext{
		Context:   c.Context,
		Input:     input,
		Arguments: c.Arguments,
		Command:   c.Command,
		RootNode:  c.RootNode,
		Nodes:     c.Nodes,
		Range:     c.Range,
		Child:     child,
		Modifier:  c.Modifier,
		Forks:     c.Forks,
	}
}
func (c *CommandContext) HasNodes() bool { return len(c.Nodes) != 0 }
func (c *CommandContext) Copy() *CommandContext {
	return &CommandContext{
		Context: c.Context,
		Arguments: func() map[string]*ParsedArgument {
			m := make(map[string]*ParsedArgument, len(c.Arguments))
			for k, v := range c.Arguments {
				m[k] = v
			}
			return m
		}(),
		RootNode: c.RootNode,
		Child:    c.Child,
		Command:  c.Command,
		Nodes:    append(make([]*ParsedCommandNode, 0, len(c.Nodes)), c.Nodes...),
		Range:    c.Range.Copy(),
		Modifier: c.Modifier,
		Forks:    c.Forks,
		Input:    c.Input,
		cursor:   c.cursor,
	}
}
func (c *CommandContext) CopyFor(ctx context.Context) *CommandContext {
	if c.Context == ctx || ctx == nil {
		return c
	}
	clone := c.Copy()
	clone.Context = ctx
	return clone
}
type ParsedCommandNode struct {
	Node  CommandNode
	Range *StringRange
}
const ArgumentSeparator rune = ' '
var ErrDispatcherExpectedArgumentSeparator = errors.New("dispatcher: expected argument separator")
type CommandSyntaxError struct{ Err error }
func (e *CommandSyntaxError) Unwrap() error { return e.Err }
func (e *CommandSyntaxError) Error() string {
	return e.Err.Error()
}
func (d *Dispatcher) parseNodes(originalReader *StringReader, node CommandNode, ctxSoFar *CommandContext) *ParseResults {
	errs := map[CommandNode]error{}
	var potentials []*ParseResults
	cursor := originalReader.Cursor
	var (
		err error
		ctx *CommandContext
		rd  *StringReader
	)
	for _, child := range node.RelevantNodes(originalReader) {
		if !child.CanUse(ctxSoFar) {
			continue
		}
		ctx = ctxSoFar.Copy()
		rd = &StringReader{
			Cursor: originalReader.Cursor,
			String: originalReader.String,
		}
		err = child.Parse(ctx, rd)
		if err == nil && rd.CanRead() && rd.Peek() != ArgumentSeparator {
			err = &CommandSyntaxError{Err: &ReaderError{
				Err:    ErrDispatcherExpectedArgumentSeparator,
				Reader: rd,
			}}
		}
		if err != nil {
			errs[child] = err
			rd.Cursor = cursor
			continue
		}
		ctx.Command = child.Command()
		redirect := child.Redirect()
		canRead := 1
		if redirect == nil {
			canRead = 2
		}
		if rd.CanReadLen(canRead) {
			rd.Skip()
			if redirect != nil {
				childCtx := &CommandContext{
					Context:  ctx,
					RootNode: redirect,
					cursor:   rd.Cursor,
					Range: StringRange{
						Start: rd.Cursor,
						End:   rd.Cursor,
					},
				}
				parse := d.parseNodes(rd, redirect, childCtx)
				ctx.Child = parse.Context
				return &ParseResults{
					Context: ctx,
					Reader:  parse.Reader,
					Errs:    parse.Errs,
				}
			}
			potentials = append(potentials, d.parseNodes(rd, child, ctx))
		} else {
			potentials = append(potentials, &ParseResults{
				Context: ctx,
				Reader:  rd,
			})
		}
	}
	if len(potentials) != 0 {
		if len(potentials) > 1 {
			sort.Slice(potentials, func(i, j int) bool {
				a := potentials[i]
				b := potentials[j]
				if !a.Reader.CanRead() && b.Reader.CanRead() {
					return true
				}
				if a.Reader.CanRead() && !b.Reader.CanRead() {
					return false
				}
				if len(a.Errs) == 0 && len(b.Errs) != 0 {
					return false
				}
				if len(a.Errs) != 0 && len(b.Errs) == 0 {
					return true
				}
				return false
			})
		}
		return potentials[0]
	}
	return &ParseResults{
		Context: ctxSoFar,
		Reader:  originalReader,
		Errs:    errs,
	}
}
func (r *ParseResults) firstErr() error {
	for _, err := range r.Errs {
		return err
	}
	return nil
}
func (n *Node) RelevantNodes(input *StringReader) []CommandNode {
	if len(n.literals) != 0 {
		cursor := input.Cursor
		for input.CanRead() && input.Peek() != ArgumentSeparator {
			input.Skip()
		}
		text := input.String[cursor:input.Cursor]
		input.Cursor = cursor
		literal, ok := n.literals[text]
		if ok {
			return []CommandNode{literal}
		}
	}
	nodes := make([]CommandNode, 0, len(n.arguments))
	for _, a := range n.arguments {
		nodes = append(nodes, a)
	}
	return nodes
}
type IncorrectLiteralError struct {
	Literal string  
}
func (e *IncorrectLiteralError) Error() string { return fmt.Sprintf("incorrect literal %q", e.Literal) }
func (n *LiteralCommandNode) Parse(ctx *CommandContext, rd *StringReader) error {
	start := rd.Cursor
	end := n.parse(rd)
	if end <= -1 {
		return &CommandSyntaxError{Err: &ReaderError{
			Err:    &IncorrectLiteralError{Literal: n.Literal},
			Reader: rd,
		}}
	}
	ctx.withNode(n, &StringRange{Start: start, End: end})
	return nil
}
func (n *LiteralCommandNode) parse(rd *StringReader) int {
	start := rd.Cursor
	if rd.CanReadLen(len(n.Literal)) {
		end := start + len(n.Literal)
		if rd.String[start:end] == n.Literal {
			rd.Cursor = end
			if !rd.CanRead() || rd.Peek() == ArgumentSeparator {
				return end
			}
			rd.Cursor = start
		}
	}
	return -1
}
type ParsedArgument struct {
	Range  *StringRange  
	Result interface{}   
}