aboutsummaryrefslogtreecommitdiff
path: root/src/reader/parser/inside_closing_tag_name.rs
blob: 6d86808af0de73a25b80bdc44e753fe1b2e76445 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::reader::error::SyntaxError;
use crate::{common::is_whitespace_char, namespace};
use crate::reader::lexer::Token;
use super::{ClosingTagSubstate, PullParser, QualifiedNameTarget, Result, State};

impl PullParser {
    pub fn inside_closing_tag_name(&mut self, t: Token, s: ClosingTagSubstate) -> Option<Result> {
        match s {
            ClosingTagSubstate::CTInsideName => self.read_qualified_name(t, QualifiedNameTarget::ClosingTagNameTarget, |this, token, name| {
                match name.prefix_ref() {
                    Some(prefix) if prefix == namespace::NS_XML_PREFIX ||
                                    prefix == namespace::NS_XMLNS_PREFIX =>
                        Some(this.error(SyntaxError::InvalidNamePrefix(prefix.into()))),
                    _ => {
                        this.data.element_name = Some(name.clone());
                        match token {
                            Token::TagEnd => this.emit_end_element(),
                            Token::Character(c) if is_whitespace_char(c) => this.into_state_continue(State::InsideClosingTag(ClosingTagSubstate::CTAfterName)),
                            _ => Some(this.error(SyntaxError::UnexpectedTokenInClosingTag(token)))
                        }
                    }
                }
            }),
            ClosingTagSubstate::CTAfterName => match t {
                Token::TagEnd => self.emit_end_element(),
                Token::Character(c) if is_whitespace_char(c) => None,  //  Skip whitespace
                _ => Some(self.error(SyntaxError::UnexpectedTokenInClosingTag(t)))
            }
        }
    }
}