Skip to content

How it works

Vivek edited this page Feb 7, 2018 · 1 revision

The core of this library is a constexpr based parser for a basic HTML dialect. constexpr functions in C++ execute during compiletime and generate values.

The set of features that can be used in constexpr is quite extensive, and it makes meta-programming much more easier than the traditional template based code.

HTML can be considered a multiway tree of nodes and each node can have any number of key value pairs as attributes.

A tree structure is dynamic, and typically needs runtime allocation for nodes. However we do not have dynamic allocation during constexpr - everything needs to have predeterminable sizes. That leaves us with essentially statically sized arrays and structs as the only possible data structures.

The way out of this problem is to simply pre-allocate an array of nodes of a fixed size, and use that as an allocation pool. We never need to change the shape of the tree, nor delete nodes, so this works fantastcially. The limitation is that our tree is restricted by the total number of nodes we pre-allocated. In future versions of this library we will attempt to overcome that limitation.

If you deal with nodes from an array as the base unit to construct a tree, once can use indices instead of pointers. This is convenient and looks better.

Our tree is "construct only". Meaning it gets built and never changes - we do not need to implement anything except creation and traversal strategies.

Now note that multiway trees need an arbitrary number of child node pointers in each node - so we again hit the problem of how to implement dynamic allocation.

Clone this wiki locally