mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
language: Add expression literals
Add expression literals, so you can set properties of type Gtk.Expression.
This commit is contained in:
parent
a6d57cebec
commit
02344139c2
29 changed files with 268 additions and 21 deletions
|
@ -81,6 +81,16 @@ class LiteralExpr(ExprBase):
|
|||
or self.root.is_legacy_template(self.literal.value.ident)
|
||||
)
|
||||
|
||||
@property
|
||||
def is_this(self) -> bool:
|
||||
from .values import IdentLiteral
|
||||
|
||||
return (
|
||||
not self.is_object
|
||||
and isinstance(self.literal.value, IdentLiteral)
|
||||
and self.literal.value.ident == "item"
|
||||
)
|
||||
|
||||
@property
|
||||
def literal(self):
|
||||
from .values import Literal
|
||||
|
@ -91,6 +101,15 @@ class LiteralExpr(ExprBase):
|
|||
def type(self) -> T.Optional[GirType]:
|
||||
return self.literal.value.type
|
||||
|
||||
@validate()
|
||||
def item_validations(self):
|
||||
if self.is_this:
|
||||
if not isinstance(self.rhs, CastExpr):
|
||||
raise CompileError('"item" must be cast to its object type')
|
||||
|
||||
if not isinstance(self.rhs.rhs, LookupOp):
|
||||
raise CompileError('"item" can only be used for looking up properties')
|
||||
|
||||
|
||||
class LookupOp(InfixExpr):
|
||||
grammar = [".", UseIdent("property")]
|
||||
|
@ -285,6 +304,9 @@ expr.children = [
|
|||
def decompile_lookup(
|
||||
ctx: DecompileCtx, gir: gir.GirContext, cdata: str, name: str, type: str
|
||||
):
|
||||
if ctx.parent_node is not None and ctx.parent_node.tag == "property":
|
||||
ctx.print("expr ")
|
||||
|
||||
if t := ctx.type_by_cname(type):
|
||||
type = decompile.full_name(t)
|
||||
else:
|
||||
|
@ -304,6 +326,8 @@ def decompile_lookup(
|
|||
if constant is not None:
|
||||
if constant == ctx.template_class:
|
||||
ctx.print("template." + name)
|
||||
elif constant == "":
|
||||
ctx.print("item as <" + type + ">." + name)
|
||||
else:
|
||||
ctx.print(constant + "." + name)
|
||||
return
|
||||
|
@ -318,6 +342,9 @@ def decompile_lookup(
|
|||
def decompile_constant(
|
||||
ctx: DecompileCtx, gir: gir.GirContext, cdata: str, type: T.Optional[str] = None
|
||||
):
|
||||
if ctx.parent_node is not None and ctx.parent_node.tag == "property":
|
||||
ctx.print("expr ")
|
||||
|
||||
if type is None:
|
||||
if cdata == ctx.template_class:
|
||||
ctx.print("template")
|
||||
|
@ -330,6 +357,9 @@ def decompile_constant(
|
|||
|
||||
@decompiler("closure", skip_children=True)
|
||||
def decompile_closure(ctx: DecompileCtx, gir: gir.GirContext, function: str, type: str):
|
||||
if ctx.parent_node is not None and ctx.parent_node.tag == "property":
|
||||
ctx.print("expr ")
|
||||
|
||||
if t := ctx.type_by_cname(type):
|
||||
type = decompile.full_name(t)
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue