34 : p_{cooked.AsCharBlock().begin()}, limit_{cooked.AsCharBlock().end()} {}
35 ParseState(
const ParseState &that)
36 : p_{that.p_}, limit_{that.limit_}, context_{that.context_},
37 userState_{that.userState_}, inFixedForm_{that.inFixedForm_},
38 anyErrorRecovery_{that.anyErrorRecovery_},
39 anyConformanceViolation_{that.anyConformanceViolation_},
40 deferMessages_{that.deferMessages_},
41 anyDeferredMessages_{that.anyDeferredMessages_},
42 anyTokenMatched_{that.anyTokenMatched_} {}
43 ParseState(ParseState &&that)
44 : p_{that.p_}, limit_{that.limit_}, messages_{std::move(that.messages_)},
45 context_{std::move(that.context_)}, userState_{that.userState_},
46 inFixedForm_{that.inFixedForm_},
47 anyErrorRecovery_{that.anyErrorRecovery_},
48 anyConformanceViolation_{that.anyConformanceViolation_},
49 deferMessages_{that.deferMessages_},
50 anyDeferredMessages_{that.anyDeferredMessages_},
51 anyTokenMatched_{that.anyTokenMatched_} {}
52 ParseState &operator=(
const ParseState &that) {
53 p_ = that.p_, limit_ = that.limit_, context_ = that.context_;
54 userState_ = that.userState_, inFixedForm_ = that.inFixedForm_;
55 anyErrorRecovery_ = that.anyErrorRecovery_;
56 anyConformanceViolation_ = that.anyConformanceViolation_;
57 deferMessages_ = that.deferMessages_;
58 anyDeferredMessages_ = that.anyDeferredMessages_;
59 anyTokenMatched_ = that.anyTokenMatched_;
62 ParseState &operator=(ParseState &&that) {
63 p_ = that.p_, limit_ = that.limit_, messages_ = std::move(that.messages_);
64 context_ = std::move(that.context_);
65 userState_ = that.userState_, inFixedForm_ = that.inFixedForm_;
66 anyErrorRecovery_ = that.anyErrorRecovery_;
67 anyConformanceViolation_ = that.anyConformanceViolation_;
68 deferMessages_ = that.deferMessages_;
69 anyDeferredMessages_ = that.anyDeferredMessages_;
70 anyTokenMatched_ = that.anyTokenMatched_;
74 const Messages &messages()
const {
return messages_; }
75 Messages &messages() {
return messages_; }
77 const Message::Reference &context()
const {
return context_; }
78 Message::Reference &context() {
return context_; }
80 bool anyErrorRecovery()
const {
return anyErrorRecovery_; }
81 void set_anyErrorRecovery() { anyErrorRecovery_ =
true; }
83 bool anyConformanceViolation()
const {
return anyConformanceViolation_; }
84 void set_anyConformanceViolation() { anyConformanceViolation_ =
true; }
86 UserState *userState()
const {
return userState_; }
92 bool inFixedForm()
const {
return inFixedForm_; }
93 ParseState &set_inFixedForm(
bool yes =
true) {
98 bool deferMessages()
const {
return deferMessages_; }
99 ParseState &set_deferMessages(
bool yes =
true) {
100 deferMessages_ = yes;
104 bool anyDeferredMessages()
const {
return anyDeferredMessages_; }
105 ParseState &set_anyDeferredMessages(
bool yes =
true) {
106 anyDeferredMessages_ = yes;
110 bool anyTokenMatched()
const {
return anyTokenMatched_; }
111 ParseState &set_anyTokenMatched(
bool yes =
true) {
112 anyTokenMatched_ = yes;
116 const char *GetLocation()
const {
return p_; }
120 m->SetContext(context_.get());
121 context_ = Message::Reference{m};
126 context_ = context_->attachment();
129 template <
typename... A>
void Say(
CharBlock range, A &&...args) {
130 if (deferMessages_) {
131 anyDeferredMessages_ =
true;
133 messages_.Say(range, std::forward<A>(args)...).SetContext(context_.get());
136 template <
typename... A>
void Say(
const MessageFixedText &text, A &&...args) {
137 Say(p_, text, std::forward<A>(args)...);
139 template <
typename... A>
141 Say(p_, text, std::forward<A>(args)...);
145 Nonstandard(p_, lf, msg);
149 anyConformanceViolation_ =
true;
150 if (userState_ && userState_->features().ShouldWarn(lf)) {
155 if (userState_ && !userState_->features().IsEnabled(lf)) {
158 Nonstandard(lf, msg);
162 bool IsAtEnd()
const {
return p_ >= limit_; }
164 const char *UncheckedAdvance(std::size_t n = 1) {
165 const char *result{p_};
170 std::optional<const char *> GetNextChar() {
172 return UncheckedAdvance();
178 std::optional<const char *> PeekAtNextChar()
const {
186 std::size_t BytesRemaining()
const {
187 std::size_t remain = limit_ - p_;
191 void CombineFailedParses(ParseState &&that) {
192 bool haveMessages{anyDeferredMessages_ || !messages_.empty()};
193 bool thatHasMessages{that.anyDeferredMessages_ || !that.messages_.empty()};
194 if (haveMessages && !thatHasMessages) {
196 }
else if (!that.anyTokenMatched_ && (haveMessages || !thatHasMessages)) {
198 }
else if ((!anyTokenMatched_ && that.anyTokenMatched_) ||
199 (!haveMessages && thatHasMessages) ||
201 anyTokenMatched_ = that.anyTokenMatched_;
203 messages_ = std::move(that.messages_);
204 anyDeferredMessages_ = that.anyDeferredMessages_;
205 anyConformanceViolation_ = that.anyConformanceViolation_;
206 anyErrorRecovery_ = that.anyErrorRecovery_;
207 }
else if (that.p_ == p_) {
208 anyTokenMatched_ |= that.anyTokenMatched_;
209 messages_.Merge(std::move(that.messages_));
210 anyDeferredMessages_ |= that.anyDeferredMessages_;
211 anyConformanceViolation_ |= that.anyConformanceViolation_;
212 anyErrorRecovery_ |= that.anyErrorRecovery_;
218 const char *p_{
nullptr}, *limit_{
nullptr};
222 Message::Reference context_;
226 bool inFixedForm_{
false};
227 bool anyErrorRecovery_{
false};
228 bool anyConformanceViolation_{
false};
229 bool deferMessages_{
false};
230 bool anyDeferredMessages_{
false};
231 bool anyTokenMatched_{
false};