got type system working
This commit is contained in:
@@ -37,7 +37,7 @@ pub LiteralInt: String = {
|
||||
};
|
||||
|
||||
pub SpannedLiteralInt: ast::LiteralInt = {
|
||||
<literal_int:Spanned<LiteralInt>> => ast::LiteralInt{value: literal_int, type_: ast::TypeUsage::new_builtin("i64".to_string())}
|
||||
<literal_int:Spanned<LiteralInt>> => ast::LiteralInt{value: literal_int, type_: ast::TypeUsage::new_builtin("I64".to_string())}
|
||||
};
|
||||
|
||||
pub LiteralFloat: String = {
|
||||
@@ -45,7 +45,7 @@ pub LiteralFloat: String = {
|
||||
};
|
||||
|
||||
pub SpannedLiteralFloat: ast::LiteralFloat = {
|
||||
<literal_float:Spanned<LiteralFloat>> => ast::LiteralFloat{value: literal_float, type_: ast::TypeUsage::new_builtin("f64".to_string())}
|
||||
<literal_float:Spanned<LiteralFloat>> => ast::LiteralFloat{value: literal_float, type_: ast::TypeUsage::new_builtin("F64".to_string())}
|
||||
};
|
||||
|
||||
pub Identifier: String = {
|
||||
@@ -149,7 +149,7 @@ pub Statement: ast::Statement = {
|
||||
|
||||
pub Block: ast::Block = {
|
||||
"{" <v:(<Statement>)*> <e:Expression?> "}" => match e {
|
||||
None => ast::Block{statements: v, type_: ast::new_never()},
|
||||
None => ast::Block{statements: v, type_: ast::TypeUsage::new_unknown(&id_generator)},
|
||||
Some(e) => {
|
||||
let mut v = v;
|
||||
v.push(ast::Statement::Expression(e));
|
||||
@@ -160,7 +160,7 @@ pub Block: ast::Block = {
|
||||
|
||||
pub TypeUsage: ast::TypeUsage = {
|
||||
<n:SpannedIdentifier> => ast::TypeUsage::Named(ast::NamedTypeUsage{name: n}),
|
||||
"fn" "(" <args:Comma<TypeUsage>> ")" => ast::TypeUsage::Function(ast::FunctionTypeUsage{arguments: args, return_type: Box::new(ast::TypeUsage::new_unknown(&id_generator))}),
|
||||
"fn" "(" <args:Comma<TypeUsage>> ")" => ast::TypeUsage::Function(ast::FunctionTypeUsage{arguments: args, return_type: Box::new(ast::new_unit())}),
|
||||
"fn" "(" <args:Comma<TypeUsage>> ")" ":" <rt:TypeUsage> => ast::TypeUsage::Function(ast::FunctionTypeUsage{arguments: args, return_type: Box::new(rt)}),
|
||||
};
|
||||
|
||||
@@ -169,7 +169,7 @@ pub VariableDeclaration: ast::VariableDeclaration = {
|
||||
};
|
||||
|
||||
pub FunctionDeclaration: ast::FunctionDeclaration = {
|
||||
"fn" <n:SpannedIdentifier> "(" <args:Comma<VariableDeclaration>> ")" => ast::FunctionDeclaration{name: n, arguments: args, return_type: ast::TypeUsage::new_unknown(&id_generator)},
|
||||
"fn" <n:SpannedIdentifier> "(" <args:Comma<VariableDeclaration>> ")" => ast::FunctionDeclaration{name: n, arguments: args, return_type: ast::new_unit()},
|
||||
"fn" <n:SpannedIdentifier> "(" <args:Comma<VariableDeclaration>> ")" ":" <rt:TypeUsage> => ast::FunctionDeclaration{name: n, arguments: args, return_type: rt},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user