|
The CommonMark\CQL classIntroductionCommonMark Query Language is a DSL for describing how to travel through a CommonMark Node tree implemented as a parser and compiler for a small set of instructions, and a virtual machine for executing those instructions.
Paths:
In it's most simplistic form, a CQL query combines the following paths and
/firstChild/lastChild would travel to the last child node of the first child node.
Loops
CQL can be instructed to loop, for example through the children of, or siblings to a particular node, by using the path
Subqueries
CQL can be instructed how to travel by using a subquery like
Loop Constraints
While looping, CQL can be instructed to constrict the travelled path to nodes of particular type. For example
/children(BlockQuote|List) will travel to the children of a node where the type is BlockQuote or List . Types, or unions of types, may be also negated. For example /children(~BlockQuote) will travel to the children of a node where the type is not BlockQuote , and /children(~BlockQuote|Paragraph) will travel to the children of a node where the type is not BlockQuote or Paragraph
Path Constraints
CQL can be instructed to create a loop to travel to a node of a particular type, at a particular path. For example,
Implementation NotesWhile CQL has been implemented as part of the PHP CommonMark extension, it stands separately from PHP and does not use PHP's virtual machine or internal representation of values. Class synopsisCommonMark\CQL
class CommonMark\CQL
{
/* Constructor */
public __construct(string
$query )/* Methods */
public __invoke(CommonMark\Node
}$root , callable $handler )
|