added block expression
This commit is contained in:
@@ -91,7 +91,7 @@ class VariableUsage:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Expression:
|
class Expression:
|
||||||
expression: Union[LiteralInt, LiteralFloat, FunctionCall, VariableUsage, Operation]
|
expression: Union[LiteralInt, LiteralFloat, FunctionCall, "Block", VariableUsage, Operation]
|
||||||
type: TypeUsage
|
type: TypeUsage
|
||||||
|
|
||||||
|
|
||||||
@@ -163,6 +163,7 @@ boring_grammar = r"""
|
|||||||
| variable_usage
|
| variable_usage
|
||||||
| function_call
|
| function_call
|
||||||
| "(" expression ")"
|
| "(" expression ")"
|
||||||
|
| block
|
||||||
|
|
||||||
let_statement : "let" identifier "=" expression ";"
|
let_statement : "let" identifier "=" expression ";"
|
||||||
| "let" identifier ":" type_usage "=" expression ";"
|
| "let" identifier ":" type_usage "=" expression ";"
|
||||||
|
|||||||
@@ -139,6 +139,10 @@ class TypeChecker:
|
|||||||
if self.with_function_call(env, type_env, subexpression):
|
if self.with_function_call(env, type_env, subexpression):
|
||||||
changed = True
|
changed = True
|
||||||
return changed
|
return changed
|
||||||
|
if isinstance(subexpression, parse.Block):
|
||||||
|
if self.with_block(env, type_env, subexpression):
|
||||||
|
changed = True
|
||||||
|
return changed
|
||||||
if isinstance(subexpression, parse.VariableUsage):
|
if isinstance(subexpression, parse.VariableUsage):
|
||||||
if self.with_variable_usage(env, type_env, subexpression):
|
if self.with_variable_usage(env, type_env, subexpression):
|
||||||
changed = True
|
changed = True
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
fn add(a: I32, b: I32): I32 {
|
fn add(a: I32, b: I32): I32 {
|
||||||
let foo = 4;
|
let foo = 4;
|
||||||
let test_float: F32 = 10.2;
|
let test_float: F32 = {
|
||||||
|
10.2
|
||||||
|
};
|
||||||
a + b + foo
|
a + b + foo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user