mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Change the way values work
Change the parsing for values to make them more reusable, in particular for when I implement extensions.
This commit is contained in:
parent
6938267952
commit
1df46b5a06
30 changed files with 707 additions and 291 deletions
|
@ -20,6 +20,7 @@
|
|||
|
||||
from .common import *
|
||||
from .types import TypeName
|
||||
from .gtkbuilder_template import Template
|
||||
|
||||
|
||||
expr = Pratt()
|
||||
|
@ -30,6 +31,10 @@ class Expr(AstNode):
|
|||
def type(self) -> T.Optional[GirType]:
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def type_complete(self) -> bool:
|
||||
return True
|
||||
|
||||
@property
|
||||
def rhs(self) -> T.Optional["Expr"]:
|
||||
if isinstance(self.parent, ExprChain):
|
||||
|
@ -53,6 +58,10 @@ class ExprChain(Expr):
|
|||
def type(self) -> T.Optional[GirType]:
|
||||
return self.last.type
|
||||
|
||||
@property
|
||||
def type_complete(self) -> bool:
|
||||
return self.last.type_complete
|
||||
|
||||
|
||||
class InfixExpr(Expr):
|
||||
@property
|
||||
|
@ -83,6 +92,13 @@ class IdentExpr(Expr):
|
|||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def type_complete(self) -> bool:
|
||||
if object := self.root.objects_by_id.get(self.ident):
|
||||
return not isinstance(object, Template)
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
class LookupOp(InfixExpr):
|
||||
grammar = [".", UseIdent("property")]
|
||||
|
@ -103,17 +119,24 @@ class LookupOp(InfixExpr):
|
|||
|
||||
@validate("property")
|
||||
def property_exists(self):
|
||||
if self.lhs.type is None or isinstance(self.lhs.type, UncheckedType):
|
||||
if (
|
||||
self.lhs.type is None
|
||||
or not self.lhs.type_complete
|
||||
or isinstance(self.lhs.type, UncheckedType)
|
||||
):
|
||||
return
|
||||
|
||||
elif not isinstance(self.lhs.type, gir.Class) and not isinstance(
|
||||
self.lhs.type, gir.Interface
|
||||
):
|
||||
raise CompileError(
|
||||
f"Type {self.lhs.type.full_name} does not have properties"
|
||||
)
|
||||
|
||||
elif self.lhs.type.properties.get(self.property_name) is None:
|
||||
raise CompileError(
|
||||
f"{self.lhs.type.full_name} does not have a property called {self.property_name}"
|
||||
f"{self.lhs.type.full_name} does not have a property called {self.property_name}",
|
||||
did_you_mean=(self.property_name, self.lhs.type.properties.keys()),
|
||||
)
|
||||
|
||||
|
||||
|
@ -124,9 +147,13 @@ class CastExpr(InfixExpr):
|
|||
def type(self) -> T.Optional[GirType]:
|
||||
return self.children[TypeName][0].gir_type
|
||||
|
||||
@property
|
||||
def type_complete(self) -> bool:
|
||||
return True
|
||||
|
||||
@validate()
|
||||
def cast_makes_sense(self):
|
||||
if self.lhs.type is None:
|
||||
if self.type is None or self.lhs.type is None:
|
||||
return
|
||||
|
||||
if not self.type.assignable_to(self.lhs.type):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue