How to use the scamp._metric_structure.MeterArithmeticGroup function in scamp

To help you get started, we’ve selected a few scamp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MarcTheSpark / scamp / scamp / _metric_structure.py View on Github external
merged_multiplies = []
            i = 0
            while i < len(chunks):
                if i + 1 < len(chunks) and chunks[i + 1] == "*":
                    multiplied_elements = chunks[i:i + 3:2]
                    i += 3
                    while i < len(chunks) and chunks[i] == "*":
                        multiplied_elements.append(chunks[i + 1])
                        i += 2
                    merged_multiplies.append(
                        MeterArithmeticGroup([MeterArithmeticGroup.parse(x) for x in multiplied_elements], "*"))
                else:
                    merged_multiplies.append(chunks[i])
                    i += 1
            return MeterArithmeticGroup(
                [x if isinstance(x, MeterArithmeticGroup)
                 else MeterArithmeticGroup.parse(x) for x in merged_multiplies if x != "+"], "+"
            )
        else:
            return MeterArithmeticGroup([int(input_string)], None)
github MarcTheSpark / scamp / scamp / _metric_structure.py View on Github external
merged_multiplies = []
            i = 0
            while i < len(chunks):
                if i + 1 < len(chunks) and chunks[i + 1] == "*":
                    multiplied_elements = chunks[i:i + 3:2]
                    i += 3
                    while i < len(chunks) and chunks[i] == "*":
                        multiplied_elements.append(chunks[i + 1])
                        i += 2
                    merged_multiplies.append(
                        MeterArithmeticGroup([MeterArithmeticGroup.parse(x) for x in multiplied_elements], "*"))
                else:
                    merged_multiplies.append(chunks[i])
                    i += 1
            return MeterArithmeticGroup(
                [x if isinstance(x, MeterArithmeticGroup)
                 else MeterArithmeticGroup.parse(x) for x in merged_multiplies if x != "+"], "+"
            )
        else:
            return MeterArithmeticGroup([int(input_string)], None)
github MarcTheSpark / scamp / scamp / _metric_structure.py View on Github external
i = 0
            while i < len(chunks):
                if i + 1 < len(chunks) and chunks[i + 1] == "*":
                    multiplied_elements = chunks[i:i + 3:2]
                    i += 3
                    while i < len(chunks) and chunks[i] == "*":
                        multiplied_elements.append(chunks[i + 1])
                        i += 2
                    merged_multiplies.append(
                        MeterArithmeticGroup([MeterArithmeticGroup.parse(x) for x in multiplied_elements], "*"))
                else:
                    merged_multiplies.append(chunks[i])
                    i += 1
            return MeterArithmeticGroup(
                [x if isinstance(x, MeterArithmeticGroup)
                 else MeterArithmeticGroup.parse(x) for x in merged_multiplies if x != "+"], "+"
            )
        else:
            return MeterArithmeticGroup([int(input_string)], None)
github MarcTheSpark / scamp / scamp / _metric_structure.py View on Github external
chunks.append(current_chunk)

            if paren_level > 0:
                raise ValueError("Encountered unmatched open-parenthesis.")

            merged_multiplies = []
            i = 0
            while i < len(chunks):
                if i + 1 < len(chunks) and chunks[i + 1] == "*":
                    multiplied_elements = chunks[i:i + 3:2]
                    i += 3
                    while i < len(chunks) and chunks[i] == "*":
                        multiplied_elements.append(chunks[i + 1])
                        i += 2
                    merged_multiplies.append(
                        MeterArithmeticGroup([MeterArithmeticGroup.parse(x) for x in multiplied_elements], "*"))
                else:
                    merged_multiplies.append(chunks[i])
                    i += 1
            return MeterArithmeticGroup(
                [x if isinstance(x, MeterArithmeticGroup)
                 else MeterArithmeticGroup.parse(x) for x in merged_multiplies if x != "+"], "+"
            )
        else:
            return MeterArithmeticGroup([int(input_string)], None)
github MarcTheSpark / scamp / scamp / _metric_structure.py View on Github external
def from_string(cls, input_string: str, break_up_large_numbers: bool = False) -> 'MetricStructure':
        """
        Creates a MetricStructure from an appropriately formatted input string. This is the simplest way of creating
        complex nested structures. For example, "3 * 2 + 5 + (2 + 3)" renders to
        `MetricStructure(MetricStructure(2, 2, 2), 5, MetricStructure(2, 3))`.

        :param input_string: input string consisting of integers, plus signs, multiplication signs, and parentheses
        :param break_up_large_numbers: see :class:`MetricStructure`
        """
        return MeterArithmeticGroup.parse(input_string).to_metric_structure(break_up_large_numbers)
github MarcTheSpark / scamp / scamp / _metric_structure.py View on Github external
multiplied_elements = chunks[i:i + 3:2]
                    i += 3
                    while i < len(chunks) and chunks[i] == "*":
                        multiplied_elements.append(chunks[i + 1])
                        i += 2
                    merged_multiplies.append(
                        MeterArithmeticGroup([MeterArithmeticGroup.parse(x) for x in multiplied_elements], "*"))
                else:
                    merged_multiplies.append(chunks[i])
                    i += 1
            return MeterArithmeticGroup(
                [x if isinstance(x, MeterArithmeticGroup)
                 else MeterArithmeticGroup.parse(x) for x in merged_multiplies if x != "+"], "+"
            )
        else:
            return MeterArithmeticGroup([int(input_string)], None)