prochitecture / pml

Translator for PML (Prochitecture Markup Language)
2 stars 0 forks source link

Incorrect Python code with a condition #13

Closed vvoovv closed 1 year ago

vvoovv commented 1 year ago

The following PML code (attached as a text file here) generates incorrect Python code:

facade(item.gable and 2.5 < item.width < 12.) {
     claddingColor: if (item.front) green | green;
}

The resulting output is

styles = [
    Facade(
        condition = lambda item : item.gable and 2.5 < item.width < 12.,
        claddingColor = Value(Conditional(
            lambda item: item.frontValue(Alternatives(
,
                Constant((0.0, 0.502, 0.0, 1.0)),
                Constant((0.0, 0.502, 0.0, 1.0))
            ))
        ))
    )
]
polarkernel commented 1 year ago

The resulting output is

Could you please post the desired (correct) result? I am no more used to read PML code.

vvoovv commented 1 year ago

If the alternatives are reversed for claddingColor

facade(item.gable and 2.5 < item.width < 12.) {
     claddingColor:  green | if (item.front) green;
}

then it works correctly:

styles = [
    Facade(
        condition = lambda item : item.gable and 2.5 < item.width < 12.,
        claddingColor = Value(Alternatives(
            Constant((0.0, 0.502, 0.0, 1.0)),
            Conditional(
                lambda item: item.front,
                Constant((0.0, 0.502, 0.0, 1.0))
            )
        ))
    )
]

So the desired output should be:

styles = [
    Facade(
        condition = lambda item : item.gable and 2.5 < item.width < 12.,
        claddingColor = Value(Alternatives(
            Conditional(
                lambda item: item.front,
                Constant((0.0, 0.502, 0.0, 1.0))
            ),
            Constant((0.0, 0.502, 0.0, 1.0))
        ))
    )
]
polarkernel commented 1 year ago

The following PML code (attached as a text file here) generates incorrect Python code:

Fixed. Committed to the branch 'pml'.

vvoovv commented 1 year ago

Thank you very much! It works.

I'll add some unit tests to the repository to cover those cases.

vvoovv commented 1 year ago

Added unit tests at _tests/testconditional.py.