Closed huntzhan closed 9 years ago
Order of argument:
Guideline 11: The order of different options relative to one another should not matter, unless the options are documented as mutually-exclusive and such an option is documented to override any incompatible options preceding it. If an option that has option-arguments is repeated, the option and option-argument combinations should be interpreted in the order specified on the command line. Guideline 12: The order of operands may matter and position-related interpretations should be determined on a utility-specific basis.
Miscellaneous requirement:
there are some exceptions in POSIX.1-2008 to ensure continued operation of historical applications: a. If the SYNOPSIS of a standard utility shows an option with a mandatory option-argument (as with [ -c option_argument] in the example), a conforming application shall use separate arguments for that option and its option-argument. However, a conforming implementation shall also permit applications to specify the option and option-argument in the same argument string without intervening
characters. b. If the SYNOPSIS shows an optional option-argument (as with [ -f[ option_argument]] in the example), a conforming application shall place any option-argument for that option directly adjacent to the option in the same argument string, without intervening characters. If the utility receives an argument containing only the option, it shall behave as specified in its description for an omitted option-argument; it shall not treat the next argument (if any) as the option-argument for that option. ... Guideline 5: One or more options without option-arguments, followed by at most one option that takes an option-argument, should be accepted when grouped behind one '-' delimiter. ... Guideline 8: When multiple option-arguments are specified to follow a single option, they should be presented as a single argument, using characters within that argument or characters within that argument to separate them. ... Guideline 10: The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character. ... Guideline 13: For utilities that use operands to represent files to be opened for either reading or writing, the '-' operand should be used to mean only standard input (or standard output when it is clear from context that an output file is being specified) or a file named -.
Matching algorithm only consider three kinds of tokens, POSIX_OPTION
, GNU_OPTION
and GENERAL_ELEMENT
, due to #29 . Furthermore, the algorithm don't need to concern about the miscellaneous requirements, since #29 would handle that.
each process unit(i.e. LogicAnd
node, PosixOption
node) could access following variable:
tokens_
with type of const vector<Token> &
, consists of tokens generated by #29 .MatchStateManager
)tokens_iter_
with the type of const map<Token, vector<Token>::const_iterator>>
.MatchStateManager
)state_manager_
with type of MatchStateManager
.child_match_condition_
with type of boolean, indicating the state of a child process unit.principle of process unit:
AST visitor pattern:
{
match_state_manager_.PushRollbackPoint();
child_node->Accept(visitor_ptr_);
if (!child_match_flag_) {
// rollback to latest point.
match_state_manager_.Rollback();
return;
}
// remove latest rollback point.
match_state_manager_.PopRollbackPoint();
}
Arguments would be tokenized. The general idea of token matching algorithm is as follow: