some changes

This commit is contained in:
tezlm 2023-10-03 16:41:47 -07:00
parent 4854fb87f5
commit 6e6d7f765b
Signed by: tezlm
GPG key ID: 649733FCD94AFBBA
3 changed files with 35 additions and 15 deletions

View file

@ -207,6 +207,18 @@ impl Lexer {
};
}
macro_rules! next_is {
($ch:expr) => {
match self.input.get(self.pos + 1) {
Some($ch) => {
self.pos += 1;
true
}
_ => false,
}
};
}
let token = match ch {
'(' => Some(Token::OpenParan),
')' => Some(Token::CloseParan),
@ -314,24 +326,15 @@ impl Lexer {
_ => Symbol::Greater,
},
'.' => match self.input.get(self.pos + 1) {
Some('.') => match self.input.get(self.pos + 1) {
Some('.') => {
self.pos += 2;
Symbol::TripleDot
}
_ => {
self.pos += 1;
Symbol::DoubleDot
}
Some('.') => match next_is!('.') {
true => Symbol::TripleDot,
false => Symbol::DoubleDot,
},
_ => Symbol::Dot,
},
':' => match self.input.get(self.pos + 1) {
Some(':') => {
self.pos += 1;
Symbol::DoubleColon
}
_ => Symbol::Colon,
':' => match next_is!(':') {
true => Symbol::DoubleColon,
false => Symbol::Colon,
},
',' => Symbol::Comma,
';' => Symbol::Semicolon,

View file

@ -119,6 +119,20 @@ impl Parser {
"bool" => Type::Boolean,
_ => return Err(Error::TypeError(format!("unknown type {ident}"))),
},
Token::OpenParan => {
let mut tys = vec![];
while !self.peek_tok().is_some_and(|tok| tok == &Token::CloseParan) {
tys.push(self.parse_type()?);
if self.peek_tok() == Some(&Token::Symbol(Symbol::Comma)) {
self.eat(Token::Symbol(Symbol::Comma))?;
} else {
break;
}
}
self.eat(Token::CloseParan)?;
Type::Tuple(tys)
},
_ => todo!(),
};
Ok(ty)

3
test/t7 Normal file
View file

@ -0,0 +1,3 @@
fn main() -> (i32, i32) {
(123, 456)
}