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