From aea043a9e7c6505b5a67b4c65b10ae15da8d4531 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 11 Jan 2025 19:51:03 -0600 Subject: [PATCH] rewrite optional match logic to satisfy mac compiler --- src/location.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/location.cpp b/src/location.cpp index 0212acb4a..1972ddf53 100644 --- a/src/location.cpp +++ b/src/location.cpp @@ -241,35 +241,37 @@ std::ostream& operator<< (std::ostream& out, location l) { struct match { 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(!m.optional){ - in.setstate(std::ios_base::failbit); - }else{ - in.clear(); - } + in.clear(); return in; } char next = in.get(); - if(next != m.c) { - if(m.optional){ - in.putback(next); - }else{ - in.setstate(std::ios_base::failbit); - } + if(next != o.m.c) { + in.putback(next); + } + return in; +} + +static std::istream& operator>> (std::istream& in, match m) { + if(in.get() != m.c) { + in.setstate(std::ios_base::failbit); } return in; } std::istream& operator>> (std::istream& in, location& l) { - in >> std::ws >> match{'(', true}; + in >> std::ws >> opt{match{'('}}; in >> l.x; in >> match{','} >> std::ws; in >> l.y; - in >> match{')', true}; + in >> opt{match{')'}}; return in; }