Fix some more parsing issues

Example of issues we had is that parsing floating point numbers would parse the dot as an attribute syntax and trying to retrieve both sides of the attributes to the get_value resolve. E.g `3.14` would be interpreted as getting the `14` property of the object `3`, which ofcourse throws an error.

CURA-11347
This commit is contained in:
c.lamboo 2023-11-16 14:45:46 +01:00
parent 036516b8f9
commit 36f2deea1d

View file

@ -6,7 +6,7 @@ import numpy
from string import Formatter from string import Formatter
from enum import IntEnum from enum import IntEnum
import time import time
from typing import Any, cast, Dict, List, Optional, Set from typing import Any, cast, Dict, List, Optional, Set, Tuple
import re import re
import pyArcus as Arcus # For typing. import pyArcus as Arcus # For typing.
from PyQt6.QtCore import QCoreApplication from PyQt6.QtCore import QCoreApplication
@ -68,6 +68,14 @@ class GcodeStartEndFormatter(Formatter):
self._default_extruder_nr: int = default_extruder_nr self._default_extruder_nr: int = default_extruder_nr
self._additional_per_extruder_settings: Optional[Dict[str, Dict[str, any]]] = additional_per_extruder_settings self._additional_per_extruder_settings: Optional[Dict[str, Dict[str, any]]] = additional_per_extruder_settings
def get_field(self, field_name, args: [str], kwargs: dict) -> Tuple[str, str]:
# get_field method parses all fields in the format-string and parses them individually to the get_value method.
# e.g. for a string "Hello {foo.bar}" would the complete field "foo.bar" would be passed to get_field, and then
# the individual parts "foo" and "bar" would be passed to get_value. This poses a problem for us, because want
# to parse the entire field as a single expression. To solve this, we override the get_field method and return
# the entire field as the expression.
return self.get_value(field_name, args, kwargs), field_name
def get_value(self, expression: str, args: [str], kwargs: dict) -> str: def get_value(self, expression: str, args: [str], kwargs: dict) -> str:
# The following variables are not settings, but only become available after slicing. # The following variables are not settings, but only become available after slicing.