| 1 | //! Fluent Translation List serialization utilities |
| 2 | //! |
| 3 | //! This modules provides a way to serialize an abstract syntax tree representing a |
| 4 | //! Fluent Translation List. Use cases include normalization and programmatic |
| 5 | //! manipulation of a Fluent Translation List. |
| 6 | //! |
| 7 | //! # Example |
| 8 | //! |
| 9 | //! ``` |
| 10 | //! use fluent_syntax::parser; |
| 11 | //! use fluent_syntax::serializer; |
| 12 | //! |
| 13 | //! let ftl = r#"# This is a message comment |
| 14 | //! hello-world = Hello World! |
| 15 | //! "#; |
| 16 | //! |
| 17 | //! let resource = parser::parse(ftl).expect("Failed to parse an FTL resource."); |
| 18 | //! |
| 19 | //! let serialized = serializer::serialize(&resource); |
| 20 | //! |
| 21 | //! assert_eq!(ftl, serialized); |
| 22 | //! ``` |
| 23 | |
| 24 | use craterust-analyzer cargo fluent-syntax 0.12.0 crate/::{astrust-analyzer cargo fluent-syntax 0.12.0 ast/::*, parserrust-analyzer cargo fluent-syntax 0.12.0 parser/::matches_fluent_wsrust-analyzer cargo fluent-syntax 0.12.0 parser/slice/matches_fluent_ws()., parserrust-analyzer cargo fluent-syntax 0.12.0 parser/::Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#}; |
| 25 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#; |
| 26 | |
| 27 | /// Serializes an abstract syntax tree representing a Fluent Translation List into a |
| 28 | /// String. |
| 29 | /// |
| 30 | /// # Example |
| 31 | /// |
| 32 | /// ``` |
| 33 | /// use fluent_syntax::parser; |
| 34 | /// use fluent_syntax::serializer; |
| 35 | /// |
| 36 | /// let ftl = r#" |
| 37 | /// unnormalized-message=This message has |
| 38 | /// abnormal spacing and indentation"#; |
| 39 | /// |
| 40 | /// let resource = parser::parse(ftl).expect("Failed to parse an FTL resource."); |
| 41 | /// |
| 42 | /// let serialized = serializer::serialize(&resource); |
| 43 | /// |
| 44 | /// let expected = r#"unnormalized-message = |
| 45 | /// This message has |
| 46 | /// abnormal spacing and indentation |
| 47 | /// "#; |
| 48 | /// |
| 49 | /// assert_eq!(expected, serialized); |
| 50 | /// ``` |
| 51 | pub fn serializerust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(resource: &Resourcerust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#<S>) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 52 | serialize_with_optionsrust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize_with_options().(resource, Optionsrust-analyzer cargo fluent-syntax 0.12.0 serializer/Options#::defaultrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Options][Default]default().()) |
| 53 | } |
| 54 | |
| 55 | /// Serializes an abstract syntax tree representing a Fluent Translation List into a |
| 56 | /// String accepting custom options. |
| 57 | pub fn serialize_with_optionsrust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize_with_options().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>( |
| 58 | resource: &Resourcerust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#<S>, |
| 59 | options: Optionsrust-analyzer cargo fluent-syntax 0.12.0 serializer/Options#, |
| 60 | ) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 61 | let mut ser = Serializerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#::newrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]new().(options); |
| 62 | ser.serialize_resourcerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_resource().(resource); |
| 63 | ser.into_serialized_textrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]into_serialized_text().() |
| 64 | } |
| 65 | |
| 66 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 67 | struct Serializerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer# { |
| 68 | writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer.: TextWriterrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#, |
| 69 | optionsrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#options.: Optionsrust-analyzer cargo fluent-syntax 0.12.0 serializer/Options#, |
| 70 | staterust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#state.: Staterust-analyzer cargo fluent-syntax 0.12.0 serializer/State#, |
| 71 | } |
| 72 | |
| 73 | impl Serializerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer# { |
| 74 | fn newrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]new().(options: Optionsrust-analyzer cargo fluent-syntax 0.12.0 serializer/Options#) -> Selfrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer] { |
| 75 | Serializerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer# { |
| 76 | writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer.: TextWriterrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#::defaultrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter][Default]default().(), |
| 77 | optionsrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#options., |
| 78 | staterust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#state.: Staterust-analyzer cargo fluent-syntax 0.12.0 serializer/State#::defaultrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[State][Default]default().(), |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | fn serialize_resourcerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_resource().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, res: &Resourcerust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#<S>) { |
| 83 | for entry in &res.bodyrust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#body. { |
| 84 | match entry { |
| 85 | Entryrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#::Messagerust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#Message#(msg) => self.serialize_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_message().(msg), |
| 86 | Entryrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#::Termrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#Term#(term) => self.serialize_termrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_term().(term), |
| 87 | Entryrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#::Commentrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#Comment#(comment) => self.serialize_free_commentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_free_comment().(comment, "#"), |
| 88 | Entryrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#::GroupCommentrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#GroupComment#(comment) => self.serialize_free_commentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_free_comment().(comment, "##"), |
| 89 | Entryrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#::ResourceCommentrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#ResourceComment#(comment) => self.serialize_free_commentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_free_comment().(comment, "###"), |
| 90 | Entryrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#::Junkrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#Junk# { contentrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#Junk#content. } => { |
| 91 | if self.optionsrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#options..with_junkrust-analyzer cargo fluent-syntax 0.12.0 serializer/Options#with_junk. { |
| 92 | self.serialize_junkrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_junk().(content.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 93 | } |
| 94 | } |
| 95 | }; |
| 96 | |
| 97 | self.staterust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#state..wrote_non_junk_entryrust-analyzer cargo fluent-syntax 0.12.0 serializer/State#wrote_non_junk_entry. = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(entry, Entryrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#::Junkrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#Junk# { .. }); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | fn into_serialized_textrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]into_serialized_text().(self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 102 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..bufferrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#buffer. |
| 103 | } |
| 104 | |
| 105 | fn serialize_junkrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_junk().(&mut self, junk: &str) { |
| 106 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(junk); |
| 107 | } |
| 108 | |
| 109 | fn serialize_free_commentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_free_comment().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, comment: &Commentrust-analyzer cargo fluent-syntax 0.12.0 ast/Comment#<S>, prefix: &str) { |
| 110 | if self.staterust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#state..wrote_non_junk_entryrust-analyzer cargo fluent-syntax 0.12.0 serializer/State#wrote_non_junk_entry. { |
| 111 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(); |
| 112 | } |
| 113 | self.serialize_commentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_comment().(comment, prefix); |
| 114 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(); |
| 115 | } |
| 116 | |
| 117 | fn serialize_commentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_comment().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, comment: &Commentrust-analyzer cargo fluent-syntax 0.12.0 ast/Comment#<S>, prefix: &str) { |
| 118 | for line in &comment.contentrust-analyzer cargo fluent-syntax 0.12.0 ast/Comment#content. { |
| 119 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(prefix); |
| 120 | |
| 121 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().line.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().trim_matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_matches().(matches_fluent_wsrust-analyzer cargo fluent-syntax 0.12.0 parser/slice/matches_fluent_ws().).is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() { |
| 122 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(" "); |
| 123 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(line.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 124 | } |
| 125 | |
| 126 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | fn serialize_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_message().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, msg: &Messagerust-analyzer cargo fluent-syntax 0.12.0 ast/Message#<S>) { |
| 131 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(comment) = msg.commentrust-analyzer cargo fluent-syntax 0.12.0 ast/Message#comment..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() { |
| 132 | self.serialize_commentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_comment().(comment, "#"); |
| 133 | } |
| 134 | |
| 135 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(msg.idrust-analyzer cargo fluent-syntax 0.12.0 ast/Message#id..namerust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#name..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 136 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(" ="); |
| 137 | |
| 138 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = msg.valuerust-analyzer cargo fluent-syntax 0.12.0 ast/Message#value..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() { |
| 139 | self.serialize_patternrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_pattern().(value); |
| 140 | } |
| 141 | |
| 142 | self.serialize_attributesrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_attributes().(&msg.attributesrust-analyzer cargo fluent-syntax 0.12.0 ast/Message#attributes.); |
| 143 | |
| 144 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(); |
| 145 | } |
| 146 | |
| 147 | fn serialize_termrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_term().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, term: &Termrust-analyzer cargo fluent-syntax 0.12.0 ast/Term#<S>) { |
| 148 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(comment) = term.commentrust-analyzer cargo fluent-syntax 0.12.0 ast/Term#comment..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() { |
| 149 | self.serialize_commentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_comment().(comment, "#"); |
| 150 | } |
| 151 | |
| 152 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("-"); |
| 153 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(term.idrust-analyzer cargo fluent-syntax 0.12.0 ast/Term#id..namerust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#name..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 154 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(" ="); |
| 155 | self.serialize_patternrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_pattern().(&term.valuerust-analyzer cargo fluent-syntax 0.12.0 ast/Term#value.); |
| 156 | |
| 157 | self.serialize_attributesrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_attributes().(&term.attributesrust-analyzer cargo fluent-syntax 0.12.0 ast/Term#attributes.); |
| 158 | |
| 159 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(); |
| 160 | } |
| 161 | |
| 162 | fn serialize_patternrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_pattern().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, pattern: &Patternrust-analyzer cargo fluent-syntax 0.12.0 ast/Pattern#<S>) { |
| 163 | let start_on_newline = pattern.starts_on_new_linerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[`Pattern<S>`]starts_on_new_line().(); |
| 164 | |
| 165 | if start_on_newline { |
| 166 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(); |
| 167 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..indentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]indent().(); |
| 168 | } else { |
| 169 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(" "); |
| 170 | } |
| 171 | |
| 172 | for element in &pattern.elementsrust-analyzer cargo fluent-syntax 0.12.0 ast/Pattern#elements. { |
| 173 | self.serialize_elementrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_element().(element); |
| 174 | } |
| 175 | |
| 176 | if start_on_newline { |
| 177 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..dedentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]dedent().(); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | fn serialize_attributesrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_attributes().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, attrs: &[Attributerust-analyzer cargo fluent-syntax 0.12.0 ast/Attribute#<S>]) { |
| 182 | if attrs.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..indentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]indent().(); |
| 187 | |
| 188 | for attr in attrs { |
| 189 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(); |
| 190 | self.serialize_attributerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_attribute().(attr); |
| 191 | } |
| 192 | |
| 193 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..dedentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]dedent().(); |
| 194 | } |
| 195 | |
| 196 | fn serialize_attributerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_attribute().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, attr: &Attributerust-analyzer cargo fluent-syntax 0.12.0 ast/Attribute#<S>) { |
| 197 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("."); |
| 198 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(attr.idrust-analyzer cargo fluent-syntax 0.12.0 ast/Attribute#id..namerust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#name..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 199 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(" ="); |
| 200 | |
| 201 | self.serialize_patternrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_pattern().(&attr.valuerust-analyzer cargo fluent-syntax 0.12.0 ast/Attribute#value.); |
| 202 | } |
| 203 | |
| 204 | fn serialize_elementrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_element().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, elem: &PatternElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#<S>) { |
| 205 | match elem { |
| 206 | PatternElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#::TextElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#TextElement# { valuerust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#TextElement#value. } => self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(value.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()), |
| 207 | PatternElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#::Placeablerust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#Placeable# { expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#Placeable#expression. } => match expression { |
| 208 | Expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#::Inlinerust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Inline#(InlineExpressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#::Placeablerust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#Placeable# { expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#Placeable#expression. }) => { |
| 209 | // A placeable inside a placeable is a special case because we |
| 210 | // don't want the braces to look silly (e.g. "{ { Foo() } }"). |
| 211 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("{{ "); |
| 212 | self.serialize_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_expression().(expression); |
| 213 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(" }}"); |
| 214 | } |
| 215 | Expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#::Selectrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Select# { .. } => { |
| 216 | // select adds its own newline and indent, emit the brace |
| 217 | // *without* a space so we don't get 5 spaces instead of 4 |
| 218 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("{ "); |
| 219 | self.serialize_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_expression().(expression); |
| 220 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("}"); |
| 221 | } |
| 222 | Expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#::Inlinerust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Inline#(_) => { |
| 223 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("{ "); |
| 224 | self.serialize_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_expression().(expression); |
| 225 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(" }"); |
| 226 | } |
| 227 | }, |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | fn serialize_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_expression().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, expr: &Expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#<S>) { |
| 232 | match expr { |
| 233 | Expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#::Inlinerust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Inline#(inline) => self.serialize_inline_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_inline_expression().(inline), |
| 234 | Expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#::Selectrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Select# { selectorrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Select#selector., variantsrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Select#variants. } => { |
| 235 | self.serialize_select_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_select_expression().(selector, variants); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | fn serialize_inline_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_inline_expression().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, expr: &InlineExpressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#<S>) { |
| 241 | match expr { |
| 242 | InlineExpressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#::StringLiteralrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#StringLiteral# { valuerust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#StringLiteral#value. } => { |
| 243 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("\""); |
| 244 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(value.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 245 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("\""); |
| 246 | } |
| 247 | InlineExpressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#::NumberLiteralrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#NumberLiteral# { valuerust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#NumberLiteral#value. } => self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(value.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()), |
| 248 | InlineExpressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#::VariableReferencerust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#VariableReference# { |
| 249 | idrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#VariableReference#id.: Identifierrust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier# { namerust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#name.: value }, |
| 250 | } => { |
| 251 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("$"); |
| 252 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(value.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 253 | } |
| 254 | InlineExpressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#::FunctionReferencerust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#FunctionReference# { idrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#FunctionReference#id., argumentsrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#FunctionReference#arguments. } => { |
| 255 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(id.namerust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#name..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 256 | self.serialize_call_argumentsrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_call_arguments().(arguments); |
| 257 | } |
| 258 | InlineExpressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#::MessageReferencerust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#MessageReference# { idrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#MessageReference#id., attributerust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#MessageReference#attribute. } => { |
| 259 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(id.namerust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#name..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 260 | |
| 261 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(attr) = attribute.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() { |
| 262 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("."); |
| 263 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(attr.namerust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#name..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 264 | } |
| 265 | } |
| 266 | InlineExpressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#::TermReferencerust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#TermReference# { |
| 267 | idrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#TermReference#id., |
| 268 | attributerust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#TermReference#attribute., |
| 269 | argumentsrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#TermReference#arguments., |
| 270 | } => { |
| 271 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("-"); |
| 272 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(id.namerust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#name..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 273 | |
| 274 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(attr) = attribute.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() { |
| 275 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("."); |
| 276 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(attr.namerust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#name..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 277 | } |
| 278 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(args) = arguments.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() { |
| 279 | self.serialize_call_argumentsrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_call_arguments().(args); |
| 280 | } |
| 281 | } |
| 282 | InlineExpressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#::Placeablerust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#Placeable# { expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#Placeable#expression. } => { |
| 283 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("{"); |
| 284 | self.serialize_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_expression().(expression); |
| 285 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("}"); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | fn serialize_select_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_select_expression().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>( |
| 291 | &mut self, |
| 292 | selector: &InlineExpressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#<S>, |
| 293 | variants: &[Variantrust-analyzer cargo fluent-syntax 0.12.0 ast/Variant#<S>], |
| 294 | ) { |
| 295 | self.serialize_inline_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_inline_expression().(selector); |
| 296 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(" ->"); |
| 297 | |
| 298 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(); |
| 299 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..indentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]indent().(); |
| 300 | |
| 301 | for variant in variants { |
| 302 | self.serialize_variantrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_variant().(variant); |
| 303 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(); |
| 304 | } |
| 305 | |
| 306 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..dedentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]dedent().(); |
| 307 | } |
| 308 | |
| 309 | fn serialize_variantrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_variant().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, variant: &Variantrust-analyzer cargo fluent-syntax 0.12.0 ast/Variant#<S>) { |
| 310 | if variant.defaultrust-analyzer cargo fluent-syntax 0.12.0 ast/Variant#default. { |
| 311 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_char_into_indentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_char_into_indent().('*'); |
| 312 | } |
| 313 | |
| 314 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("["); |
| 315 | self.serialize_variant_keyrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_variant_key().(&variant.keyrust-analyzer cargo fluent-syntax 0.12.0 ast/Variant#key.); |
| 316 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("]"); |
| 317 | self.serialize_patternrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_pattern().(&variant.valuerust-analyzer cargo fluent-syntax 0.12.0 ast/Variant#value.); |
| 318 | } |
| 319 | |
| 320 | fn serialize_variant_keyrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_variant_key().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, key: &VariantKeyrust-analyzer cargo fluent-syntax 0.12.0 ast/VariantKey#<S>) { |
| 321 | match key { |
| 322 | VariantKeyrust-analyzer cargo fluent-syntax 0.12.0 ast/VariantKey#::NumberLiteralrust-analyzer cargo fluent-syntax 0.12.0 ast/VariantKey#NumberLiteral# { valuerust-analyzer cargo fluent-syntax 0.12.0 ast/VariantKey#NumberLiteral#value. } | VariantKeyrust-analyzer cargo fluent-syntax 0.12.0 ast/VariantKey#::Identifierrust-analyzer cargo fluent-syntax 0.12.0 ast/VariantKey#Identifier# { namerust-analyzer cargo fluent-syntax 0.12.0 ast/VariantKey#Identifier#name.: value } => { |
| 323 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(value.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | fn serialize_call_argumentsrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_call_arguments().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(&mut self, args: &CallArgumentsrust-analyzer cargo fluent-syntax 0.12.0 ast/CallArguments#<S>) { |
| 329 | let mut argument_written = false; |
| 330 | |
| 331 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("("); |
| 332 | |
| 333 | for positional in &args.positionalrust-analyzer cargo fluent-syntax 0.12.0 ast/CallArguments#positional. { |
| 334 | if argument_written { |
| 335 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(", "); |
| 336 | } |
| 337 | |
| 338 | self.serialize_inline_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_inline_expression().(positional); |
| 339 | argument_written = true; |
| 340 | } |
| 341 | |
| 342 | for named in &args.namedrust-analyzer cargo fluent-syntax 0.12.0 ast/CallArguments#named. { |
| 343 | if argument_written { |
| 344 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(", "); |
| 345 | } |
| 346 | |
| 347 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(named.namerust-analyzer cargo fluent-syntax 0.12.0 ast/NamedArgument#name..namerust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#name..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 348 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(": "); |
| 349 | self.serialize_inline_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[Serializer]serialize_inline_expression().(&named.valuerust-analyzer cargo fluent-syntax 0.12.0 ast/NamedArgument#value.); |
| 350 | argument_written = true; |
| 351 | } |
| 352 | |
| 353 | self.writerrust-analyzer cargo fluent-syntax 0.12.0 serializer/Serializer#writer..write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(")"); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | impl<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>> Patternrust-analyzer cargo fluent-syntax 0.12.0 ast/Pattern#<S> { |
| 358 | fn starts_on_new_linerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[`Pattern<S>`]starts_on_new_line().(&self) -> bool { |
| 359 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.has_leading_text_dotrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[`Pattern<S>`]has_leading_text_dot().() && self.is_multilinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[`Pattern<S>`]is_multiline().() |
| 360 | } |
| 361 | |
| 362 | fn is_multilinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[`Pattern<S>`]is_multiline().(&self) -> bool { |
| 363 | self.elementsrust-analyzer cargo fluent-syntax 0.12.0 ast/Pattern#elements..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|elem| match elem { |
| 364 | PatternElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#::TextElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#TextElement# { valuerust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#TextElement#value. } => value.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().('\n'), |
| 365 | PatternElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#::Placeablerust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#Placeable# { expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#Placeable#expression. } => is_select_exprrust-analyzer cargo fluent-syntax 0.12.0 serializer/is_select_expr().(expression), |
| 366 | }) |
| 367 | } |
| 368 | |
| 369 | fn has_leading_text_dotrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[`Pattern<S>`]has_leading_text_dot().(&self) -> bool { |
| 370 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(PatternElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#::TextElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#TextElement# { valuerust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#TextElement#value. }) = self.elementsrust-analyzer cargo fluent-syntax 0.12.0 ast/Pattern#elements..firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().() { |
| 371 | value.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('.') |
| 372 | } else { |
| 373 | false |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | fn is_select_exprrust-analyzer cargo fluent-syntax 0.12.0 serializer/is_select_expr().<'s, S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>>(expr: &Expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#<S>) -> bool { |
| 379 | match expr { |
| 380 | Expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#::Selectrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Select# { .. } => true, |
| 381 | Expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#::Inlinerust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Inline#(InlineExpressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#::Placeablerust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#Placeable# { expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#Placeable#expression. }) => { |
| 382 | is_select_exprrust-analyzer cargo fluent-syntax 0.12.0 serializer/is_select_expr().(expression) |
| 383 | } |
| 384 | Expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#::Inlinerust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Inline#(_) => false, |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | /// Options for serializing an abstract syntax tree. |
| 389 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 390 | pub struct Optionsrust-analyzer cargo fluent-syntax 0.12.0 serializer/Options# { |
| 391 | /// Whether invalid text fragments should be serialized, too. |
| 392 | pub with_junkrust-analyzer cargo fluent-syntax 0.12.0 serializer/Options#with_junk.: bool, |
| 393 | } |
| 394 | |
| 395 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 396 | struct Staterust-analyzer cargo fluent-syntax 0.12.0 serializer/State# { |
| 397 | wrote_non_junk_entryrust-analyzer cargo fluent-syntax 0.12.0 serializer/State#wrote_non_junk_entry.: bool, |
| 398 | } |
| 399 | |
| 400 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 401 | struct TextWriterrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter# { |
| 402 | bufferrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#buffer.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 403 | indent_levelrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#indent_level.: usize, |
| 404 | } |
| 405 | |
| 406 | impl TextWriterrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter# { |
| 407 | fn indentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]indent().(&mut self) { |
| 408 | self.indent_levelrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#indent_level. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 409 | } |
| 410 | |
| 411 | fn dedentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]dedent().(&mut self) { |
| 412 | self.indent_levelrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#indent_level. = self |
| 413 | .indent_levelrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#indent_level. |
| 414 | .checked_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_sub().(1) |
| 415 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Dedenting without a corresponding indent"); |
| 416 | } |
| 417 | |
| 418 | fn write_indentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_indent().(&mut self) { |
| 419 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.indent_levelrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#indent_level. { |
| 420 | self.bufferrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#buffer..push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(" "); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | fn newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(&mut self) { |
| 425 | if self.bufferrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#buffer..ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('\r') { |
| 426 | // handle rare edge case, where the trailing `\r` would get confused |
| 427 | // as part of the line ending |
| 428 | self.bufferrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#buffer..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\r'); |
| 429 | } |
| 430 | self.bufferrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#buffer..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\n'); |
| 431 | } |
| 432 | |
| 433 | fn write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().(&mut self, item: &str) { |
| 434 | if self.bufferrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#buffer..ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('\n') { |
| 435 | // we've just added a newline, make sure it's properly indented |
| 436 | self.write_indentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_indent().(); |
| 437 | } |
| 438 | |
| 439 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(self.bufferrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#buffer., "{}", item).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Writing to an in-memory buffer never fails"); |
| 440 | } |
| 441 | |
| 442 | fn write_char_into_indentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_char_into_indent().(&mut self, ch: char) { |
| 443 | if self.bufferrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#buffer..ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('\n') { |
| 444 | self.write_indentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_indent().(); |
| 445 | } |
| 446 | self.bufferrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#buffer..poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]pop().(); |
| 447 | self.bufferrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#buffer..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(ch); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | #[cfg(test)] |
| 452 | mod testrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/ { |
| 453 | use superrust-analyzer cargo fluent-syntax 0.12.0 serializer/::*; |
| 454 | use craterust-analyzer cargo fluent-syntax 0.12.0 crate/::parserrust-analyzer cargo fluent-syntax 0.12.0 parser/::parserust-analyzer cargo fluent-syntax 0.12.0 parser/parse().; |
| 455 | |
| 456 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 457 | fn write_something_then_indentrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/write_something_then_indent().() { |
| 458 | let mut writer = TextWriterrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#::defaultrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter][Default]default().(); |
| 459 | |
| 460 | writer.write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("foo ="); |
| 461 | writer.newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(); |
| 462 | writer.indentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]indent().(); |
| 463 | writer.write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("first line"); |
| 464 | writer.newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(); |
| 465 | writer.write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("second line"); |
| 466 | writer.newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(); |
| 467 | writer.dedentrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]dedent().(); |
| 468 | writer.write_literalrust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]write_literal().("not indented"); |
| 469 | writer.newlinerust-analyzer cargo fluent-syntax 0.12.0 serializer/impl#[TextWriter]newline().(); |
| 470 | |
| 471 | let got = &writer.bufferrust-analyzer cargo fluent-syntax 0.12.0 serializer/TextWriter#buffer.; |
| 472 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 473 | got, |
| 474 | "foo =\n first line\n second line\nnot indented\n" |
| 475 | ); |
| 476 | } |
| 477 | |
| 478 | macro_rules! text_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/text_message! { |
| 479 | ($name:expr, $value:expr) => { |
| 480 | Entry::Message(Message { |
| 481 | id: Identifier { name: $name }, |
| 482 | value: Some(Pattern { |
| 483 | elements: vec![PatternElement::TextElement { value: $value }], |
| 484 | }), |
| 485 | attributes: vec![], |
| 486 | comment: None, |
| 487 | }) |
| 488 | }; |
| 489 | } |
| 490 | |
| 491 | impl<'a> Entryrust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#<&'a str> { |
| 492 | fn as_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Entry<&'a str>`]as_message().(&mut self) -> &mut Messagerust-analyzer cargo fluent-syntax 0.12.0 ast/Message#<&'a str> { |
| 493 | match self { |
| 494 | Selfrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Entry<&'a str>`]::Messagerust-analyzer cargo fluent-syntax 0.12.0 ast/Entry#Message#(msg) => msg, |
| 495 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected Message"), |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | impl<'a> Messagerust-analyzer cargo fluent-syntax 0.12.0 ast/Message#<&'a str> { |
| 501 | fn as_patternrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Message<&'a str>`]as_pattern().(&mut self) -> &mut Patternrust-analyzer cargo fluent-syntax 0.12.0 ast/Pattern#<&'a str> { |
| 502 | self.valuerust-analyzer cargo fluent-syntax 0.12.0 ast/Message#value..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Expected Pattern") |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | impl<'a> PatternElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#<&'a str> { |
| 507 | fn as_textrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`PatternElement<&'a str>`]as_text().(&mut self) -> &mut &'a str { |
| 508 | match self { |
| 509 | Selfrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`PatternElement<&'a str>`]::TextElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#TextElement# { valuerust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#TextElement#value. } => value, |
| 510 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected TextElement"), |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | fn as_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`PatternElement<&'a str>`]as_expression().(&mut self) -> &mut Expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#<&'a str> { |
| 515 | match self { |
| 516 | Selfrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`PatternElement<&'a str>`]::Placeablerust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#Placeable# { expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#Placeable#expression. } => expression, |
| 517 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected Placeable"), |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | impl<'a> Expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#<&'a str> { |
| 523 | fn as_variantsrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Expression<&'a str>`]as_variants().(&mut self) -> &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Variantrust-analyzer cargo fluent-syntax 0.12.0 ast/Variant#<&'a str>> { |
| 524 | match self { |
| 525 | Selfrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Expression<&'a str>`]::Selectrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Select# { variantsrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Select#variants., .. } => variants, |
| 526 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected Select"), |
| 527 | } |
| 528 | } |
| 529 | fn as_inline_variable_idrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Expression<&'a str>`]as_inline_variable_id().(&mut self) -> &mut Identifierrust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#<&'a str> { |
| 530 | match self { |
| 531 | Selfrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Expression<&'a str>`]::Inlinerust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Inline#(InlineExpressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#::VariableReferencerust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#VariableReference# { idrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#VariableReference#id. }) => id, |
| 532 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Expected Inline"), |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 538 | fn change_idrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/change_id().() { |
| 539 | let mut ast = parserust-analyzer cargo fluent-syntax 0.12.0 parser/parse().("foo = bar\n").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to parse ftl resource"); |
| 540 | ast.bodyrust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#body.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..as_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Entry<&'a str>`]as_message().().idrust-analyzer cargo fluent-syntax 0.12.0 ast/Message#id..namerust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#name. = "baz"; |
| 541 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(serializerust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize().(&ast), "baz = bar\n"); |
| 542 | } |
| 543 | |
| 544 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 545 | fn change_valuerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/change_value().() { |
| 546 | let mut ast = parserust-analyzer cargo fluent-syntax 0.12.0 parser/parse().("foo = bar\n").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to parse ftl resource"); |
| 547 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().ast.bodyrust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#body.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..as_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Entry<&'a str>`]as_message().().as_patternrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Message<&'a str>`]as_pattern().().elementsrust-analyzer cargo fluent-syntax 0.12.0 ast/Pattern#elements.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..as_textrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`PatternElement<&'a str>`]as_text().() = "baz"; |
| 548 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("foo = baz\n", serializerust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize().(&ast)); |
| 549 | } |
| 550 | |
| 551 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 552 | fn add_expression_variantrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/add_expression_variant().() { |
| 553 | let message = concatrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/concat!!( |
| 554 | "foo =\n", |
| 555 | " { $num ->\n", |
| 556 | " *[other] { $num } bars\n", |
| 557 | " }\n" |
| 558 | ); |
| 559 | let mut ast = parserust-analyzer cargo fluent-syntax 0.12.0 parser/parse().(message).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to parse ftl resource"); |
| 560 | |
| 561 | let one_variant = Variantrust-analyzer cargo fluent-syntax 0.12.0 ast/Variant# { |
| 562 | keyrust-analyzer cargo fluent-syntax 0.12.0 ast/Variant#key.: VariantKeyrust-analyzer cargo fluent-syntax 0.12.0 ast/VariantKey#::Identifierrust-analyzer cargo fluent-syntax 0.12.0 ast/VariantKey#Identifier# { namerust-analyzer cargo fluent-syntax 0.12.0 ast/VariantKey#Identifier#name.: "one" }, |
| 563 | valuerust-analyzer cargo fluent-syntax 0.12.0 ast/Variant#value.: Patternrust-analyzer cargo fluent-syntax 0.12.0 ast/Pattern# { |
| 564 | elementsrust-analyzer cargo fluent-syntax 0.12.0 ast/Pattern#elements.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 565 | PatternElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#::Placeablerust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#Placeable# { |
| 566 | expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#Placeable#expression.: Expressionrust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#::Inlinerust-analyzer cargo fluent-syntax 0.12.0 ast/Expression#Inline#(InlineExpressionrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#::VariableReferencerust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#VariableReference# { |
| 567 | idrust-analyzer cargo fluent-syntax 0.12.0 ast/InlineExpression#VariableReference#id.: Identifierrust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier# { namerust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#name.: "num" }, |
| 568 | }), |
| 569 | }, |
| 570 | PatternElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#::TextElementrust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#TextElement# { valuerust-analyzer cargo fluent-syntax 0.12.0 ast/PatternElement#TextElement#value.: " bar" }, |
| 571 | ], |
| 572 | }, |
| 573 | defaultrust-analyzer cargo fluent-syntax 0.12.0 ast/Variant#default.: false, |
| 574 | }; |
| 575 | ast.bodyrust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#body.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..as_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Entry<&'a str>`]as_message().().as_patternrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Message<&'a str>`]as_pattern().().elementsrust-analyzer cargo fluent-syntax 0.12.0 ast/Pattern#elements.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). |
| 576 | .as_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`PatternElement<&'a str>`]as_expression().() |
| 577 | .as_variantsrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Expression<&'a str>`]as_variants().() |
| 578 | .insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().(0, one_variant); |
| 579 | |
| 580 | let expected = concatrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/concat!!( |
| 581 | "foo =\n", |
| 582 | " { $num ->\n", |
| 583 | " [one] { $num } bar\n", |
| 584 | " *[other] { $num } bars\n", |
| 585 | " }\n" |
| 586 | ); |
| 587 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(serializerust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize().(&ast), expected); |
| 588 | } |
| 589 | |
| 590 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 591 | fn change_variable_referencerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/change_variable_reference().() { |
| 592 | let mut ast = parserust-analyzer cargo fluent-syntax 0.12.0 parser/parse().("foo = { $bar }\n").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to parse ftl resource"); |
| 593 | ast.bodyrust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#body.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..as_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Entry<&'a str>`]as_message().().as_patternrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Message<&'a str>`]as_pattern().().elementsrust-analyzer cargo fluent-syntax 0.12.0 ast/Pattern#elements.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). |
| 594 | .as_expressionrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`PatternElement<&'a str>`]as_expression().() |
| 595 | .as_inline_variable_idrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Expression<&'a str>`]as_inline_variable_id().() |
| 596 | .namerust-analyzer cargo fluent-syntax 0.12.0 ast/Identifier#name. = "qux"; |
| 597 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("foo = { $qux }\n", serializerust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize().(&ast)); |
| 598 | } |
| 599 | |
| 600 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 601 | fn remove_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/remove_message().() { |
| 602 | let mut ast = parserust-analyzer cargo fluent-syntax 0.12.0 parser/parse().("foo = bar\nbaz = qux\n").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to parse ftl resource"); |
| 603 | ast.bodyrust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#body..poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().(); |
| 604 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("foo = bar\n", serializerust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize().(&ast)); |
| 605 | } |
| 606 | |
| 607 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 608 | fn add_message_at_toprust-analyzer cargo fluent-syntax 0.12.0 serializer/test/add_message_at_top().() { |
| 609 | let mut ast = parserust-analyzer cargo fluent-syntax 0.12.0 parser/parse().("foo = bar\n").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to parse ftl resource"); |
| 610 | ast.bodyrust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#body..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().(0, text_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/text_message!!("baz", "qux")); |
| 611 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("baz = qux\nfoo = bar\n", serializerust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize().(&ast)); |
| 612 | } |
| 613 | |
| 614 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 615 | fn add_message_at_endrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/add_message_at_end().() { |
| 616 | let mut ast = parserust-analyzer cargo fluent-syntax 0.12.0 parser/parse().("foo = bar\n").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to parse ftl resource"); |
| 617 | ast.bodyrust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#body..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(text_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/text_message!!("baz", "qux")); |
| 618 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("foo = bar\nbaz = qux\n", serializerust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize().(&ast)); |
| 619 | } |
| 620 | |
| 621 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 622 | fn add_message_in_betweenrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/add_message_in_between().() { |
| 623 | let mut ast = parserust-analyzer cargo fluent-syntax 0.12.0 parser/parse().("foo = bar\nbaz = qux\n").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to parse ftl resource"); |
| 624 | ast.bodyrust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#body..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().(1, text_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/text_message!!("hello", "there")); |
| 625 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("foo = bar\nhello = there\nbaz = qux\n", serializerust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize().(&ast)); |
| 626 | } |
| 627 | |
| 628 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 629 | fn add_message_commentrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/add_message_comment().() { |
| 630 | let mut ast = parserust-analyzer cargo fluent-syntax 0.12.0 parser/parse().("foo = bar\n").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to parse ftl resource"); |
| 631 | ast.bodyrust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#body.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..as_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Entry<&'a str>`]as_message().().commentrust-analyzer cargo fluent-syntax 0.12.0 ast/Message#comment..replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]replace().(Commentrust-analyzer cargo fluent-syntax 0.12.0 ast/Comment# { |
| 632 | contentrust-analyzer cargo fluent-syntax 0.12.0 ast/Comment#content.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["great message!"], |
| 633 | }); |
| 634 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("# great message!\nfoo = bar\n", serializerust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize().(&ast)); |
| 635 | } |
| 636 | |
| 637 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 638 | fn remove_message_commentrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/remove_message_comment().() { |
| 639 | let mut ast = parserust-analyzer cargo fluent-syntax 0.12.0 parser/parse().("# great message!\nfoo = bar\n").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to parse ftl resource"); |
| 640 | ast.bodyrust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#body.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..as_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Entry<&'a str>`]as_message().().commentrust-analyzer cargo fluent-syntax 0.12.0 ast/Message#comment..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().(); |
| 641 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("foo = bar\n", serializerust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize().(&ast)); |
| 642 | } |
| 643 | |
| 644 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 645 | fn edit_message_commentrust-analyzer cargo fluent-syntax 0.12.0 serializer/test/edit_message_comment().() { |
| 646 | let mut ast = parserust-analyzer cargo fluent-syntax 0.12.0 parser/parse().("# great message!\nfoo = bar\n").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("failed to parse ftl resource"); |
| 647 | ast.bodyrust-analyzer cargo fluent-syntax 0.12.0 ast/Resource#body.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). |
| 648 | .as_messagerust-analyzer cargo fluent-syntax 0.12.0 serializer/test/impl#[`Entry<&'a str>`]as_message().() |
| 649 | .commentrust-analyzer cargo fluent-syntax 0.12.0 ast/Message#comment. |
| 650 | .as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().() |
| 651 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("comment is missing") |
| 652 | .contentrust-analyzer cargo fluent-syntax 0.12.0 ast/Comment#content.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = "very original"; |
| 653 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("# very original\nfoo = bar\n", serializerust-analyzer cargo fluent-syntax 0.12.0 serializer/serialize().(&ast)); |
| 654 | } |
| 655 | } |