diff options
Diffstat (limited to 'decoder/nt_span.h')
| -rwxr-xr-x | decoder/nt_span.h | 22 | 
1 files changed, 16 insertions, 6 deletions
diff --git a/decoder/nt_span.h b/decoder/nt_span.h index 46234b07..a918f301 100755 --- a/decoder/nt_span.h +++ b/decoder/nt_span.h @@ -8,10 +8,15 @@  struct Span {    int l,r;    Span() : l(-1) {  } +  bool is_null() const { return l<0; } +  void print(std::ostream &o,char const* for_null="") const { +    if (is_null()) +      o<<for_null; +    else +      o<<'<'<<l<<','<<r<<'>'; +  }    friend inline std::ostream &operator<<(std::ostream &o,Span const& s) { -    if (s.l<0) -      return o; -    return o<<'<'<<s.l<<','<<s.r<<'>'; +    s.print(o);return o;    }  }; @@ -20,10 +25,15 @@ struct NTSpan {    WordID nt; // awkward: this is a positive index, used in TD.  but represented as negative in mixed terminal/NT space in rules/hgs.    NTSpan() : nt(0) {  }    // prints as possibly empty name (whatever you set of nt,s will show) +  void print(std::ostream &o,char const* for_span_null="_",char const* for_null="") const { +    if (nt>0) { +      o<<TD::Convert(nt); +      s.print(o,for_span_null); +    } else +      s.print(o,for_null); +  }    friend inline std::ostream &operator<<(std::ostream &o,NTSpan const& t) { -    if (t.nt>0) -      o<<TD::Convert(t.nt); -    return o << t.s; +    t.print(o);return o;    }  };  | 
