2020#include < regex>
2121#include < iostream>
2222#include < cassert>
23+ #include < cstddef>
2324
2425using namespace docopt ;
2526
@@ -119,7 +120,7 @@ bool LeafPattern::match(PatternList& left, std::vector<std::shared_ptr<LeafPatte
119120 return false ;
120121 }
121122
122- left.erase (left.begin ()+match.first );
123+ left.erase (left.begin ()+static_cast <std:: ptrdiff_t >( match.first ) );
123124
124125 auto same_name = std::find_if (collected.begin (), collected.end (), [&](std::shared_ptr<LeafPattern> const & p) {
125126 return p->name ()==name ();
@@ -170,7 +171,7 @@ Option Option::parse(std::string const& option_description)
170171 auto double_space = option_description.find (" " );
171172 auto options_end = option_description.end ();
172173 if (double_space != std::string::npos) {
173- options_end = option_description.begin () + double_space;
174+ options_end = option_description.begin () + static_cast <std:: ptrdiff_t >( double_space) ;
174175 }
175176
176177 static const std::regex pattern {" (-{1,2})?(.*?)([,= ]|$)" };
@@ -340,7 +341,7 @@ std::pair<size_t, std::shared_ptr<LeafPattern>> Option::single_match(PatternList
340341#pragma mark -
341342#pragma mark Parsing stuff
342343
343- std::vector<PatternList> transform (PatternList pattern);
344+ static std::vector<PatternList> transform (PatternList pattern);
344345
345346void BranchPattern::fix_repeating_arguments ()
346347{
@@ -385,7 +386,7 @@ void BranchPattern::fix_repeating_arguments()
385386 }
386387}
387388
388- std::vector<PatternList> transform (PatternList pattern)
389+ static std::vector<PatternList> transform (PatternList pattern)
389390{
390391 std::vector<PatternList> result;
391392
@@ -512,7 +513,7 @@ class Tokens {
512513 std::string the_rest () const {
513514 if (!*this )
514515 return {};
515- return join (fTokens .begin ()+fIndex ,
516+ return join (fTokens .begin ()+static_cast <std:: ptrdiff_t >( fIndex ) ,
516517 fTokens .end (),
517518 " " );
518519 }
@@ -546,7 +547,7 @@ std::vector<T*> flat_filter(Pattern& pattern) {
546547 return ret;
547548}
548549
549- std::vector<std::string> parse_section (std::string const & name, std::string const & source) {
550+ static std::vector<std::string> parse_section (std::string const & name, std::string const & source) {
550551 // ECMAScript regex only has "?=" for a non-matching lookahead. In order to make sure we always have
551552 // a newline to anchor our matching, we have to avoid matching the final newline of each grouping.
552553 // Therefore, our regex is adjusted from the docopt Python one to use ?= to match the newlines before
@@ -571,7 +572,7 @@ std::vector<std::string> parse_section(std::string const& name, std::string cons
571572 return ret;
572573}
573574
574- bool is_argument_spec (std::string const & token) {
575+ static bool is_argument_spec (std::string const & token) {
575576 if (token.empty ())
576577 return false ;
577578
@@ -593,7 +594,7 @@ std::vector<std::string> longOptions(I iter, I end) {
593594 return ret;
594595}
595596
596- PatternList parse_long (Tokens& tokens, std::vector<Option>& options)
597+ static PatternList parse_long (Tokens& tokens, std::vector<Option>& options)
597598{
598599 // long ::= '--' chars [ ( ' ' | '=' ) chars ] ;
599600 std::string longOpt, equal;
@@ -665,7 +666,7 @@ PatternList parse_long(Tokens& tokens, std::vector<Option>& options)
665666 return ret;
666667}
667668
668- PatternList parse_short (Tokens& tokens, std::vector<Option>& options)
669+ static PatternList parse_short (Tokens& tokens, std::vector<Option>& options)
669670{
670671 // shorts ::= '-' ( chars )* [ [ ' ' ] chars ] ;
671672
@@ -706,8 +707,8 @@ PatternList parse_short(Tokens& tokens, std::vector<Option>& options)
706707 if (o->argCount ()) {
707708 if (i == token.end ()) {
708709 // consume the next token
709- auto const & token = tokens.current ();
710- if (token .empty () || token ==" --" ) {
710+ auto const & ttoken = tokens.current ();
711+ if (ttoken .empty () || ttoken ==" --" ) {
711712 std::string error = shortOpt + " requires an argument" ;
712713 throw Tokens::OptionError (std::move (error));
713714 }
@@ -729,9 +730,9 @@ PatternList parse_short(Tokens& tokens, std::vector<Option>& options)
729730 return ret;
730731}
731732
732- PatternList parse_expr (Tokens& tokens, std::vector<Option>& options);
733+ static PatternList parse_expr (Tokens& tokens, std::vector<Option>& options);
733734
734- PatternList parse_atom (Tokens& tokens, std::vector<Option>& options)
735+ static PatternList parse_atom (Tokens& tokens, std::vector<Option>& options)
735736{
736737 // atom ::= '(' expr ')' | '[' expr ']' | 'options'
737738 // | long | shorts | argument | command ;
@@ -778,7 +779,7 @@ PatternList parse_atom(Tokens& tokens, std::vector<Option>& options)
778779 return ret;
779780}
780781
781- PatternList parse_seq (Tokens& tokens, std::vector<Option>& options)
782+ static PatternList parse_seq (Tokens& tokens, std::vector<Option>& options)
782783{
783784 // seq ::= ( atom [ '...' ] )* ;"""
784785
@@ -802,15 +803,15 @@ PatternList parse_seq(Tokens& tokens, std::vector<Option>& options)
802803 return ret;
803804}
804805
805- std::shared_ptr<Pattern> maybe_collapse_to_required (PatternList&& seq)
806+ static std::shared_ptr<Pattern> maybe_collapse_to_required (PatternList&& seq)
806807{
807808 if (seq.size ()==1 ) {
808809 return std::move (seq[0 ]);
809810 }
810811 return std::make_shared<Required>(std::move (seq));
811812}
812813
813- std::shared_ptr<Pattern> maybe_collapse_to_either (PatternList&& seq)
814+ static std::shared_ptr<Pattern> maybe_collapse_to_either (PatternList&& seq)
814815{
815816 if (seq.size ()==1 ) {
816817 return std::move (seq[0 ]);
@@ -839,7 +840,7 @@ PatternList parse_expr(Tokens& tokens, std::vector<Option>& options)
839840 return { maybe_collapse_to_either (std::move (ret)) };
840841}
841842
842- Required parse_pattern (std::string const & source, std::vector<Option>& options)
843+ static Required parse_pattern (std::string const & source, std::vector<Option>& options)
843844{
844845 auto tokens = Tokens::from_pattern (source);
845846 auto result = parse_expr (tokens, options);
@@ -852,25 +853,25 @@ Required parse_pattern(std::string const& source, std::vector<Option>& options)
852853}
853854
854855
855- std::string formal_usage (std::string const & section) {
856+ static std::string formal_usage (std::string const & section) {
856857 std::string ret = " (" ;
857858
858859 auto i = section.find (' :' )+1 ; // skip past "usage:"
859860 auto parts = split (section, i);
860- for (size_t i = 1 ; i < parts.size (); ++i ) {
861- if (parts[i ] == parts[0 ]) {
861+ for (size_t ii = 1 ; ii < parts.size (); ++ii ) {
862+ if (parts[ii ] == parts[0 ]) {
862863 ret += " ) | (" ;
863864 } else {
864865 ret.push_back (' ' );
865- ret += parts[i ];
866+ ret += parts[ii ];
866867 }
867868 }
868869
869870 ret += " )" ;
870871 return ret;
871872}
872873
873- PatternList parse_argv (Tokens tokens, std::vector<Option>& options, bool options_first)
874+ static PatternList parse_argv (Tokens tokens, std::vector<Option>& options, bool options_first)
874875{
875876 // Parse command-line argument vector.
876877 //
@@ -907,7 +908,7 @@ PatternList parse_argv(Tokens tokens, std::vector<Option>& options, bool options
907908 return ret;
908909}
909910
910- std::vector<Option> parse_defaults (std::string const & doc) {
911+ static std::vector<Option> parse_defaults (std::string const & doc) {
911912 // This pattern is a bit more complex than the python docopt one due to lack of
912913 // re.split. Effectively, it grabs any line with leading whitespace and then a
913914 // hyphen; it stops grabbing when it hits another line that also looks like that.
@@ -920,7 +921,7 @@ std::vector<Option> parse_defaults(std::string const& doc) {
920921 std::vector<Option> defaults;
921922
922923 for (auto s : parse_section (" options:" , doc)) {
923- s.erase (s.begin (), s.begin ()+s.find (' :' )+1 ); // get rid of "options:"
924+ s.erase (s.begin (), s.begin ()+static_cast <std:: ptrdiff_t >( s.find (' :' ) )+1 ); // get rid of "options:"
924925
925926 std::for_each (std::sregex_iterator{ s.begin (), s.end (), pattern },
926927 std::sregex_iterator{},
@@ -937,7 +938,7 @@ std::vector<Option> parse_defaults(std::string const& doc) {
937938 return defaults;
938939}
939940
940- bool isOptionSet (PatternList const & options, std::string const & opt1, std::string const & opt2 = " " ) {
941+ static bool isOptionSet (PatternList const & options, std::string const & opt1, std::string const & opt2 = " " ) {
941942 return std::any_of (options.begin (), options.end (), [&](std::shared_ptr<Pattern const > const & opt) -> bool {
942943 auto const & name = opt->name ();
943944 if (name==opt1 || (!opt2.empty () && name==opt2)) {
@@ -947,7 +948,7 @@ bool isOptionSet(PatternList const& options, std::string const& opt1, std::strin
947948 });
948949}
949950
950- void extras (bool help, bool version, PatternList const & options) {
951+ static void extras (bool help, bool version, PatternList const & options) {
951952 if (help && isOptionSet (options, " -h" , " --help" )) {
952953 throw DocoptExitHelp ();
953954 }
@@ -958,7 +959,7 @@ void extras(bool help, bool version, PatternList const& options) {
958959}
959960
960961// Parse the doc string and generate the Pattern tree
961- std::pair<Required, std::vector<Option>> create_pattern_tree (std::string const & doc)
962+ static std::pair<Required, std::vector<Option>> create_pattern_tree (std::string const & doc)
962963{
963964 auto usage_sections = parse_section (" usage:" , doc);
964965 if (usage_sections.empty ()) {
0 commit comments