Some other examples:
Correct (recommended)
Parser action = something.Separate(); // doesn't create a sequence yet. If something is a sequence, separate it so we don't add to it
action &= somethingElse; // creates a new sequence here
The key is to name your parsers at the end, especially when using operators. If you're not using operators then it gets much more explicit what is getting named, and what is not.
This creates the following hierarchy:
SequenceParser (named action)
something
somethingElse
op
tail
or, to create without operators:
var action = new SequenceParser { Name = "action" };
action.Add(something);
action.Add(somethingElse);
These are incorrect:
Parser action = (something & somethingElse).Named("action"); // Named creates a new unary parser
action &= op & tail; // creates a new sequence parser
becomes:
SequenceParser (no name)
UnaryParser (named action)
SequenceParser
something
somethingElse
op
tail
or this:
Parser action = something; // haven't created the sequence yet!
action.Name = "action"; // we're actually setting the name on 'something' here
action &= op & term; // finally, we've created the sequence.. but no name!
creates:
SequenceParser
something (named action)
op
term
Curtis.