prochitecture / pml

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

Style attributes in a condition #7

Open vvoovv opened 3 years ago

vvoovv commented 3 years ago

It's desirable to access some variables in the condition of a style block.

Example. A small building can have only one entrance. A larger building can have exactly two entrances.

That can be realized by using the style variable count in the condition. It's proposed to prefix it with the style namespace.

facade[item.front and style.count<=1] {
  class: facade_with_door;
}
vvoovv commented 3 years ago

Other style variables may be introduced later. They should be also accessed in the similar way: style.variable.

vvoovv commented 3 years ago

style.count should be translated to self.count.

polarkernel commented 3 years ago

I see.

It would be less complicated to implement, when style.variable could appear in both, in a condition and in an arithemtic expression. Would that be OK?

Is it important to restrict variable to count and other identifiers to be introduced later, or could it be just a free name?

vvoovv commented 3 years ago

Sorry, I didn't understand what you meant by the arithmetic expression.

vvoovv commented 3 years ago

Is it important to restrict variable to count and other identifiers to be introduced later, or could it be just a free name?

I thought it should be implemented in the same way as item.variable. As far as I can see a variable for the item can be any name. Is it correct?

polarkernel commented 3 years ago

Sorry, I didn't understand what you meant by the arithmetic expression.

Something like

levels: height * style.count

Don't know if such constructions could make sense somewhere, but it would be easier not to restrict it to conditions.

I thought it should be implemented in the same way as item.variable. As far as I can see a variable for the item can be any name. Is it correct?

Yes. Any name would be accepted by the translator and not just predefined names like count.

vvoovv commented 3 years ago

Something like

levels: height * style.count

Expressions for attributes could be a useful feature. It deserves a separate issue for discussions. I'll create one. It can be translated to something like: levels = Value(Expression(lambda item: ...)),

Don't know if such constructions could make sense somewhere, but it would be easier not to restrict it to conditions.

Ok, let's not restrict item.variable and style.variable to conditions.

Yes. Any name would be accepted by the translator and not just predefined names like count.

Let's do the same for style.variable.

polarkernel commented 3 years ago

Style attributes in a condition implemented and commited. The example

        facade[item.front and style.count<=1] {
        class: facade_with_door;
        }

translates to

        Facade(
            condition = lambda item : item.front and self.count <= 1,
            cl = "facade_with_door"
        )

Any name behind style gets accepted. Usage in expressions will be a separate issue for discussions, as proposed.

vvoovv commented 3 years ago

Style attributes in a condition implemented and commited.

Thanks! Now I'll have to introduce style.count in the code of the addon.