diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7e9ee9c..ed26158 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,7 +19,7 @@ build: - ninja -C _build docs/en - git clone https://gitlab.gnome.org/jwestman/blueprint-regression-tests.git - cd blueprint-regression-tests - - git checkout 3077f669fc9c8e3ceb4da85e6bda680c297c58a2 + - git checkout 9bfb9325d75a9985310230f119579f07df519e60 - ./test.sh - cd .. coverage: '/TOTAL.*\s([.\d]+)%/' diff --git a/blueprintcompiler/outputs/xml/__init__.py b/blueprintcompiler/outputs/xml/__init__.py index e9f091f..12b4e18 100644 --- a/blueprintcompiler/outputs/xml/__init__.py +++ b/blueprintcompiler/outputs/xml/__init__.py @@ -193,7 +193,10 @@ class XmlOutput(OutputFormat): elif isinstance(value, TypeLiteral): xml.put_text(value.type_name.glib_type_name) else: - xml.put_text(value.value) + if isinstance(value.value, float) and value.value == int(value.value): + xml.put_text(int(value.value)) + else: + xml.put_text(value.value) def _emit_value(self, value: Value, xml: XmlEmitter): if isinstance(value.child, Literal): diff --git a/blueprintcompiler/parse_tree.py b/blueprintcompiler/parse_tree.py index 48f60b1..3ddac69 100644 --- a/blueprintcompiler/parse_tree.py +++ b/blueprintcompiler/parse_tree.py @@ -520,8 +520,6 @@ class UseNumber(ParseNode): return False number = token.get_number() - if number % 1.0 == 0: - number = int(number) ctx.set_group_val(self.key, number, token) return True diff --git a/blueprintcompiler/tokenizer.py b/blueprintcompiler/tokenizer.py index 3c98b94..bde8dd1 100644 --- a/blueprintcompiler/tokenizer.py +++ b/blueprintcompiler/tokenizer.py @@ -70,8 +70,10 @@ class Token: try: if string.startswith("0x"): return int(string, 16) - else: + elif "." in string: return float(string) + else: + return int(string) except: raise CompileError( f"{str(self)} is not a valid number literal", self.start, self.end diff --git a/tests/samples/issue_119.blp b/tests/samples/issue_119.blp new file mode 100644 index 0000000..145a9f8 --- /dev/null +++ b/tests/samples/issue_119.blp @@ -0,0 +1,5 @@ +using Gtk 4.0; + +Adjustment { + value: bind 1.0 as ; +} \ No newline at end of file diff --git a/tests/samples/issue_119.ui b/tests/samples/issue_119.ui new file mode 100644 index 0000000..2e039b5 --- /dev/null +++ b/tests/samples/issue_119.ui @@ -0,0 +1,9 @@ + + + + + + 1 + + + diff --git a/tests/samples/numbers.blp b/tests/samples/numbers.blp index 9ac25dd..ae0ce42 100644 --- a/tests/samples/numbers.blp +++ b/tests/samples/numbers.blp @@ -2,7 +2,7 @@ using Gtk 4.0; Gtk.Label { xalign: .5; + yalign: 0.0; height-request: 1_000_000; margin-top: 0x30; - } diff --git a/tests/samples/numbers.ui b/tests/samples/numbers.ui index 03dee06..813afe4 100644 --- a/tests/samples/numbers.ui +++ b/tests/samples/numbers.ui @@ -3,6 +3,7 @@ 0.5 + 0 1000000 48