Compiler #10

Open
wants to merge 34 commits into
from

Conversation

Projects
None yet
1 participant
Owner

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 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.
9055ff9
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.
8a7d9bb
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.
8ab5c56
Sean Bryant [compiler] parse tree is now filled with tuples
fix up the tests.
11689a9
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.

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))))))
949a80d
Sean Bryant [compiler] simplify this whole parse tree mess to generate a consiste…
…nt tree.
27b611c
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
evil.
92eb01c
Sean Bryant [origin-compiler] First successful match!
(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")))
80ad3a0
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.
faf1ca3
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.
d61a332
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…
…dable
a5cac74
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