Skip to content

Commit 62df412

Browse files
committed
Convert the tree builder's unexpected!() macro to a function
Avoids hygiene issues.
1 parent 5033e36 commit 62df412

File tree

2 files changed

+76
-75
lines changed

2 files changed

+76
-75
lines changed

src/tree_builder/actions.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use std::ascii::StrAsciiExt;
2929
use std::iter::{Rev, Enumerate};
3030
use std::slice;
3131
use std::str::Slice;
32+
use std::fmt::Show;
3233

3334
pub struct ActiveFormattingIter<'a, Handle> {
3435
iter: Rev<Enumerate<slice::Items<'a, FormatEntry<Handle>>>>,
@@ -50,6 +51,7 @@ pub enum PushFlag {
5051

5152
// These go in a trait so that we can control visibility.
5253
pub trait TreeBuilderActions<Handle> {
54+
fn unexpected<T: Show>(&mut self, thing: &T) -> ProcessResult;
5355
fn clear_active_formatting_to_marker(&mut self);
5456
fn create_formatting_element_for(&mut self, tag: Tag) -> Handle;
5557
fn append_text(&mut self, text: String) -> ProcessResult;
@@ -101,6 +103,14 @@ pub trait TreeBuilderActions<Handle> {
101103
impl<'sink, Handle: Clone, Sink: TreeSink<Handle>>
102104
TreeBuilderActions<Handle> for super::TreeBuilder<'sink, Handle, Sink> {
103105

106+
fn unexpected<T: Show>(&mut self, thing: &T) -> ProcessResult {
107+
self.sink.parse_error(format_if!(
108+
self.opts.exact_errors,
109+
"Unexpected token",
110+
"Unexpected token {} in insertion mode {}", to_escaped_string(thing), self.mode));
111+
Done
112+
}
113+
104114
/// Iterate over the active formatting elements (with index in the list) from the end
105115
/// to the last marker, or the beginning if there are no markers.
106116
fn active_formatting_end_to_marker<'a>(&'a self) -> ActiveFormattingIter<'a, Handle> {

0 commit comments

Comments
 (0)