/css-selectors

A common lisp library that implements a css3 selector query language on CXML DOM documents and Nodes

Primary LanguageCommon LispGNU Lesser General Public License v3.0LGPL-3.0

Table of Contents

css-selectors: a jquery-style dom query language

CSS-selectors is a query language for finding specific nodes in cxml dom documents and dom sub trees.

API

query

 (query 
   (or css-selector-string match-fn)
   (or nodes *document*))

Similar to jQuery('css-selector', NodeList or *document*)

Returns a list of matching nodes.

if the second argument is a css-selector, compile it (as with compile-css-node-matcher) into a matcher function and call query again with it

if the second argument is a function, it is assumed to take a single node and to test whether or not that node matches the css-selector match function

If the css-selector-string is constantp, it will be compiled at compile time

node-matches?

 (node-matches? node-node (or match-fn css-selector-string))

if the second argument is a css-selector, compile it (as with compile-css-node-matcher) into a matcher function and call node-matches again with it

if the second argument is a function, it is assumed to take a single node and to test whether or not that node matches the css-selector match function

If the css-selector-string is constantp, it will be compiled at compile time

parse-results

 (parse-results inp)

Parses a css3 selector into an AST representing the selector expression. Probably only useful for debugging or implementing a different compiler.

Uses clppcre and *VERY* basic flex parser (defined in parse.lisp) to create a lexer. Combines that lexer with a parser generated by cl-yacc and runs the input through the parse.

compile-css-node-matcher

 (compile-css-node-matcher inp)

Turns a parse-tree or css-selector-string into a compiled lambda matcher function this matcher function can be used with query and node-matches?. The matcher function takes two arguments

Pseudo Selectors

Implementing new pseudo selectors

Any function defined in the :pseudo (:css-selectors.pseudo) will be available as a pseudo selector (see pseudo.lisp for examples).

All pseudo selectors should be of the following format: (defun pseudo:MY-NEW-PSEUDO (node &optional sub-sel-function) ...)

If your pseudo selector has no args, then it should signal an error if a sub-selction-function is passed to it and vice-versa