Add parsing for defers
This commit is contained in:
parent
659c79373d
commit
2cee127d8f
@ -543,3 +543,7 @@ class Import(Statement):
|
||||
class TypeDefinition(Statement):
|
||||
name: str
|
||||
expression: TypeExpression
|
||||
|
||||
@dataclass
|
||||
class DeferStatement(Statement):
|
||||
statement: Statement
|
||||
|
@ -656,6 +656,8 @@ def interpret_statements(statements: List_[Statement], program: ProgramState) ->
|
||||
program.modules[file.str] = module
|
||||
case TypeDefinition(name, expression_):
|
||||
program.declare_and_assign_variable(name, TypeObject(calculate_type_expression(expression_, program)))
|
||||
case DeferStatement(statement=statement):
|
||||
assert False, "TODO: Defers are not implemented"
|
||||
case _:
|
||||
assert False, ("Unimplemented", statement)
|
||||
return NothingResult()
|
||||
|
@ -358,6 +358,9 @@ def parse_statement(lexer: Lexer) -> Statement:
|
||||
type_expression = parse_type(lexer)
|
||||
lexer.assert_token(SymbolToken(Symbol.Semicolon))
|
||||
return TypeDefinition(name, type_expression)
|
||||
elif lexer.take_token(KeywordToken(Keyword.Defer)):
|
||||
statement = parse_statement(lexer)
|
||||
return DeferStatement(statement)
|
||||
elif lexer.check_tokenkind(KeywordToken) and not lexer.check_tokens(KeywordToken(Keyword.Return), KeywordToken(Keyword.Lambda)):
|
||||
assert False, ("Unimplemented", lexer.next_token(), lexer.next_token(), lexer.next_token())
|
||||
elif lexer.take_token(SymbolToken(Symbol.OpenCurly)):
|
||||
|
@ -23,6 +23,7 @@ class Keyword(Enum):
|
||||
Lambda = 'lambda'
|
||||
Import = 'import'
|
||||
Type = 'type'
|
||||
Defer = 'defer'
|
||||
|
||||
class Symbol(Enum):
|
||||
Open = '('
|
||||
|
Loading…
Reference in New Issue
Block a user