parser: Mockup type-expression syntax
- Allow `name: Type` notation for parameters - Allow `fn x() -> RetVal` notation for return values - TODO: Create syntax for type-expressions/paths
This commit is contained in:
parent
374017d5e3
commit
c1c834701a
2
dummy.cl
2
dummy.cl
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// This is a function. It can be called with the call operator.
|
// This is a function. It can be called with the call operator.
|
||||||
// The function called `main` is the program's entrypoint
|
// The function called `main` is the program's entrypoint
|
||||||
fn main() {
|
fn main() -> (&str, bool, i128) {
|
||||||
// An if expression is like the ternary conditional operator in C
|
// An if expression is like the ternary conditional operator in C
|
||||||
let y = if 10 < 50 {
|
let y = if 10 < 50 {
|
||||||
"\u{1f988}"
|
"\u{1f988}"
|
||||||
|
@ -393,7 +393,7 @@ impl Parser {
|
|||||||
self.consume_type(Type::LParen)?;
|
self.consume_type(Type::LParen)?;
|
||||||
let args = self.params()?;
|
let args = self.params()?;
|
||||||
self.consume_type(Type::RParen)?;
|
self.consume_type(Type::RParen)?;
|
||||||
// Discard return type, for now
|
// TODO: Parse type-expressions and store return types in the AST
|
||||||
if self.consume_type(Type::Arrow).is_ok() {
|
if self.consume_type(Type::Arrow).is_ok() {
|
||||||
self.expr()?;
|
self.expr()?;
|
||||||
}
|
}
|
||||||
@ -404,6 +404,10 @@ impl Parser {
|
|||||||
let mut args = vec![];
|
let mut args = vec![];
|
||||||
while let Ok(ident) = self.identifier() {
|
while let Ok(ident) = self.identifier() {
|
||||||
args.push(ident);
|
args.push(ident);
|
||||||
|
if self.consume_type(Type::Colon).is_ok() {
|
||||||
|
// TODO: Parse type-expressions and make this mandatory
|
||||||
|
self.expr()?;
|
||||||
|
}
|
||||||
if self.consume_type(Type::Comma).is_err() {
|
if self.consume_type(Type::Comma).is_err() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user