| 1 | // (c) 2016-2017 Productize SPRL <[email protected]> |
| 2 | |
| 3 | use error::SexpError; |
| 4 | use Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#; |
| 5 | use parse_errorrust-analyzer cargo symbolic_expressions 5.0.3 error/parse_error().; |
| 6 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/; |
| 7 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#; |
| 8 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::preluderust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/prelude/::*; |
| 9 | |
| 10 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 11 | struct Parserrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser# { |
| 12 | datarust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#data.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<char>, |
| 13 | positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#position.: usize, |
| 14 | linerust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#line.: usize, |
| 15 | line_positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#line_position.: usize, |
| 16 | } |
| 17 | |
| 18 | impl Parserrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser# { |
| 19 | fn peekrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]peek().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<char, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> { |
| 20 | self.fail_on_eofrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]fail_on_eof().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 21 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.datarust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#data.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#position.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().) |
| 22 | } |
| 23 | |
| 24 | fn getrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]get().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<char, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> { |
| 25 | self.fail_on_eofrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]fail_on_eof().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 26 | let c = self.datarust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#data.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#position.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 27 | self.positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#position. 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; |
| 28 | self.line_positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#line_position. 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; |
| 29 | if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\n' { |
| 30 | self.linerust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#line. 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; |
| 31 | self.line_positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#line_position. = 0; |
| 32 | } |
| 33 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(c) |
| 34 | } |
| 35 | |
| 36 | fn incrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]inc().(&mut self) { |
| 37 | let c = self.datarust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#data.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#position.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 38 | self.positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#position. 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; |
| 39 | self.line_positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#line_position. 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; |
| 40 | if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\n' { |
| 41 | self.linerust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#line. 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; |
| 42 | self.line_positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#line_position. = 0; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | fn eat_spacerust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eat_space().(&mut self) { |
| 47 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.eofrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eof().() { |
| 48 | let c = self.datarust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#data.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().self.positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#position.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 49 | if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().' ' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\t' { |
| 50 | self.incrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]inc().(); |
| 51 | continue; |
| 52 | } |
| 53 | break; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | fn eat_charrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eat_char().(&mut self, c: char) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> { |
| 58 | let c2 = self.getrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]get().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 59 | if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().c2 { |
| 60 | self.parse_errorrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]parse_error().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("expected {} got {}", c, c2)) |
| 61 | } else { |
| 62 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | fn eofrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eof().(&self) -> bool { |
| 67 | self.positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#position. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().self.datarust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() |
| 68 | } |
| 69 | |
| 70 | fn fail_on_eofrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]fail_on_eof().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> { |
| 71 | if self.eofrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eof().() { |
| 72 | return self.parse_errorrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]parse_error().("End of file reached"); |
| 73 | } |
| 74 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 75 | } |
| 76 | |
| 77 | fn parse_errorrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]parse_error().<T>(&self, msg: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> { |
| 78 | parse_errorrust-analyzer cargo symbolic_expressions 5.0.3 error/parse_error().(self.linerust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#line. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1, self.line_positionrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#line_position. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1, msg.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /// parse a &str to a symbolic-expression |
| 83 | pub fn parse_strrust-analyzer cargo symbolic_expressions 5.0.3 parser/parse_str().(sexp: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> { |
| 84 | if sexp.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() { |
| 85 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#::defaultrust-analyzer cargo symbolic_expressions 5.0.3 sexp/impl#[Sexp][Default]default().()); |
| 86 | } |
| 87 | let mut parser = Parserrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#::defaultrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser][Default]default().(); |
| 88 | parser.datarust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#data. = sexp.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 89 | parserust-analyzer cargo symbolic_expressions 5.0.3 parser/parse().(&mut parser) |
| 90 | } |
| 91 | |
| 92 | fn parserust-analyzer cargo symbolic_expressions 5.0.3 parser/parse().(parser: &mut Parserrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> { |
| 93 | parser.eat_spacerust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eat_space().(); |
| 94 | let c = parser.peekrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]peek().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 95 | if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'(' { |
| 96 | parse_listrust-analyzer cargo symbolic_expressions 5.0.3 parser/parse_list().(parser) |
| 97 | } else if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'"' { |
| 98 | parse_quoted_stringrust-analyzer cargo symbolic_expressions 5.0.3 parser/parse_quoted_string().(parser) |
| 99 | } else if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().')' { |
| 100 | parser.parse_errorrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]parse_error().("Unexpected )") |
| 101 | } else { |
| 102 | parse_bare_stringrust-analyzer cargo symbolic_expressions 5.0.3 parser/parse_bare_string().(parser) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | fn parse_listrust-analyzer cargo symbolic_expressions 5.0.3 parser/parse_list().(parser: &mut Parserrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> { |
| 107 | parser.eat_charrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eat_char().('(')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 108 | let mut v = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 109 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().parser.eofrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eof().() { |
| 110 | let c = parser.peekrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]peek().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 111 | if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().')' { |
| 112 | break; |
| 113 | } else if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().' ' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\t' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\r' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\n' { |
| 114 | parser.incrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]inc().() |
| 115 | } else { |
| 116 | let s = parserust-analyzer cargo symbolic_expressions 5.0.3 parser/parse().(parser)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 117 | v.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(s) |
| 118 | } |
| 119 | } |
| 120 | parser.eat_charrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eat_char().(')')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 121 | parser.eat_spacerust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eat_space().(); |
| 122 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#::Listrust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#List#(v)) |
| 123 | } |
| 124 | |
| 125 | fn parse_quoted_stringrust-analyzer cargo symbolic_expressions 5.0.3 parser/parse_quoted_string().(parser: &mut Parserrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> { |
| 126 | let mut s = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 127 | parser.eat_charrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eat_char().('"')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 128 | // note that escaped quotes are actually not allowed |
| 129 | let mut escape = false; |
| 130 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().parser.eofrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eof().() { |
| 131 | let c = parser.peekrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]peek().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 132 | if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\\' { |
| 133 | escape = true; |
| 134 | } else if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'"' { |
| 135 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().escape { |
| 136 | break; |
| 137 | } else { |
| 138 | escape = false; |
| 139 | } |
| 140 | } else { |
| 141 | escape = false; |
| 142 | } |
| 143 | s.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(c); |
| 144 | parser.incrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]inc().() |
| 145 | } |
| 146 | parser.eat_charrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eat_char().('"')?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 147 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#::Stringrust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#String#(s)) |
| 148 | } |
| 149 | |
| 150 | fn parse_bare_stringrust-analyzer cargo symbolic_expressions 5.0.3 parser/parse_bare_string().(parser: &mut Parserrust-analyzer cargo symbolic_expressions 5.0.3 parser/Parser#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> { |
| 151 | let mut s = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 152 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().parser.eofrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]eof().() { |
| 153 | let c = parser.peekrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]peek().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 154 | if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().' ' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'(' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().')' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\r' || c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\n' { |
| 155 | break; |
| 156 | } |
| 157 | s.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(c); |
| 158 | parser.incrust-analyzer cargo symbolic_expressions 5.0.3 parser/impl#[Parser]inc().() |
| 159 | } |
| 160 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#::Stringrust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#String#(s)) |
| 161 | } |
| 162 | |
| 163 | fn read_filerust-analyzer cargo symbolic_expressions 5.0.3 parser/read_file().(name: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 164 | let mut f = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(name)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 165 | let mut s = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 166 | f.read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File][Read]read_to_string().(&mut s)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 167 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(s) |
| 168 | } |
| 169 | |
| 170 | /// parse a file as a symbolic-expression |
| 171 | pub fn parse_filerust-analyzer cargo symbolic_expressions 5.0.3 parser/parse_file().(name: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Sexprust-analyzer cargo symbolic_expressions 5.0.3 sexp/Sexp#, SexpErrorrust-analyzer cargo symbolic_expressions 5.0.3 error/SexpError#> { |
| 172 | let s = read_filerust-analyzer cargo symbolic_expressions 5.0.3 parser/read_file().(name)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 173 | parse_strrust-analyzer cargo symbolic_expressions 5.0.3 parser/parse_str().(&s[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().) |
| 174 | } |