gss / parser

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

Port PEG JavaScript to CoffeeScript. #9

Closed paulyoung closed 10 years ago

paulyoung commented 10 years ago

This is exactly the same as #8 except that it's from the-gss/ccss-compiler instead of paulyoung/ccss-compiler which will makes things easier for another pull request I'm working on.

This is my first attempt at porting one of these.

The basic concept is that there is a CoffeeScript class whose instance methods each map to a rule in the grammar.

I went with this approach over other "use CoffeeScript with PEG" methods [1][2] since they affected the unlying way that PEG works.

All of the test pass, but I figured that there might be some things to discuss regarding naming or the API. In general, I tried to refactor or rename things to be more explicit and easier to understand.

This also addresses #7.

paulyoung commented 10 years ago

A note on the interface and my thinking behind why I chose to make it the way it is:

Everything is a function call, even though we could use direct access to objects.

For example:

grammar.conditionalOperator().gte();

could have been:

grammar.conditionalOperator.gte;

where conditionalOperator could be an object, and gte a string.

I decided to make everything a function call for the following reasons:

d4tocchini commented 10 years ago

Much cleaner - the peg file was getting out of hand! Your reasoning makes sense

Go ahead and push to master & update the other grammars. You should have access now