gss / parser

Constraint Cascading Style Sheets compiler
MIT License
48 stars 6 forks source link

2 dimensional sugar #1

Closed d4tocchini closed 10 years ago

d4tocchini commented 11 years ago

#box1[size] == #box2[size]

should compile to 2 constraints:

...
constraints: [
  ['eq', ['get', '#box1[width]'], ['get', '#box2[width]']]
  ['eq', ['get', '#box1[height]'], ['get', '#box2[height]']]
]
bergie commented 11 years ago

:+1:

paulyoung commented 10 years ago

I started looking into this, went to write a spec first, and saw this comment:

This should probably be handled with a preparser or optimizer, not the main PEG grammar

paulyoung commented 10 years ago

I think we're saying that a preparser would transform:

#box1[size] == #box2[size]

into:

#box1[width] == #box2[width]
#box1[height] == #box2[height]

We'd need a good strategy for not duplicating a lot of code between the two grammars since they'd both need the same rules. I've asked about this here: dmajda/pegjs#268

d4tocchini commented 10 years ago

That comment now seems too certain. Your point about duplicating parser rules hold weight. Probably best this is done within the CCSS grammar anyway so VFL & VGL can use 2-D properties and just send them down the stack.

There are some small details to consider, should the below throw a warning?

#box1[size] == #box2[width];

I say go on with your spec, this would be a super helpful addition!

Would be cool to support things like:

#box1[top-left] == #box2[center];
paulyoung commented 10 years ago

For reference, this exists if we ever wanted to use it: https://github.com/andreineculau/pegjs-override-action

paulyoung commented 10 years ago

Any requests for 2D mappings? So far I've configured:

{
  "bottom-left": ["left", "bottom"],
  "bottom-right": ["right", "bottom"],
  center: ["center-x", "center-y"],
  "intrinsic-size": ["intrinsic-width", "intrinsic-height"],
  position: ["x", "y"],
  size: ["width", "height"],
  "top-left": ["left", "top"],
  "top-right": ["right", "top"]
}
paulyoung commented 10 years ago

I have 2D sugar working for stays now too.

paulyoung commented 10 years ago

What's the status of measure? I see an old spec hinting that 2D should work for this too.

Was it deprecated?

paulyoung commented 10 years ago

There are some small details to consider, should the below throw a warning?

#box1[size] == #box2[width];

I need some input on this. Currently it will only create a constraint for the width but also doesn't issue any warnings.

paulyoung commented 10 years ago

Would something like this be preferred?

#box1[width] == #box2[width] !strong;
#box1[height] == #box2[width];
d4tocchini commented 10 years ago

measure was replaced with intrinsics, good catch.

as for #box1[size] == #box2[width];, it should probably constrain just the width so that 2-d props can be used in things like VFL helpers where the dimension would be inferred.