Skip to content

Commit bddd109

Browse files
committed
Do some renames around of TagState enum and improve documentation
1 parent b54d0c2 commit bddd109

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

src/reader/mod.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -142,35 +142,35 @@ pub use ns_reader::NsReader;
142142
/// subgraph _
143143
/// direction LR
144144
///
145-
/// Init -- "(no event)"\nStartText --> Opened
146-
/// Opened -- Decl, DocType, PI\nComment, CData\nStart, Empty, End --> Closed
147-
/// Closed -- "#lt;false#gt;\n(no event)"\nText --> Opened
145+
/// Init -- "(no event)"\nStartText --> OpenedTag
146+
/// OpenedTag -- Decl, DocType, PI\nComment, CData\nStart, Empty, End --> ClosedTag
147+
/// ClosedTag -- "#lt;false#gt;\n(no event)"\nText --> OpenedTag
148148
/// end
149-
/// Closed -- "#lt;true#gt;"\nStart --> Empty
150-
/// Empty -- End --> Closed
149+
/// ClosedTag -- "#lt;true#gt;"\nStart --> Empty
150+
/// Empty -- End --> ClosedTag
151151
/// _ -. Eof .-> Exit
152152
/// ```
153153
#[derive(Clone)]
154-
enum TagState {
154+
enum ParseState {
155155
/// Initial state in which reader stay after creation. Transition from that
156156
/// state could produce a `StartText`, `Decl`, `Comment` or `Start` event.
157-
/// The next state is always `Opened`. The reader will never return to this
158-
/// state. The event emitted during transition to `Opened` is a `StartEvent`
157+
/// The next state is always `OpenedTag`. The reader will never return to this
158+
/// state. The event emitted during transition to `OpenedTag` is a `StartEvent`
159159
/// if the first symbol not `<`, otherwise no event are emitted.
160160
Init,
161161
/// State after seeing the `<` symbol. Depending on the next symbol all other
162162
/// events (except `StartText`) could be generated.
163163
///
164-
/// After generating ane event the reader moves to the `Closed` state.
165-
Opened,
164+
/// After generating ane event the reader moves to the `ClosedTag` state.
165+
OpenedTag,
166166
/// State in which reader searches the `<` symbol of a markup. All bytes before
167167
/// that symbol will be returned in the [`Event::Text`] event. After that
168-
/// the reader moves to the `Opened` state.
169-
Closed,
168+
/// the reader moves to the `OpenedTag` state.
169+
ClosedTag,
170170
/// This state is used only if option `expand_empty_elements` is set to `true`.
171-
/// Reader enters to this state when it is in a `Closed` state and emits an
171+
/// Reader enters to this state when it is in a `ClosedTag` state and emits an
172172
/// [`Event::Start`] event. The next event emitted will be an [`Event::End`],
173-
/// after which reader returned to the `Closed` state.
173+
/// after which reader returned to the `ClosedTag` state.
174174
Empty,
175175
/// Reader enters this state when `Eof` event generated or an error occurred.
176176
/// This is the last state, the reader stay in it forever.
@@ -374,9 +374,9 @@ impl<R> Reader<R> {
374374
///
375375
/// Useful when debugging errors.
376376
pub fn buffer_position(&self) -> usize {
377-
// when internal state is Opened, we have actually read until '<',
377+
// when internal state is OpenedTag, we have actually read until '<',
378378
// which we don't want to show
379-
if let TagState::Opened = self.parser.tag_state {
379+
if let ParseState::OpenedTag = self.parser.state {
380380
self.parser.offset - 1
381381
} else {
382382
self.parser.offset
@@ -405,28 +405,28 @@ impl<R> Reader<R> {
405405
where
406406
R: XmlSource<'i, B>,
407407
{
408-
let event = match self.parser.tag_state {
409-
TagState::Init => self.read_until_open(buf, true),
410-
TagState::Closed => self.read_until_open(buf, false),
411-
TagState::Opened => self.read_until_close(buf),
412-
TagState::Empty => self.parser.close_expanded_empty(),
413-
TagState::Exit => return Ok(Event::Eof),
408+
let event = match self.parser.state {
409+
ParseState::Init => self.read_until_open(buf, true),
410+
ParseState::ClosedTag => self.read_until_open(buf, false),
411+
ParseState::OpenedTag => self.read_until_close(buf),
412+
ParseState::Empty => self.parser.close_expanded_empty(),
413+
ParseState::Exit => return Ok(Event::Eof),
414414
};
415415
match event {
416-
Err(_) | Ok(Event::Eof) => self.parser.tag_state = TagState::Exit,
416+
Err(_) | Ok(Event::Eof) => self.parser.state = ParseState::Exit,
417417
_ => {}
418418
}
419419
event
420420
}
421421

422-
/// Read until '<' is found and moves reader to an `Opened` state.
422+
/// Read until '<' is found and moves reader to an `OpenedTag` state.
423423
///
424424
/// Return a `StartText` event if `first` is `true` and a `Text` event otherwise
425425
fn read_until_open<'i, B>(&mut self, buf: B, first: bool) -> Result<Event<'i>>
426426
where
427427
R: XmlSource<'i, B>,
428428
{
429-
self.parser.tag_state = TagState::Opened;
429+
self.parser.state = ParseState::OpenedTag;
430430

431431
if self.parser.trim_text_start {
432432
self.reader.skip_whitespace(&mut self.parser.offset)?;
@@ -453,7 +453,7 @@ impl<R> Reader<R> {
453453
where
454454
R: XmlSource<'i, B>,
455455
{
456-
self.parser.tag_state = TagState::Closed;
456+
self.parser.state = ParseState::ClosedTag;
457457

458458
match self.reader.peek_one() {
459459
// `<!` - comment, CDATA or DOCTYPE declaration

src/reader/parser.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::errors::{Error, Result};
1010
use crate::events::{BytesCData, BytesDecl, BytesEnd, BytesStart, BytesText, Event};
1111
#[cfg(feature = "encoding")]
1212
use crate::reader::EncodingRef;
13-
use crate::reader::{is_whitespace, BangType, TagState};
13+
use crate::reader::{is_whitespace, BangType, ParseState};
1414

1515
use memchr;
1616

@@ -19,21 +19,21 @@ use memchr;
1919
/// get back produced [`Event`]s.
2020
#[derive(Clone)]
2121
pub(super) struct Parser {
22-
/// current buffer position, useful for debugging errors
22+
/// Number of bytes read from the source of data since the parser was created
2323
pub offset: usize,
24-
/// current state Open/Close
25-
pub tag_state: TagState,
26-
/// expand empty element into an opening and closing element
24+
/// Defines how to process next byte
25+
pub state: ParseState,
26+
/// Expand empty element into an opening and closing element
2727
pub expand_empty_elements: bool,
28-
/// trims leading whitespace in Text events, skip the element if text is empty
28+
/// Trims leading whitespace in Text events, skip the element if text is empty
2929
pub trim_text_start: bool,
30-
/// trims trailing whitespace in Text events.
30+
/// Trims trailing whitespace in Text events.
3131
pub trim_text_end: bool,
32-
/// trims trailing whitespaces from markup names in closing tags `</a >`
32+
/// Trims trailing whitespaces from markup names in closing tags `</a >`
3333
pub trim_markup_names_in_closing_tags: bool,
34-
/// check if End nodes match last Start node
34+
/// Check if [`Event::End`] nodes match last [`Event::Start`] node
3535
pub check_end_names: bool,
36-
/// check if comments contains `--` (false per default)
36+
/// Check if comments contains `--` (false per default)
3737
pub check_comments: bool,
3838
/// All currently Started elements which didn't have a matching
3939
/// End element yet.
@@ -219,7 +219,7 @@ impl Parser {
219219
if let Some(&b'/') = buf.last() {
220220
let end = if name_end < len { name_end } else { len - 1 };
221221
if self.expand_empty_elements {
222-
self.tag_state = TagState::Empty;
222+
self.state = ParseState::Empty;
223223
self.opened_starts.push(self.opened_buffer.len());
224224
self.opened_buffer.extend(&buf[..end]);
225225
Ok(Event::Start(BytesStart::wrap(&buf[..len - 1], end)))
@@ -237,7 +237,7 @@ impl Parser {
237237

238238
#[inline]
239239
pub fn close_expanded_empty(&mut self) -> Result<Event<'static>> {
240-
self.tag_state = TagState::Closed;
240+
self.state = ParseState::ClosedTag;
241241
let name = self
242242
.opened_buffer
243243
.split_off(self.opened_starts.pop().unwrap());
@@ -263,7 +263,7 @@ impl Default for Parser {
263263
fn default() -> Self {
264264
Self {
265265
offset: 0,
266-
tag_state: TagState::Init,
266+
state: ParseState::Init,
267267
expand_empty_elements: false,
268268
trim_text_start: false,
269269
trim_text_end: false,

0 commit comments

Comments
 (0)