Compiler #10

wants to merge 34 commits into


None yet
1 participant

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. p


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 some commits Oct 3, 2011

Sean Bryant [compiler] we're going to need mop 59857a4
Sean Bryant [compiler] WIP beginnings of a tokenizing state machine 86bd640
Sean Bryant [compiler] remove read-css% symbol walker, not needed anymore. 0ee0021
Sean Bryant [compiler] add a place to store completed tokens. b14cd7a
Sean Bryant [compiler] don't need read-css right now. 0412db4
Sean Bryant [compiler] add support for class and id events d07a096
Sean Bryant [compiler] add a token emitter to emit tokens on event change. 702692f
Sean Bryant [compiler] removing the token-prefix, should never have been added. 2ab7bb9
Sean Bryant [compiler] comment out some spurious logging, also coerce the buffer …
…sequence into a string.
Sean Bryant [compilers] add id and class emitters, simplifies the process 7e4374d
Sean Bryant [compiler] make strings in to keyword symbols. also bring back read-c…
…ss, used in tests.
Sean Bryant [compiler] finally generating correct token stream. aeadbc3
Sean Bryant [compiler] add support for adjacent siblings b6a8f10
Sean Bryant [compiler] generate parse tree e736a89
Sean Bryant [compiler] make tests work with parse tree structure. probably changi…
…ng soon.
Sean Bryant [compiler] parse tree is now filled with tuples
fix up the tests.
Sean Bryant [compiler] remove next-event from emit-token. f6ae6da
Sean Bryant [compiler] add compound statements to tokens-to-tree.
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.


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

                                 (:DESCENDANTS ((:SYMBOL :P))))

                                                (:ID :MY-ID))))

                                             (:ID :MY-ID)))
                                 (:DESCENDANTS ((:SYMBOL :P))))

                                                                (:ID :MY-ID)))
                                                    (:DESCENDANTS ((:COMPOUND ((:SYMBOL :P)
                                                                               (:CLASS :MY-CLASS))))))
Sean Bryant [compiler] simplify this whole parse tree mess to generate a consiste…
…nt tree.
Sean Bryant [origin-compiler] Clean up whitespace. 3927a95
Sean Bryant [origin-compiler] Symbol and class matching work...poorly. 8105372
Sean Bryant [origin-compiler] Make compound match descendent.
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
Sean Bryant [origin-compiler] First successful match!
(matches-p (make-path-matcher "p.b") *lhtml-nodes*)

where lhtml nodes looks something like:

 (:BODY NIL (:P ((:ID "a") (:CLASS "b")) "Test")))
Sean Bryant [origin-compiler] Matching based on element id are go. fb797ce
Sean Bryant [origin-compiler] Return the reference the node that matched. 60a85e1
Sean Bryant [origin-compiler] Descending and compounding was broken.
Specifically, the problem was with descending without compound predicates.
This lead to strange behavior when descendants weren't forms but just
random tokens.
Sean Bryant [origin-compiler] Work in progress to get descendant matchers working.
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.
Sean Bryant [origin-compiler] Don't know what I was thinking here. 640c477
Sean Bryant [origin-compiler] All the parse tests pass now. 5d94de5
Sean Bryant [origin-compiler] Use criterion aliases to make the criteria more rea…
Sean Bryant [origin-compiler] Time to stop throwing everything into a single file. c4eb83e
Sean Bryant [origin-compiler] Add the matching group with a BS test. 🐴 0811078
Sean Bryant [origin-compiler] Add a simple html fixture 2a8f77d
Sean Bryant [origin-compiler] Add some path matching tests. 0f867b1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment