| 1 | use craterust-analyzer cargo xml-rs 0.8.19 crate/::readerrust-analyzer cargo xml-rs 0.8.19 reader/::errorrust-analyzer cargo xml-rs 0.8.19 reader/error/::SyntaxErrorrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#; |
| 2 | use craterust-analyzer cargo xml-rs 0.8.19 crate/::commonrust-analyzer cargo xml-rs 0.8.19 common/::{is_name_charrust-analyzer cargo xml-rs 0.8.19 common/is_name_char()., is_name_start_charrust-analyzer cargo xml-rs 0.8.19 common/is_name_start_char()., is_whitespace_charrust-analyzer cargo xml-rs 0.8.19 common/is_whitespace_char().}; |
| 3 | |
| 4 | use craterust-analyzer cargo xml-rs 0.8.19 crate/::readerrust-analyzer cargo xml-rs 0.8.19 reader/::eventsrust-analyzer cargo xml-rs 0.8.19 reader/events/::XmlEventrust-analyzer cargo xml-rs 0.8.19 reader/events/XmlEvent#; |
| 5 | use craterust-analyzer cargo xml-rs 0.8.19 crate/::readerrust-analyzer cargo xml-rs 0.8.19 reader/::lexerrust-analyzer cargo xml-rs 0.8.19 reader/lexer/::Tokenrust-analyzer cargo xml-rs 0.8.19 reader/lexer/Token#; |
| 6 | |
| 7 | use superrust-analyzer cargo xml-rs 0.8.19 reader/parser/::{DeclarationSubstaterust-analyzer cargo xml-rs 0.8.19 reader/parser/DeclarationSubstate#, ProcessingInstructionSubstaterust-analyzer cargo xml-rs 0.8.19 reader/parser/ProcessingInstructionSubstate#, PullParserrust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#, Resultrust-analyzer cargo xml-rs 0.8.19 reader/parser/Result#, Staterust-analyzer cargo xml-rs 0.8.19 reader/parser/State#, Encounteredrust-analyzer cargo xml-rs 0.8.19 reader/parser/Encountered#}; |
| 8 | |
| 9 | impl PullParserrust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser# { |
| 10 | pub fn inside_processing_instructionrust-analyzer cargo xml-rs 0.8.19 reader/parser/inside_processing_instruction/impl#[PullParser]inside_processing_instruction().(&mut self, t: Tokenrust-analyzer cargo xml-rs 0.8.19 reader/lexer/Token#, s: ProcessingInstructionSubstaterust-analyzer cargo xml-rs 0.8.19 reader/parser/ProcessingInstructionSubstate#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Resultrust-analyzer cargo xml-rs 0.8.19 reader/parser/Result#> { |
| 11 | match s { |
| 12 | ProcessingInstructionSubstaterust-analyzer cargo xml-rs 0.8.19 reader/parser/ProcessingInstructionSubstate#::PIInsideNamerust-analyzer cargo xml-rs 0.8.19 reader/parser/ProcessingInstructionSubstate#PIInsideName# => match t { |
| 13 | Tokenrust-analyzer cargo xml-rs 0.8.19 reader/lexer/Token#::Characterrust-analyzer cargo xml-rs 0.8.19 reader/lexer/Token#Character#(c) if self.bufrust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#buf..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() && is_name_start_charrust-analyzer cargo xml-rs 0.8.19 common/is_name_start_char().(c) || |
| 14 | self.buf_has_datarust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]buf_has_data().() && is_name_charrust-analyzer cargo xml-rs 0.8.19 common/is_name_char().(c) => { |
| 15 | if self.bufrust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#buf..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().self.configrust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#config..max_name_lengthrust-analyzer cargo xml-rs 0.8.19 reader/config/ParserConfig2#max_name_length. { |
| 16 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.errorrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]error().(SyntaxErrorrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#::ExceededConfiguredLimitrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#ExceededConfiguredLimit#)); |
| 17 | } |
| 18 | self.bufrust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#buf..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(c); |
| 19 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 20 | }, |
| 21 | |
| 22 | Tokenrust-analyzer cargo xml-rs 0.8.19 reader/lexer/Token#::ProcessingInstructionEndrust-analyzer cargo xml-rs 0.8.19 reader/lexer/Token#ProcessingInstructionEnd# => { |
| 23 | // self.buf contains PI name |
| 24 | let name = self.take_bufrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]take_buf().(); |
| 25 | |
| 26 | // Don't need to check for declaration because it has mandatory attributes |
| 27 | // but there is none |
| 28 | match &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().name { |
| 29 | // Name is empty, it is an error |
| 30 | "" => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.errorrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]error().(SyntaxErrorrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#::ProcessingInstructionWithoutNamerust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#ProcessingInstructionWithoutName#)), |
| 31 | |
| 32 | // Found <?xml-like PI not at the beginning of a document, |
| 33 | // it is an error - see section 2.6 of XML 1.1 spec |
| 34 | n if "xml".eq_ignore_ascii_caserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]eq_ignore_ascii_case().(n) => |
| 35 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.errorrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]error().(SyntaxErrorrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#::InvalidXmlProcessingInstructionrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#InvalidXmlProcessingInstruction#(name.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))), |
| 36 | |
| 37 | // All is ok, emitting event |
| 38 | _ => { |
| 39 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(self.next_eventrust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#next_event..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().(), "{:?}", self.next_eventrust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#next_event.); |
| 40 | // can't have a PI before `<?xml` |
| 41 | let event1 = self.set_encounteredrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]set_encountered().(Encounteredrust-analyzer cargo xml-rs 0.8.19 reader/parser/Encountered#::Declarationrust-analyzer cargo xml-rs 0.8.19 reader/parser/Encountered#Declaration#); |
| 42 | let event2 = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(XmlEventrust-analyzer cargo xml-rs 0.8.19 reader/events/XmlEvent#::ProcessingInstructionrust-analyzer cargo xml-rs 0.8.19 reader/events/XmlEvent#ProcessingInstruction# { |
| 43 | namerust-analyzer cargo xml-rs 0.8.19 reader/events/XmlEvent#ProcessingInstruction#name., |
| 44 | datarust-analyzer cargo xml-rs 0.8.19 reader/events/XmlEvent#ProcessingInstruction#data.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 45 | })); |
| 46 | // emitting two events at once is cumbersome |
| 47 | let event1 = if event1.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 48 | self.next_eventrust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#next_event. = event2; |
| 49 | event1 |
| 50 | } else { |
| 51 | event2 |
| 52 | }; |
| 53 | self.into_staterust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]into_state().(Staterust-analyzer cargo xml-rs 0.8.19 reader/parser/State#::OutsideTagrust-analyzer cargo xml-rs 0.8.19 reader/parser/State#OutsideTag#, event1) |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | Tokenrust-analyzer cargo xml-rs 0.8.19 reader/lexer/Token#::Characterrust-analyzer cargo xml-rs 0.8.19 reader/lexer/Token#Character#(c) if is_whitespace_charrust-analyzer cargo xml-rs 0.8.19 common/is_whitespace_char().(c) => { |
| 59 | // self.buf contains PI name |
| 60 | let name = self.take_bufrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]take_buf().(); |
| 61 | |
| 62 | match &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().name { |
| 63 | // We have not ever encountered an element and have not parsed XML declaration |
| 64 | "xml" if self.encounteredrust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#encountered. rust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[Encountered][`PartialEq<Self>`]eq().==rust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[Encountered][`PartialEq<Self>`]eq(). rust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[Encountered][`PartialEq<Self>`]eq().Encounteredrust-analyzer cargo xml-rs 0.8.19 reader/parser/Encountered#::Nonerust-analyzer cargo xml-rs 0.8.19 reader/parser/Encountered#None# => |
| 65 | self.into_state_continuerust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]into_state_continue().(Staterust-analyzer cargo xml-rs 0.8.19 reader/parser/State#::InsideDeclarationrust-analyzer cargo xml-rs 0.8.19 reader/parser/State#InsideDeclaration#(DeclarationSubstaterust-analyzer cargo xml-rs 0.8.19 reader/parser/DeclarationSubstate#::BeforeVersionrust-analyzer cargo xml-rs 0.8.19 reader/parser/DeclarationSubstate#BeforeVersion#)), |
| 66 | |
| 67 | // Found <?xml-like PI after the beginning of a document, |
| 68 | // it is an error - see section 2.6 of XML 1.1 spec |
| 69 | n if "xml".eq_ignore_ascii_caserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]eq_ignore_ascii_case().(n) => |
| 70 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.errorrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]error().(SyntaxErrorrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#::InvalidXmlProcessingInstructionrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#InvalidXmlProcessingInstruction#(name.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))), |
| 71 | |
| 72 | // All is ok, starting parsing PI data |
| 73 | _ => { |
| 74 | self.datarust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#data..namerust-analyzer cargo xml-rs 0.8.19 reader/parser/MarkupData#name. = name; |
| 75 | // can't have a PI before `<?xml` |
| 76 | let next_event = self.set_encounteredrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]set_encountered().(Encounteredrust-analyzer cargo xml-rs 0.8.19 reader/parser/Encountered#::Declarationrust-analyzer cargo xml-rs 0.8.19 reader/parser/Encountered#Declaration#); |
| 77 | self.into_staterust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]into_state().(Staterust-analyzer cargo xml-rs 0.8.19 reader/parser/State#::InsideProcessingInstructionrust-analyzer cargo xml-rs 0.8.19 reader/parser/State#InsideProcessingInstruction#(ProcessingInstructionSubstaterust-analyzer cargo xml-rs 0.8.19 reader/parser/ProcessingInstructionSubstate#::PIInsideDatarust-analyzer cargo xml-rs 0.8.19 reader/parser/ProcessingInstructionSubstate#PIInsideData#), next_event) |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | _ => { |
| 83 | let buf = self.take_bufrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]take_buf().(); |
| 84 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.errorrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]error().(SyntaxErrorrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#::UnexpectedProcessingInstructionrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#UnexpectedProcessingInstruction#(buf.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), t))) |
| 85 | } |
| 86 | }, |
| 87 | |
| 88 | ProcessingInstructionSubstaterust-analyzer cargo xml-rs 0.8.19 reader/parser/ProcessingInstructionSubstate#::PIInsideDatarust-analyzer cargo xml-rs 0.8.19 reader/parser/ProcessingInstructionSubstate#PIInsideData# => match t { |
| 89 | Tokenrust-analyzer cargo xml-rs 0.8.19 reader/lexer/Token#::ProcessingInstructionEndrust-analyzer cargo xml-rs 0.8.19 reader/lexer/Token#ProcessingInstructionEnd# => { |
| 90 | let name = self.datarust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#data..take_namerust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[MarkupData]take_name().(); |
| 91 | let data = self.take_bufrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]take_buf().(); |
| 92 | self.into_state_emitrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]into_state_emit().( |
| 93 | Staterust-analyzer cargo xml-rs 0.8.19 reader/parser/State#::OutsideTagrust-analyzer cargo xml-rs 0.8.19 reader/parser/State#OutsideTag#, |
| 94 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(XmlEventrust-analyzer cargo xml-rs 0.8.19 reader/events/XmlEvent#::ProcessingInstructionrust-analyzer cargo xml-rs 0.8.19 reader/events/XmlEvent#ProcessingInstruction# { |
| 95 | namerust-analyzer cargo xml-rs 0.8.19 reader/events/XmlEvent#ProcessingInstruction#name., |
| 96 | datarust-analyzer cargo xml-rs 0.8.19 reader/events/XmlEvent#ProcessingInstruction#data.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(data), |
| 97 | }), |
| 98 | ) |
| 99 | }, |
| 100 | |
| 101 | Tokenrust-analyzer cargo xml-rs 0.8.19 reader/lexer/Token#::Characterrust-analyzer cargo xml-rs 0.8.19 reader/lexer/Token#Character#(c) if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_valid_xml_charrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]is_valid_xml_char().(c) => { |
| 102 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.errorrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]error().(SyntaxErrorrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#::InvalidCharacterEntityrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#InvalidCharacterEntity#(c as u32))) |
| 103 | }, |
| 104 | |
| 105 | // Any other token should be treated as plain characters |
| 106 | _ => { |
| 107 | if self.bufrust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#buf..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().self.configrust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#config..max_data_lengthrust-analyzer cargo xml-rs 0.8.19 reader/config/ParserConfig2#max_data_length. { |
| 108 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.errorrust-analyzer cargo xml-rs 0.8.19 reader/parser/impl#[PullParser]error().(SyntaxErrorrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#::ExceededConfiguredLimitrust-analyzer cargo xml-rs 0.8.19 reader/error/SyntaxError#ExceededConfiguredLimit#)); |
| 109 | } |
| 110 | t.push_to_stringrust-analyzer cargo xml-rs 0.8.19 reader/lexer/impl#[Token]push_to_string().(&mut self.bufrust-analyzer cargo xml-rs 0.8.19 reader/parser/PullParser#buf.); |
| 111 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 112 | } |
| 113 | }, |
| 114 | } |
| 115 | } |
| 116 | } |