Browse Source

fix errors in parser

master
Alison Watson 2 years ago
parent
commit
7e3d8a1a2c
  1. 10
      source/framework/vire/parser.rs
  2. 7
      source/framework/vire/parser/tok.rs

10
source/framework/vire/parser.rs

@ -57,11 +57,11 @@ impl Datum {
fn list(tki: &mut TokenIter, end: tok::Type) -> Result<Self, Err> {
let mut data_v = Vec::new();
let mut car = Self::Null;
let mut cdr = Self::Null;
while !tki.drop(end)? {
if tki.drop(Peri)? {
car = Self::parse(tki)?;
cdr = Self::parse(tki)?;
tki.expect(end)?;
break;
} else {
@ -69,11 +69,11 @@ impl Datum {
}
}
for cdr in data_v.into_iter() {
car = Self::Cons { cdr: Box::new(cdr), car: Box::new(car) };
for car in data_v.into_iter().rev() {
cdr = Self::Cons { car: Box::new(car), cdr: Box::new(cdr) };
}
Ok(car)
Ok(cdr)
}
}

7
source/framework/vire/parser/tok.rs

@ -189,8 +189,10 @@ fn integer_rad(rd: &mut PosReader, rad: u32) -> Result<Token, Err> {
let mut n = 0_i64;
loop {
match rd.next() {
match rd.peek() {
c if is_delim(c) => break,
Some(c) if c.is_digit(rad) => {
rd.next();
let cn = unsafe { text::radix(c) }.into();
n =
n.checked_mul(rad.into()).ok_or_else(|| Err::Numb(rd.pos()))?;
@ -200,7 +202,6 @@ fn integer_rad(rd: &mut PosReader, rad: u32) -> Result<Token, Err> {
n.checked_add(cn).ok_or_else(|| Err::Numb(rd.pos()))?
};
}
c if is_delim(c) => break,
Some(c) => return Err(Err::Delim(rd.pos(), c)),
None => unsafe { std::hint::unreachable_unchecked() },
}
@ -232,11 +233,11 @@ fn symbol(rd: &mut PosReader, c: char) -> Result<Token, Err> {
loop {
match rd.peek() {
c if is_delim(c) => break,
Some(c) if is_sym_subs(c) => {
rd.next();
s.push(c);
}
c if is_delim(c) => break,
Some(c) => return Err(Err::Delim(rd.pos(), c)),
None => unsafe { std::hint::unreachable_unchecked() },
}

Loading…
Cancel
Save