@@ -119,7 +119,7 @@ bool LeafPattern::match(PatternList& left, std::vector<std::shared_ptr<LeafPatte
119119 return false ;
120120 }
121121
122- left.erase (left.begin ()+match.first );
122+ left.erase (left.begin ()+static_cast < decltype (left. begin ())::difference_type>( match.first ) );
123123
124124 auto same_name = std::find_if (collected.begin (), collected.end (), [&](std::shared_ptr<LeafPattern> const & p) {
125125 return p->name ()==name ();
@@ -170,7 +170,7 @@ Option Option::parse(std::string const& option_description)
170170 auto double_space = option_description.find (" " );
171171 auto options_end = option_description.end ();
172172 if (double_space != std::string::npos) {
173- options_end = option_description.begin () + double_space;
173+ options_end = option_description.begin () + static_cast < decltype (option_description. begin ())::difference_type>( double_space) ;
174174 }
175175
176176 static const std::regex pattern {" (--|-)?(.*?)([,= ]|$)" };
@@ -340,7 +340,7 @@ std::pair<size_t, std::shared_ptr<LeafPattern>> Option::single_match(PatternList
340340#pragma mark -
341341#pragma mark Parsing stuff
342342
343- std::vector<PatternList> transform (PatternList pattern);
343+ static std::vector<PatternList> transform (PatternList pattern);
344344
345345void BranchPattern::fix_repeating_arguments ()
346346{
@@ -385,7 +385,7 @@ void BranchPattern::fix_repeating_arguments()
385385 }
386386}
387387
388- std::vector<PatternList> transform (PatternList pattern)
388+ static std::vector<PatternList> transform (PatternList pattern)
389389{
390390 std::vector<PatternList> result;
391391
@@ -512,7 +512,7 @@ class Tokens {
512512 std::string the_rest () const {
513513 if (!*this )
514514 return {};
515- return join (fTokens .begin ()+fIndex ,
515+ return join (fTokens .begin ()+static_cast < decltype ( fTokens . begin ())::difference_type>( fIndex ) ,
516516 fTokens .end (),
517517 " " );
518518 }
@@ -546,7 +546,7 @@ std::vector<T*> flat_filter(Pattern& pattern) {
546546 return ret;
547547}
548548
549- std::vector<std::string> parse_section (std::string const & name, std::string const & source) {
549+ static std::vector<std::string> parse_section (std::string const & name, std::string const & source) {
550550 // ECMAScript regex only has "?=" for a non-matching lookahead. In order to make sure we always have
551551 // a newline to anchor our matching, we have to avoid matching the final newline of each grouping.
552552 // Therefore, our regex is adjusted from the docopt Python one to use ?= to match the newlines before
@@ -571,7 +571,7 @@ std::vector<std::string> parse_section(std::string const& name, std::string cons
571571 return ret;
572572}
573573
574- bool is_argument_spec (std::string const & token) {
574+ static bool is_argument_spec (std::string const & token) {
575575 if (token.empty ())
576576 return false ;
577577
@@ -593,7 +593,7 @@ std::vector<std::string> longOptions(I iter, I end) {
593593 return ret;
594594}
595595
596- PatternList parse_long (Tokens& tokens, std::vector<Option>& options)
596+ static PatternList parse_long (Tokens& tokens, std::vector<Option>& options)
597597{
598598 // long ::= '--' chars [ ( ' ' | '=' ) chars ] ;
599599 std::string longOpt, equal;
@@ -665,7 +665,7 @@ PatternList parse_long(Tokens& tokens, std::vector<Option>& options)
665665 return ret;
666666}
667667
668- PatternList parse_short (Tokens& tokens, std::vector<Option>& options)
668+ static PatternList parse_short (Tokens& tokens, std::vector<Option>& options)
669669{
670670 // shorts ::= '-' ( chars )* [ [ ' ' ] chars ] ;
671671
@@ -706,8 +706,8 @@ PatternList parse_short(Tokens& tokens, std::vector<Option>& options)
706706 if (o->argCount ()) {
707707 if (i == token.end ()) {
708708 // consume the next token
709- auto const & token = tokens.current ();
710- if (token .empty () || token ==" --" ) {
709+ auto const & ttoken = tokens.current ();
710+ if (ttoken .empty () || ttoken ==" --" ) {
711711 std::string error = shortOpt + " requires an argument" ;
712712 throw Tokens::OptionError (std::move (error));
713713 }
@@ -729,9 +729,9 @@ PatternList parse_short(Tokens& tokens, std::vector<Option>& options)
729729 return ret;
730730}
731731
732- PatternList parse_expr (Tokens& tokens, std::vector<Option>& options);
732+ static PatternList parse_expr (Tokens& tokens, std::vector<Option>& options);
733733
734- PatternList parse_atom (Tokens& tokens, std::vector<Option>& options)
734+ static PatternList parse_atom (Tokens& tokens, std::vector<Option>& options)
735735{
736736 // atom ::= '(' expr ')' | '[' expr ']' | 'options'
737737 // | long | shorts | argument | command ;
@@ -778,7 +778,7 @@ PatternList parse_atom(Tokens& tokens, std::vector<Option>& options)
778778 return ret;
779779}
780780
781- PatternList parse_seq (Tokens& tokens, std::vector<Option>& options)
781+ static PatternList parse_seq (Tokens& tokens, std::vector<Option>& options)
782782{
783783 // seq ::= ( atom [ '...' ] )* ;"""
784784
@@ -802,15 +802,15 @@ PatternList parse_seq(Tokens& tokens, std::vector<Option>& options)
802802 return ret;
803803}
804804
805- std::shared_ptr<Pattern> maybe_collapse_to_required (PatternList&& seq)
805+ static std::shared_ptr<Pattern> maybe_collapse_to_required (PatternList&& seq)
806806{
807807 if (seq.size ()==1 ) {
808808 return std::move (seq[0 ]);
809809 }
810810 return std::make_shared<Required>(std::move (seq));
811811}
812812
813- std::shared_ptr<Pattern> maybe_collapse_to_either (PatternList&& seq)
813+ static std::shared_ptr<Pattern> maybe_collapse_to_either (PatternList&& seq)
814814{
815815 if (seq.size ()==1 ) {
816816 return std::move (seq[0 ]);
@@ -839,7 +839,7 @@ PatternList parse_expr(Tokens& tokens, std::vector<Option>& options)
839839 return { maybe_collapse_to_either (std::move (ret)) };
840840}
841841
842- Required parse_pattern (std::string const & source, std::vector<Option>& options)
842+ static Required parse_pattern (std::string const & source, std::vector<Option>& options)
843843{
844844 auto tokens = Tokens::from_pattern (source);
845845 auto result = parse_expr (tokens, options);
@@ -852,25 +852,25 @@ Required parse_pattern(std::string const& source, std::vector<Option>& options)
852852}
853853
854854
855- std::string formal_usage (std::string const & section) {
855+ static std::string formal_usage (std::string const & section) {
856856 std::string ret = " (" ;
857857
858858 auto i = section.find (' :' )+1 ; // skip past "usage:"
859859 auto parts = split (section, i);
860- for (size_t i = 1 ; i < parts.size (); ++i ) {
861- if (parts[i ] == parts[0 ]) {
860+ for (size_t ii = 1 ; ii < parts.size (); ++ii ) {
861+ if (parts[ii ] == parts[0 ]) {
862862 ret += " ) | (" ;
863863 } else {
864864 ret.push_back (' ' );
865- ret += parts[i ];
865+ ret += parts[ii ];
866866 }
867867 }
868868
869869 ret += " )" ;
870870 return ret;
871871}
872872
873- PatternList parse_argv (Tokens tokens, std::vector<Option>& options, bool options_first)
873+ static PatternList parse_argv (Tokens tokens, std::vector<Option>& options, bool options_first)
874874{
875875 // Parse command-line argument vector.
876876 //
@@ -907,7 +907,7 @@ PatternList parse_argv(Tokens tokens, std::vector<Option>& options, bool options
907907 return ret;
908908}
909909
910- std::vector<Option> parse_defaults (std::string const & doc) {
910+ static std::vector<Option> parse_defaults (std::string const & doc) {
911911 // This pattern is a bit more complex than the python docopt one due to lack of
912912 // re.split. Effectively, it grabs any line with leading whitespace and then a
913913 // hyphen; it stops grabbing when it hits another line that also looks like that.
@@ -920,7 +920,7 @@ std::vector<Option> parse_defaults(std::string const& doc) {
920920 std::vector<Option> defaults;
921921
922922 for (auto s : parse_section (" options:" , doc)) {
923- s.erase (s.begin (), s.begin ()+s. find (' :' )+1 ); // get rid of "options:"
923+ s.erase (s.begin (), s.begin ()+static_cast < decltype (s. begin ())::difference_type>(s. find (' :' ) )+1 ); // get rid of "options:"
924924
925925 std::for_each (std::sregex_iterator{ s.begin (), s.end (), pattern },
926926 std::sregex_iterator{},
@@ -937,7 +937,7 @@ std::vector<Option> parse_defaults(std::string const& doc) {
937937 return defaults;
938938}
939939
940- bool isOptionSet (PatternList const & options, std::string const & opt1, std::string const & opt2 = " " ) {
940+ static bool isOptionSet (PatternList const & options, std::string const & opt1, std::string const & opt2 = " " ) {
941941 return std::any_of (options.begin (), options.end (), [&](std::shared_ptr<Pattern const > const & opt) -> bool {
942942 auto const & name = opt->name ();
943943 if (name==opt1 || (!opt2.empty () && name==opt2)) {
@@ -947,7 +947,7 @@ bool isOptionSet(PatternList const& options, std::string const& opt1, std::strin
947947 });
948948}
949949
950- void extras (bool help, bool version, PatternList const & options) {
950+ static void extras (bool help, bool version, PatternList const & options) {
951951 if (help && isOptionSet (options, " -h" , " --help" )) {
952952 throw DocoptExitHelp ();
953953 }
@@ -958,7 +958,7 @@ void extras(bool help, bool version, PatternList const& options) {
958958}
959959
960960// Parse the doc string and generate the Pattern tree
961- std::pair<Required, std::vector<Option>> create_pattern_tree (std::string const & doc)
961+ static std::pair<Required, std::vector<Option>> create_pattern_tree (std::string const & doc)
962962{
963963 auto usage_sections = parse_section (" usage:" , doc);
964964 if (usage_sections.empty ()) {
0 commit comments