mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Add StringValue
Makes the grammar more specific in a few places that take only a string literal or translated string.
This commit is contained in:
parent
5bfed72674
commit
ac2a7d9282
8 changed files with 66 additions and 42 deletions
|
@ -368,3 +368,24 @@ class Value(AstNode):
|
|||
self,
|
||||
) -> T.Union[PropertyBinding, Binding, Translated, ObjectValue, Flags, Literal]:
|
||||
return self.children[0]
|
||||
|
||||
|
||||
class StringValue(AstNode):
|
||||
grammar = AnyOf(Translated, QuotedLiteral)
|
||||
|
||||
@property
|
||||
def child(
|
||||
self,
|
||||
) -> T.Union[Translated, QuotedLiteral]:
|
||||
return self.children[0]
|
||||
|
||||
@property
|
||||
def string(self) -> str:
|
||||
if isinstance(self.child, Translated):
|
||||
return self.child.child.string
|
||||
else:
|
||||
return self.child.value
|
||||
|
||||
@context(ValueTypeCtx)
|
||||
def value_type(self) -> ValueTypeCtx:
|
||||
return ValueTypeCtx(StringType())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue