rewrite optional match logic to satisfy mac compiler
This commit is contained in:
@@ -241,35 +241,37 @@ std::ostream& operator<< (std::ostream& out, location l) {
|
|||||||
|
|
||||||
struct match {
|
struct match {
|
||||||
char c;
|
char c;
|
||||||
bool optional = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::istream& operator>> (std::istream& in, match m) {
|
struct opt {
|
||||||
|
match m;
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::istream& operator>> (std::istream& in, opt o) {
|
||||||
if(in.eof()){
|
if(in.eof()){
|
||||||
if(!m.optional){
|
in.clear();
|
||||||
in.setstate(std::ios_base::failbit);
|
|
||||||
}else{
|
|
||||||
in.clear();
|
|
||||||
}
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
char next = in.get();
|
char next = in.get();
|
||||||
if(next != m.c) {
|
if(next != o.m.c) {
|
||||||
if(m.optional){
|
in.putback(next);
|
||||||
in.putback(next);
|
}
|
||||||
}else{
|
return in;
|
||||||
in.setstate(std::ios_base::failbit);
|
}
|
||||||
}
|
|
||||||
|
static std::istream& operator>> (std::istream& in, match m) {
|
||||||
|
if(in.get() != m.c) {
|
||||||
|
in.setstate(std::ios_base::failbit);
|
||||||
}
|
}
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::istream& operator>> (std::istream& in, location& l) {
|
std::istream& operator>> (std::istream& in, location& l) {
|
||||||
in >> std::ws >> match{'(', true};
|
in >> std::ws >> opt{match{'('}};
|
||||||
in >> l.x;
|
in >> l.x;
|
||||||
in >> match{','} >> std::ws;
|
in >> match{','} >> std::ws;
|
||||||
in >> l.y;
|
in >> l.y;
|
||||||
in >> match{')', true};
|
in >> opt{match{')'}};
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user