@@ -119,7 +119,7 @@ bool LeafPattern::match(PatternList& left, std::vector<std::shared_ptr<LeafPatte
119
119
return false ;
120
120
}
121
121
122
- left.erase (left.begin ()+match.first );
122
+ left.erase (left.begin ()+static_cast < decltype (left. begin ())::difference_type>( match.first ) );
123
123
124
124
auto same_name = std::find_if (collected.begin (), collected.end (), [&](std::shared_ptr<LeafPattern> const & p) {
125
125
return p->name ()==name ();
@@ -170,7 +170,7 @@ Option Option::parse(std::string const& option_description)
170
170
auto double_space = option_description.find (" " );
171
171
auto options_end = option_description.end ();
172
172
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) ;
174
174
}
175
175
176
176
static const std::regex pattern {" (--|-)?(.*?)([,= ]|$)" };
@@ -340,7 +340,7 @@ std::pair<size_t, std::shared_ptr<LeafPattern>> Option::single_match(PatternList
340
340
#pragma mark -
341
341
#pragma mark Parsing stuff
342
342
343
- std::vector<PatternList> transform (PatternList pattern);
343
+ static std::vector<PatternList> transform (PatternList pattern);
344
344
345
345
void BranchPattern::fix_repeating_arguments ()
346
346
{
@@ -385,7 +385,7 @@ void BranchPattern::fix_repeating_arguments()
385
385
}
386
386
}
387
387
388
- std::vector<PatternList> transform (PatternList pattern)
388
+ static std::vector<PatternList> transform (PatternList pattern)
389
389
{
390
390
std::vector<PatternList> result;
391
391
@@ -512,7 +512,7 @@ class Tokens {
512
512
std::string the_rest () const {
513
513
if (!*this )
514
514
return {};
515
- return join (fTokens .begin ()+fIndex ,
515
+ return join (fTokens .begin ()+static_cast < decltype ( fTokens . begin ())::difference_type>( fIndex ) ,
516
516
fTokens .end (),
517
517
" " );
518
518
}
@@ -546,7 +546,7 @@ std::vector<T*> flat_filter(Pattern& pattern) {
546
546
return ret;
547
547
}
548
548
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) {
550
550
// ECMAScript regex only has "?=" for a non-matching lookahead. In order to make sure we always have
551
551
// a newline to anchor our matching, we have to avoid matching the final newline of each grouping.
552
552
// 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
571
571
return ret;
572
572
}
573
573
574
- bool is_argument_spec (std::string const & token) {
574
+ static bool is_argument_spec (std::string const & token) {
575
575
if (token.empty ())
576
576
return false ;
577
577
@@ -593,7 +593,7 @@ std::vector<std::string> longOptions(I iter, I end) {
593
593
return ret;
594
594
}
595
595
596
- PatternList parse_long (Tokens& tokens, std::vector<Option>& options)
596
+ static PatternList parse_long (Tokens& tokens, std::vector<Option>& options)
597
597
{
598
598
// long ::= '--' chars [ ( ' ' | '=' ) chars ] ;
599
599
std::string longOpt, equal;
@@ -665,7 +665,7 @@ PatternList parse_long(Tokens& tokens, std::vector<Option>& options)
665
665
return ret;
666
666
}
667
667
668
- PatternList parse_short (Tokens& tokens, std::vector<Option>& options)
668
+ static PatternList parse_short (Tokens& tokens, std::vector<Option>& options)
669
669
{
670
670
// shorts ::= '-' ( chars )* [ [ ' ' ] chars ] ;
671
671
@@ -706,8 +706,8 @@ PatternList parse_short(Tokens& tokens, std::vector<Option>& options)
706
706
if (o->argCount ()) {
707
707
if (i == token.end ()) {
708
708
// 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 ==" --" ) {
711
711
std::string error = shortOpt + " requires an argument" ;
712
712
throw Tokens::OptionError (std::move (error));
713
713
}
@@ -729,9 +729,9 @@ PatternList parse_short(Tokens& tokens, std::vector<Option>& options)
729
729
return ret;
730
730
}
731
731
732
- PatternList parse_expr (Tokens& tokens, std::vector<Option>& options);
732
+ static PatternList parse_expr (Tokens& tokens, std::vector<Option>& options);
733
733
734
- PatternList parse_atom (Tokens& tokens, std::vector<Option>& options)
734
+ static PatternList parse_atom (Tokens& tokens, std::vector<Option>& options)
735
735
{
736
736
// atom ::= '(' expr ')' | '[' expr ']' | 'options'
737
737
// | long | shorts | argument | command ;
@@ -778,7 +778,7 @@ PatternList parse_atom(Tokens& tokens, std::vector<Option>& options)
778
778
return ret;
779
779
}
780
780
781
- PatternList parse_seq (Tokens& tokens, std::vector<Option>& options)
781
+ static PatternList parse_seq (Tokens& tokens, std::vector<Option>& options)
782
782
{
783
783
// seq ::= ( atom [ '...' ] )* ;"""
784
784
@@ -802,15 +802,15 @@ PatternList parse_seq(Tokens& tokens, std::vector<Option>& options)
802
802
return ret;
803
803
}
804
804
805
- std::shared_ptr<Pattern> maybe_collapse_to_required (PatternList&& seq)
805
+ static std::shared_ptr<Pattern> maybe_collapse_to_required (PatternList&& seq)
806
806
{
807
807
if (seq.size ()==1 ) {
808
808
return std::move (seq[0 ]);
809
809
}
810
810
return std::make_shared<Required>(std::move (seq));
811
811
}
812
812
813
- std::shared_ptr<Pattern> maybe_collapse_to_either (PatternList&& seq)
813
+ static std::shared_ptr<Pattern> maybe_collapse_to_either (PatternList&& seq)
814
814
{
815
815
if (seq.size ()==1 ) {
816
816
return std::move (seq[0 ]);
@@ -839,7 +839,7 @@ PatternList parse_expr(Tokens& tokens, std::vector<Option>& options)
839
839
return { maybe_collapse_to_either (std::move (ret)) };
840
840
}
841
841
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)
843
843
{
844
844
auto tokens = Tokens::from_pattern (source);
845
845
auto result = parse_expr (tokens, options);
@@ -852,25 +852,25 @@ Required parse_pattern(std::string const& source, std::vector<Option>& options)
852
852
}
853
853
854
854
855
- std::string formal_usage (std::string const & section) {
855
+ static std::string formal_usage (std::string const & section) {
856
856
std::string ret = " (" ;
857
857
858
858
auto i = section.find (' :' )+1 ; // skip past "usage:"
859
859
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 ]) {
862
862
ret += " ) | (" ;
863
863
} else {
864
864
ret.push_back (' ' );
865
- ret += parts[i ];
865
+ ret += parts[ii ];
866
866
}
867
867
}
868
868
869
869
ret += " )" ;
870
870
return ret;
871
871
}
872
872
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)
874
874
{
875
875
// Parse command-line argument vector.
876
876
//
@@ -907,7 +907,7 @@ PatternList parse_argv(Tokens tokens, std::vector<Option>& options, bool options
907
907
return ret;
908
908
}
909
909
910
- std::vector<Option> parse_defaults (std::string const & doc) {
910
+ static std::vector<Option> parse_defaults (std::string const & doc) {
911
911
// This pattern is a bit more complex than the python docopt one due to lack of
912
912
// re.split. Effectively, it grabs any line with leading whitespace and then a
913
913
// 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) {
920
920
std::vector<Option> defaults;
921
921
922
922
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:"
924
924
925
925
std::for_each (std::sregex_iterator{ s.begin (), s.end (), pattern },
926
926
std::sregex_iterator{},
@@ -937,7 +937,7 @@ std::vector<Option> parse_defaults(std::string const& doc) {
937
937
return defaults;
938
938
}
939
939
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 = " " ) {
941
941
return std::any_of (options.begin (), options.end (), [&](std::shared_ptr<Pattern const > const & opt) -> bool {
942
942
auto const & name = opt->name ();
943
943
if (name==opt1 || (!opt2.empty () && name==opt2)) {
@@ -947,7 +947,7 @@ bool isOptionSet(PatternList const& options, std::string const& opt1, std::strin
947
947
});
948
948
}
949
949
950
- void extras (bool help, bool version, PatternList const & options) {
950
+ static void extras (bool help, bool version, PatternList const & options) {
951
951
if (help && isOptionSet (options, " -h" , " --help" )) {
952
952
throw DocoptExitHelp ();
953
953
}
@@ -958,7 +958,7 @@ void extras(bool help, bool version, PatternList const& options) {
958
958
}
959
959
960
960
// 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)
962
962
{
963
963
auto usage_sections = parse_section (" usage:" , doc);
964
964
if (usage_sections.empty ()) {
0 commit comments