gss / parser

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

Parser should produce "Command Array" #2

Closed d4tocchini closed 10 years ago

d4tocchini commented 10 years ago

For the CCSS Statement,

[grid-height] * #box2[width] <= 2

Right now, the parser spits out,

{
            selectors: [
              '#box2'
            ],
            vars: [
              ['var', "[grid-height]", 'grid-height']
              ['var', '#box2[width]','width', ['$id', 'box2']]
            ],
            constraints: [
              ['lte', [
                'multiply', ['get', '[grid-height]'], ['get', '#box2[width]']
                ], 
                ['number', 2]
              ]
            ]
          }

Instead, it needs to produce an array of instructions, the Command Array of the form,

[
  ['var', '[grid-height]', 'grid-height'],
  ['var', '.box[width]', 'width', ['$class', 'box']]
  ['lte', ...
]

errr...

paulyoung commented 10 years ago

@d4tocchini - could you explain why a Command Array is needed / preferred?

d4tocchini commented 10 years ago

This is actually an old, and now outdated comment... I'm now ok with compiling out an object with a commands property for the Command Array. I use an array to store the command instructions for a few reasons:

Of course, there are drawbacks...

Also, I no longer use var commands. Vars are created dynamically in the cassowary web worker (the-gss/engine/src/Thread)... On that note, I've received requests to require vars to be declared with something like @var, but years of coffeescript has gotten me addicted to more implicit / literate syntax.

What were your thoughts?

paulyoung commented 10 years ago

I was really just trying to put the pieces together when I asked. Things makes a bit more sense now I've gotten more familiar.

Recursion is elegant if you can get away with it. I suppose there's no real danger of the array getting that deeply nested that you run out of memory.

Implicit variable declaration just takes some getting used to. I thought it was weird in CoffeeScript at first but then I got used to it.