Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler #10

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open

Compiler #10

wants to merge 34 commits into from

Conversation

sbryant
Copy link
Owner

@sbryant sbryant commented Dec 19, 2011

This is the beginnings of a compiler that'll generate compiled CSS expression matchers for CSS paths.

Right now it's very simple and the only things supported are:

  • Elements div
  • Classes .my-class
  • ID #my-id
  • Descendant elements div p

And compound expressions built from any of the above.
div#my-id.my-class p

Limitations

Only a single reference is returned from the matcher. The matcher actually recurs already I just return the first match I encounter. The correct behavior would be to build a list of references.

Sean Bryant added 30 commits October 3, 2011 01:07
In the event we get a list of one we can just return it, since we have no tree to deal with.
If we have a list of more than one, attempt to compound the statements until we rerun into a descendant token. If list of compounds greater than 1 wrap in a compound statement then wrap a subtree in descendants. If we do not have a list of compounds greater than one just cons token with the descendants.

Examples:

'((:SYMBOL :DIV)) => '((:SYMBOL :DIV))

'((:SYMBOL :DIV)
   :DESCENDANT (:SYMBOL :P) => '((SYMBOL :DIV)
                                 (:DESCENDANTS ((:SYMBOL :P))))

'((:SYMBOL :DIV) (:ID :MY-ID)) => '((:COMPOUND ((:SYMBOL :DIV)
                                                (:ID :MY-ID))))

'((:SYMBOL :DIV) (:ID :MY-ID)
  :DESCENDANT (:SYMBOL :P)) => '((:COMPOUND ((:SYMBOL :DIV)
                                             (:ID :MY-ID)))
                                 (:DESCENDANTS ((:SYMBOL :P))))

'((:SYMBOL :DIV) (:ID :MY-ID)
  :DESCENDANT (:SYMBOL :P) (:CLASS :MY-CLASS)) => '((:COMPOUND ((:SYMBOL :DIV)
                                                                (:ID :MY-ID)))
                                                    (:DESCENDANTS ((:COMPOUND ((:SYMBOL :P)
                                                                               (:CLASS :MY-CLASS))))))
This seems strange but it makes sense. Instead of generating a form like
((:compound (:symbol :a) (:class :b))) generate a form that looks like:
(:compound (:symbol :a) (:class :b))

This requires a tree to be a tree with a single root rather than something
evil.
(matches-p (make-path-matcher "p.b") *lhtml-nodes*)

where lhtml nodes looks something like:

(:HTML NIL (:HEAD NIL (:TITLE NIL "lol"))
 (:BODY NIL (:P ((:ID "a") (:CLASS "b")) "Test")))
Specifically, the problem was with descending without compound predicates.
This lead to strange behavior when descendants weren't forms but just
random tokens.
My approach is a little annoying and not really clear. I'll need to redo
this in very near future because of the complexity of adding attribute and
content selector support.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant