mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Fix parsing decimals
A number literal is a float if it contains ".", not if it is divisible by 1. For example, 1.0 should be considered a float literal.
This commit is contained in:
parent
c69a12096c
commit
883a136103
8 changed files with 24 additions and 6 deletions
|
@ -19,7 +19,7 @@ build:
|
||||||
- ninja -C _build docs/en
|
- ninja -C _build docs/en
|
||||||
- git clone https://gitlab.gnome.org/jwestman/blueprint-regression-tests.git
|
- git clone https://gitlab.gnome.org/jwestman/blueprint-regression-tests.git
|
||||||
- cd blueprint-regression-tests
|
- cd blueprint-regression-tests
|
||||||
- git checkout 3077f669fc9c8e3ceb4da85e6bda680c297c58a2
|
- git checkout 9bfb9325d75a9985310230f119579f07df519e60
|
||||||
- ./test.sh
|
- ./test.sh
|
||||||
- cd ..
|
- cd ..
|
||||||
coverage: '/TOTAL.*\s([.\d]+)%/'
|
coverage: '/TOTAL.*\s([.\d]+)%/'
|
||||||
|
|
|
@ -192,6 +192,9 @@ class XmlOutput(OutputFormat):
|
||||||
xml.put_text(self._object_id(value, value.ident))
|
xml.put_text(self._object_id(value, value.ident))
|
||||||
elif isinstance(value, TypeLiteral):
|
elif isinstance(value, TypeLiteral):
|
||||||
xml.put_text(value.type_name.glib_type_name)
|
xml.put_text(value.type_name.glib_type_name)
|
||||||
|
else:
|
||||||
|
if isinstance(value.value, float) and value.value == int(value.value):
|
||||||
|
xml.put_text(int(value.value))
|
||||||
else:
|
else:
|
||||||
xml.put_text(value.value)
|
xml.put_text(value.value)
|
||||||
|
|
||||||
|
|
|
@ -520,8 +520,6 @@ class UseNumber(ParseNode):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
number = token.get_number()
|
number = token.get_number()
|
||||||
if number % 1.0 == 0:
|
|
||||||
number = int(number)
|
|
||||||
ctx.set_group_val(self.key, number, token)
|
ctx.set_group_val(self.key, number, token)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,10 @@ class Token:
|
||||||
try:
|
try:
|
||||||
if string.startswith("0x"):
|
if string.startswith("0x"):
|
||||||
return int(string, 16)
|
return int(string, 16)
|
||||||
else:
|
elif "." in string:
|
||||||
return float(string)
|
return float(string)
|
||||||
|
else:
|
||||||
|
return int(string)
|
||||||
except:
|
except:
|
||||||
raise CompileError(
|
raise CompileError(
|
||||||
f"{str(self)} is not a valid number literal", self.start, self.end
|
f"{str(self)} is not a valid number literal", self.start, self.end
|
||||||
|
|
5
tests/samples/issue_119.blp
Normal file
5
tests/samples/issue_119.blp
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
using Gtk 4.0;
|
||||||
|
|
||||||
|
Adjustment {
|
||||||
|
value: bind 1.0 as <double>;
|
||||||
|
}
|
9
tests/samples/issue_119.ui
Normal file
9
tests/samples/issue_119.ui
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk" version="4.0"/>
|
||||||
|
<object class="GtkAdjustment">
|
||||||
|
<binding name="value">
|
||||||
|
<constant type="gfloat">1</constant>
|
||||||
|
</binding>
|
||||||
|
</object>
|
||||||
|
</interface>
|
|
@ -2,7 +2,7 @@ using Gtk 4.0;
|
||||||
|
|
||||||
Gtk.Label {
|
Gtk.Label {
|
||||||
xalign: .5;
|
xalign: .5;
|
||||||
|
yalign: 0.0;
|
||||||
height-request: 1_000_000;
|
height-request: 1_000_000;
|
||||||
margin-top: 0x30;
|
margin-top: 0x30;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
<requires lib="gtk" version="4.0"/>
|
<requires lib="gtk" version="4.0"/>
|
||||||
<object class="GtkLabel">
|
<object class="GtkLabel">
|
||||||
<property name="xalign">0.5</property>
|
<property name="xalign">0.5</property>
|
||||||
|
<property name="yalign">0</property>
|
||||||
<property name="height-request">1000000</property>
|
<property name="height-request">1000000</property>
|
||||||
<property name="margin-top">48</property>
|
<property name="margin-top">48</property>
|
||||||
</object>
|
</object>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue