fixed issue with struct literal names
This commit is contained in:
@@ -69,7 +69,6 @@ class LiteralFloat:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LiteralStruct:
|
class LiteralStruct:
|
||||||
name: str
|
|
||||||
fields: Dict[str, "Expression"]
|
fields: Dict[str, "Expression"]
|
||||||
type: TypeUsage
|
type: TypeUsage
|
||||||
|
|
||||||
@@ -205,7 +204,7 @@ boring_grammar = r"""
|
|||||||
literal_int : SIGNED_INT
|
literal_int : SIGNED_INT
|
||||||
|
|
||||||
literal_struct_field : identifier ":" expression
|
literal_struct_field : identifier ":" expression
|
||||||
literal_struct : identifier "{" (literal_struct_field ",")* "}"
|
literal_struct : data_type "{" (literal_struct_field ",")* "}"
|
||||||
|
|
||||||
function_call : expression "(" [expression ("," expression)*] ")"
|
function_call : expression "(" [expression ("," expression)*] ")"
|
||||||
|
|
||||||
@@ -324,9 +323,9 @@ class TreeToBoring(Transformer):
|
|||||||
return name, expression
|
return name, expression
|
||||||
|
|
||||||
def literal_struct(self, literal_struct) -> LiteralStruct:
|
def literal_struct(self, literal_struct) -> LiteralStruct:
|
||||||
name = literal_struct[0]
|
data_type = literal_struct[0]
|
||||||
fields = {key: value for (key, value) in literal_struct[1:]}
|
fields = {key: value for (key, value) in literal_struct[1:]}
|
||||||
return LiteralStruct(name=name, fields=fields, type=DataTypeUsage(name=name))
|
return LiteralStruct(fields=fields, type=data_type)
|
||||||
|
|
||||||
def identifier(self, i) -> str:
|
def identifier(self, i) -> str:
|
||||||
(i,) = i
|
(i,) = i
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ def assert_exists(ctx: Context, type: parse.TypeUsage):
|
|||||||
class TypeChecker:
|
class TypeChecker:
|
||||||
def with_module(self, ctx: Context, module: parse.Module) -> bool:
|
def with_module(self, ctx: Context, module: parse.Module) -> bool:
|
||||||
for type_declaration in module.types:
|
for type_declaration in module.types:
|
||||||
|
if isinstance(type_declaration, parse.StructTypeDeclaration):
|
||||||
ctx.environment[type_declaration.name] = type_declaration
|
ctx.environment[type_declaration.name] = type_declaration
|
||||||
for type_declaration in module.types:
|
for type_declaration in module.types:
|
||||||
if isinstance(type_declaration, parse.StructTypeDeclaration):
|
if isinstance(type_declaration, parse.StructTypeDeclaration):
|
||||||
@@ -361,8 +362,9 @@ class TypeChecker:
|
|||||||
def with_literal_struct(
|
def with_literal_struct(
|
||||||
self, ctx: Context, literal_struct: parse.LiteralStruct
|
self, ctx: Context, literal_struct: parse.LiteralStruct
|
||||||
) -> bool:
|
) -> bool:
|
||||||
assert literal_struct.name in ctx.environment, literal_struct.name
|
assert isinstance(literal_struct.type, parse.DataTypeUsage)
|
||||||
struct_declaration = ctx.environment[literal_struct.name]
|
assert literal_struct.type.name in ctx.environment, literal_struct.type.name
|
||||||
|
struct_declaration = ctx.environment[literal_struct.type.name]
|
||||||
assert isinstance(struct_declaration, parse.StructTypeDeclaration)
|
assert isinstance(struct_declaration, parse.StructTypeDeclaration)
|
||||||
changed = False
|
changed = False
|
||||||
for name, field_type in struct_declaration.fields.items():
|
for name, field_type in struct_declaration.fields.items():
|
||||||
|
|||||||
Reference in New Issue
Block a user