| 1 | use superrust-analyzer cargo fluent-syntax 0.12.0 parser/::{corerust-analyzer cargo fluent-syntax 0.12.0 parser/core/::Parserrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#, corerust-analyzer cargo fluent-syntax 0.12.0 parser/core/::Resultrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Result#, Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#}; |
| 2 | use craterust-analyzer cargo fluent-syntax 0.12.0 crate/::astrust-analyzer cargo fluent-syntax 0.12.0 ast/; |
| 3 | |
| 4 | #[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:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 5 | pub(superrust-analyzer cargo fluent-syntax 0.12.0 parser/) enum Levelrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level# { |
| 6 | Nonerust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#None# = 0, |
| 7 | Regularrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#Regular# = 1, |
| 8 | Grouprust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#Group# = 2, |
| 9 | Resourcerust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#Resource# = 3, |
| 10 | } |
| 11 | |
| 12 | impl<'s, S> Parserrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#<S> |
| 13 | where |
| 14 | S: Slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#<'s>, |
| 15 | { |
| 16 | pub(superrust-analyzer cargo fluent-syntax 0.12.0 parser/) fn get_commentrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/impl#[`Parser<S>`]get_comment().(&mut self) -> Resultrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Result#<(astrust-analyzer cargo fluent-syntax 0.12.0 ast/::Commentrust-analyzer cargo fluent-syntax 0.12.0 ast/Comment#<S>, Levelrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#)> { |
| 17 | let mut level = Levelrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#::Nonerust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#None#; |
| 18 | let mut content = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 19 | |
| 20 | while self.ptrrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#ptr. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.lengthrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#length. { |
| 21 | let line_level = self.get_comment_levelrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/impl#[`Parser<S>`]get_comment_level().(); |
| 22 | if line_level rust-analyzer cargo fluent-syntax 0.12.0 parser/comment/impl#[Level][`PartialEq<Self>`]eq().==rust-analyzer cargo fluent-syntax 0.12.0 parser/comment/impl#[Level][`PartialEq<Self>`]eq(). rust-analyzer cargo fluent-syntax 0.12.0 parser/comment/impl#[Level][`PartialEq<Self>`]eq().Levelrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#::Nonerust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#None# { |
| 23 | self.ptrrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#ptr. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 24 | break; |
| 25 | } else if level rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Levelrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#::Nonerust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#None# && line_level rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().level { |
| 26 | self.ptrrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#ptr. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().line_level as usize; |
| 27 | break; |
| 28 | } |
| 29 | |
| 30 | level = line_level; |
| 31 | |
| 32 | if self.ptrrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#ptr. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().self.lengthrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#length. { |
| 33 | break; |
| 34 | } else if self.is_eolrust-analyzer cargo fluent-syntax 0.12.0 parser/helper/impl#[`Parser<S>`]is_eol().() { |
| 35 | content.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(self.get_comment_linerust-analyzer cargo fluent-syntax 0.12.0 parser/comment/impl#[`Parser<S>`]get_comment_line().()); |
| 36 | } else { |
| 37 | if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) = self.expect_byterust-analyzer cargo fluent-syntax 0.12.0 parser/helper/impl#[`Parser<S>`]expect_byte().(b' ') { |
| 38 | if content.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 39 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e); |
| 40 | } else { |
| 41 | self.ptrrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#ptr. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().line_level as usize; |
| 42 | break; |
| 43 | } |
| 44 | } |
| 45 | content.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(self.get_comment_linerust-analyzer cargo fluent-syntax 0.12.0 parser/comment/impl#[`Parser<S>`]get_comment_line().()); |
| 46 | } |
| 47 | self.skip_eolrust-analyzer cargo fluent-syntax 0.12.0 parser/helper/impl#[`Parser<S>`]skip_eol().(); |
| 48 | } |
| 49 | |
| 50 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((astrust-analyzer cargo fluent-syntax 0.12.0 ast/::Commentrust-analyzer cargo fluent-syntax 0.12.0 ast/Comment# { contentrust-analyzer cargo fluent-syntax 0.12.0 ast/Comment#content. }, level)) |
| 51 | } |
| 52 | |
| 53 | pub(superrust-analyzer cargo fluent-syntax 0.12.0 parser/) fn skip_commentrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/impl#[`Parser<S>`]skip_comment().(&mut self) { |
| 54 | loop { |
| 55 | while self.ptrrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#ptr. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.lengthrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#length. && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_eolrust-analyzer cargo fluent-syntax 0.12.0 parser/helper/impl#[`Parser<S>`]is_eol().() { |
| 56 | self.ptrrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#ptr. 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; |
| 57 | } |
| 58 | self.ptrrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#ptr. 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; |
| 59 | if self.is_current_byterust-analyzer cargo fluent-syntax 0.12.0 parser/helper/impl#[`Parser<S>`]is_current_byte().(b'#') { |
| 60 | self.ptrrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#ptr. 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; |
| 61 | } else { |
| 62 | break; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | fn get_comment_levelrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/impl#[`Parser<S>`]get_comment_level().(&mut self) -> Levelrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level# { |
| 68 | if self.take_byte_ifrust-analyzer cargo fluent-syntax 0.12.0 parser/helper/impl#[`Parser<S>`]take_byte_if().(b'#') { |
| 69 | if self.take_byte_ifrust-analyzer cargo fluent-syntax 0.12.0 parser/helper/impl#[`Parser<S>`]take_byte_if().(b'#') { |
| 70 | if self.take_byte_ifrust-analyzer cargo fluent-syntax 0.12.0 parser/helper/impl#[`Parser<S>`]take_byte_if().(b'#') { |
| 71 | return Levelrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#::Resourcerust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#Resource#; |
| 72 | } |
| 73 | return Levelrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#::Grouprust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#Group#; |
| 74 | } |
| 75 | return Levelrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#::Regularrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#Regular#; |
| 76 | } |
| 77 | Levelrust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#::Nonerust-analyzer cargo fluent-syntax 0.12.0 parser/comment/Level#None# |
| 78 | } |
| 79 | |
| 80 | fn get_comment_linerust-analyzer cargo fluent-syntax 0.12.0 parser/comment/impl#[`Parser<S>`]get_comment_line().(&mut self) -> S { |
| 81 | let start_pos = self.ptrrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#ptr.; |
| 82 | |
| 83 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.is_eolrust-analyzer cargo fluent-syntax 0.12.0 parser/helper/impl#[`Parser<S>`]is_eol().() { |
| 84 | self.ptrrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#ptr. 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; |
| 85 | } |
| 86 | |
| 87 | self.sourcerust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#source..slicerust-analyzer cargo fluent-syntax 0.12.0 parser/slice/Slice#slice().(start_pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#self.ptrrust-analyzer cargo fluent-syntax 0.12.0 parser/core/Parser#ptr.) |
| 88 | } |
| 89 | } |