Hubbub $Id$
Macros | Functions
treebuilder.c File Reference
#include <assert.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include "treebuilder/modes.h"
#include "treebuilder/internal.h"
#include "treebuilder/treebuilder.h"
#include "utils/utils.h"

Macros

#define mode(x)
 

Functions

hubbub_error hubbub_treebuilder_create (hubbub_tokeniser *tokeniser, hubbub_treebuilder **treebuilder)
 Create a hubbub treebuilder. More...
 
hubbub_error hubbub_treebuilder_destroy (hubbub_treebuilder *treebuilder)
 Destroy a hubbub treebuilder. More...
 
hubbub_error hubbub_treebuilder_setopt (hubbub_treebuilder *treebuilder, hubbub_treebuilder_opttype type, hubbub_treebuilder_optparams *params)
 Configure a hubbub treebuilder. More...
 
hubbub_error hubbub_treebuilder_token_handler (const hubbub_token *token, void *pw)
 Handle tokeniser emitting a token. More...
 
hubbub_error process_characters_expect_whitespace (hubbub_treebuilder *treebuilder, const hubbub_token *token, bool insert_into_current_node)
 Process a character token in cases where we expect only whitespace. More...
 
hubbub_error process_comment_append (hubbub_treebuilder *treebuilder, const hubbub_token *token, void *parent)
 Process a comment token, appending it to the given parent. More...
 
hubbub_error parse_generic_rcdata (hubbub_treebuilder *treebuilder, const hubbub_token *token, bool rcdata)
 Trigger parsing of generic (R)CDATA. More...
 
uint32_t element_in_scope (hubbub_treebuilder *treebuilder, element_type type, bool in_table)
 Determine if an element is in (table) scope. More...
 
hubbub_error reconstruct_active_formatting_list (hubbub_treebuilder *treebuilder)
 Reconstruct the list of active formatting elements. More...
 
hubbub_error remove_node_from_dom (hubbub_treebuilder *treebuilder, void *node)
 Remove a node from the DOM. More...
 
void clear_active_formatting_list_to_marker (hubbub_treebuilder *treebuilder)
 Clear the list of active formatting elements up to the last marker. More...
 
hubbub_error insert_element (hubbub_treebuilder *treebuilder, const hubbub_tag *tag, bool push)
 Create element and insert it into the DOM, potentially pushing it on the stack. More...
 
void close_implied_end_tags (hubbub_treebuilder *treebuilder, element_type except)
 Close implied end tags. More...
 
void reset_insertion_mode (hubbub_treebuilder *treebuilder)
 Reset the insertion mode. More...
 
hubbub_error complete_script (hubbub_treebuilder *treebuilder)
 Script processing and execution. More...
 
hubbub_error append_text (hubbub_treebuilder *treebuilder, const hubbub_string *string)
 Append text to the current node, inserting into the last child of the current node, iff it's a Text node. More...
 
bool is_special_element (element_type type)
 Determine if a node is a special element. More...
 
bool is_scoping_element (element_type type)
 Determine if a node is a scoping element. More...
 
bool is_formatting_element (element_type type)
 Determine if a node is a formatting element. More...
 
bool is_phrasing_element (element_type type)
 Determine if a node is a phrasing element. More...
 
hubbub_error element_stack_push (hubbub_treebuilder *treebuilder, hubbub_ns ns, element_type type, void *node)
 Push an element onto the stack of open elements. More...
 
hubbub_error element_stack_pop (hubbub_treebuilder *treebuilder, hubbub_ns *ns, element_type *type, void **node)
 Pop an element off the stack of open elements. More...
 
hubbub_error element_stack_pop_until (hubbub_treebuilder *treebuilder, element_type type)
 Pop elements until an element of type "element" has been popped. More...
 
hubbub_error element_stack_remove (hubbub_treebuilder *treebuilder, uint32_t index, hubbub_ns *ns, element_type *type, void **removed)
 Remove a node from the stack of open elements. More...
 
uint32_t current_table (hubbub_treebuilder *treebuilder)
 Find the stack index of the current table. More...
 
element_type current_node (hubbub_treebuilder *treebuilder)
 Peek at the top element of the element stack. More...
 
element_type prev_node (hubbub_treebuilder *treebuilder)
 Peek at the element below the top of the element stack. More...
 
hubbub_error formatting_list_append (hubbub_treebuilder *treebuilder, hubbub_ns ns, element_type type, void *node, uint32_t stack_index)
 Append an element to the end of the list of active formatting elements. More...
 
hubbub_error formatting_list_insert (hubbub_treebuilder *treebuilder, formatting_list_entry *prev, formatting_list_entry *next, hubbub_ns ns, element_type type, void *node, uint32_t stack_index)
 Insert an element into the list of active formatting elements. More...
 
hubbub_error formatting_list_remove (hubbub_treebuilder *treebuilder, formatting_list_entry *entry, hubbub_ns *ns, element_type *type, void **node, uint32_t *stack_index)
 Remove an element from the list of active formatting elements. More...
 
hubbub_error formatting_list_replace (hubbub_treebuilder *treebuilder, formatting_list_entry *entry, hubbub_ns ns, element_type type, void *node, uint32_t stack_index, hubbub_ns *ons, element_type *otype, void **onode, uint32_t *ostack_index)
 Remove an element from the list of active formatting elements. More...
 
void element_stack_dump (hubbub_treebuilder *treebuilder, FILE *fp)
 Dump an element stack to the given file pointer. More...
 
void formatting_list_dump (hubbub_treebuilder *treebuilder, FILE *fp)
 Dump a formatting list to the given file pointer. More...
 

Macro Definition Documentation

◆ mode

#define mode (   x)
Value:
case x: \
printf( #x "\n");

Function Documentation

◆ append_text()

hubbub_error append_text ( hubbub_treebuilder treebuilder,
const hubbub_string string 
)

Append text to the current node, inserting into the last child of the current node, iff it's a Text node.

Parameters
treebuilderThe treebuilder instance
stringThe string to append
Returns
HUBBUB_OK on success, appropriate error otherwise

◆ clear_active_formatting_list_to_marker()

void clear_active_formatting_list_to_marker ( hubbub_treebuilder treebuilder)

Clear the list of active formatting elements up to the last marker.

Parameters
treebuilderThe treebuilder instance containing the list

◆ close_implied_end_tags()

void close_implied_end_tags ( hubbub_treebuilder treebuilder,
element_type  except 
)

Close implied end tags.

Parameters
treebuilderThe treebuilder instance
exceptTag type to exclude from processing [DD,DT,LI,OPTION, OPTGROUP,P,RP,RT], UNKNOWN to exclude nothing

◆ complete_script()

hubbub_error complete_script ( hubbub_treebuilder treebuilder)

Script processing and execution.

Parameters
treebuilderThe treebuilder instance
Returns
HUBBUB_OK on success, appropriate error otherwise

◆ current_node()

element_type current_node ( hubbub_treebuilder treebuilder)

Peek at the top element of the element stack.

Parameters
treebuilderTreebuilder instance
Returns
Element type on the top of the stack

◆ current_table()

uint32_t current_table ( hubbub_treebuilder treebuilder)

Find the stack index of the current table.

◆ element_in_scope()

uint32_t element_in_scope ( hubbub_treebuilder treebuilder,
element_type  type,
bool  in_table 
)

Determine if an element is in (table) scope.

Parameters
treebuilderTreebuilder to look in
typeElement type to find
in_tableWhether we're looking in table scope
Returns
Element stack index, or 0 if not in scope

◆ element_stack_dump()

void element_stack_dump ( hubbub_treebuilder treebuilder,
FILE *  fp 
)

Dump an element stack to the given file pointer.

Parameters
treebuilderThe treebuilder instance
fpThe file to dump to

◆ element_stack_pop()

hubbub_error element_stack_pop ( hubbub_treebuilder treebuilder,
hubbub_ns ns,
element_type type,
void **  node 
)

Pop an element off the stack of open elements.

Parameters
treebuilderThe treebuilder instance containing the stack
nsPointer to location to receive element namespace
typePointer to location to receive element type
nodePointer to location to receive node
Returns
HUBBUB_OK on success, appropriate error otherwise.
Todo:
Can we optimise this? (i.e. by not traversing the entire list)
Todo:
reduce allocated stack size once there's enough free

◆ element_stack_pop_until()

hubbub_error element_stack_pop_until ( hubbub_treebuilder treebuilder,
element_type  type 
)

Pop elements until an element of type "element" has been popped.

Returns
HUBBUB_OK on success, appropriate error otherwise.

◆ element_stack_push()

hubbub_error element_stack_push ( hubbub_treebuilder treebuilder,
hubbub_ns  ns,
element_type  type,
void *  node 
)

Push an element onto the stack of open elements.

Parameters
treebuilderThe treebuilder instance containing the stack
nsThe namespace of element being pushed
typeThe type of element being pushed
nodeThe node to push
Returns
HUBBUB_OK on success, appropriate error otherwise.

◆ element_stack_remove()

hubbub_error element_stack_remove ( hubbub_treebuilder treebuilder,
uint32_t  index,
hubbub_ns ns,
element_type type,
void **  removed 
)

Remove a node from the stack of open elements.

Parameters
treebuilderThe treebuilder instance
indexThe index of the node to remove
nsPointer to location to receive namespace
typePointer to location to receive type
removedPointer to location to receive removed node
Returns
HUBBUB_OK on success, appropriate error otherwise.

◆ formatting_list_append()

hubbub_error formatting_list_append ( hubbub_treebuilder treebuilder,
hubbub_ns  ns,
element_type  type,
void *  node,
uint32_t  stack_index 
)

Append an element to the end of the list of active formatting elements.

Parameters
treebuilderTreebuilder instance containing list
nsNamespace of node being inserted
typeType of node being inserted
nodeNode being inserted
stack_indexIndex into stack of open elements
Returns
HUBBUB_OK on success, appropriate error otherwise

◆ formatting_list_dump()

void formatting_list_dump ( hubbub_treebuilder treebuilder,
FILE *  fp 
)

Dump a formatting list to the given file pointer.

Parameters
treebuilderThe treebuilder instance
fpThe file to dump to

◆ formatting_list_insert()

hubbub_error formatting_list_insert ( hubbub_treebuilder treebuilder,
formatting_list_entry prev,
formatting_list_entry next,
hubbub_ns  ns,
element_type  type,
void *  node,
uint32_t  stack_index 
)

Insert an element into the list of active formatting elements.

Parameters
treebuilderTreebuilder instance containing list
prevPrevious entry
nextNext entry
nsNamespace of node being inserted
typeType of node being inserted
nodeNode being inserted
stack_indexIndex into stack of open elements
Returns
HUBBUB_OK on success, appropriate error otherwise

◆ formatting_list_remove()

hubbub_error formatting_list_remove ( hubbub_treebuilder treebuilder,
formatting_list_entry entry,
hubbub_ns ns,
element_type type,
void **  node,
uint32_t *  stack_index 
)

Remove an element from the list of active formatting elements.

Parameters
treebuilderTreebuilder instance containing list
entryThe item to remove
nsPointer to location to receive namespace of node
typePointer to location to receive type of node
nodePointer to location to receive node
stack_indexPointer to location to receive stack index
Returns
HUBBUB_OK on success, appropriate error otherwise.

◆ formatting_list_replace()

hubbub_error formatting_list_replace ( hubbub_treebuilder treebuilder,
formatting_list_entry entry,
hubbub_ns  ns,
element_type  type,
void *  node,
uint32_t  stack_index,
hubbub_ns ons,
element_type otype,
void **  onode,
uint32_t *  ostack_index 
)

Remove an element from the list of active formatting elements.

Parameters
treebuilderTreebuilder instance containing list
entryThe item to replace
nsReplacement node namespace
typeReplacement node type
nodeReplacement node
stack_indexReplacement stack index
onsPointer to location to receive old namespace
otypePointer to location to receive old type
onodePointer to location to receive old node
ostack_indexPointer to location to receive old stack index
Returns
HUBBUB_OK on success, appropriate error otherwise

◆ hubbub_treebuilder_create()

hubbub_error hubbub_treebuilder_create ( hubbub_tokeniser tokeniser,
hubbub_treebuilder **  treebuilder 
)

Create a hubbub treebuilder.

Parameters
tokeniserUnderlying tokeniser instance
treebuilderPointer to location to receive treebuilder instance
Returns
HUBBUB_OK on success, HUBBUB_BADPARM on bad parameters HUBBUB_NOMEM on memory exhaustion

◆ hubbub_treebuilder_destroy()

hubbub_error hubbub_treebuilder_destroy ( hubbub_treebuilder treebuilder)

Destroy a hubbub treebuilder.

Parameters
treebuilderThe treebuilder instance to destroy
Returns
HUBBUB_OK on success, appropriate error otherwise

◆ hubbub_treebuilder_setopt()

hubbub_error hubbub_treebuilder_setopt ( hubbub_treebuilder treebuilder,
hubbub_treebuilder_opttype  type,
hubbub_treebuilder_optparams params 
)

Configure a hubbub treebuilder.

Parameters
treebuilderThe treebuilder instance to configure
typeThe option type to configure
paramsPointer to option-specific parameters
Returns
HUBBUB_OK on success, appropriate error otherwise.

◆ hubbub_treebuilder_token_handler()

hubbub_error hubbub_treebuilder_token_handler ( const hubbub_token token,
void *  pw 
)

Handle tokeniser emitting a token.

Parameters
tokenThe emitted token
pwPointer to treebuilder instance

◆ insert_element()

hubbub_error insert_element ( hubbub_treebuilder treebuilder,
const hubbub_tag tag,
bool  push 
)

Create element and insert it into the DOM, potentially pushing it on the stack.

Parameters
treebuilderThe treebuilder instance
tagThe element to insert
pushWhether to push the element onto the stack
Returns
HUBBUB_OK on success, appropriate error otherwise.

◆ is_formatting_element()

bool is_formatting_element ( element_type  type)

Determine if a node is a formatting element.

Parameters
typeNode type to consider
Returns
True iff node is a formatting element

◆ is_phrasing_element()

bool is_phrasing_element ( element_type  type)

Determine if a node is a phrasing element.

Parameters
typeNode type to consider
Returns
True iff node is a phrasing element

◆ is_scoping_element()

bool is_scoping_element ( element_type  type)

Determine if a node is a scoping element.

Parameters
typeNode type to consider
Returns
True iff node is a scoping element

◆ is_special_element()

bool is_special_element ( element_type  type)

Determine if a node is a special element.

Parameters
typeNode type to consider
Returns
True iff node is a special element

◆ parse_generic_rcdata()

hubbub_error parse_generic_rcdata ( hubbub_treebuilder treebuilder,
const hubbub_token token,
bool  rcdata 
)

Trigger parsing of generic (R)CDATA.

Parameters
treebuilderThe treebuilder instance
tokenThe current token
rcdataTrue for RCDATA, false for CDATA
Returns
HUBBUB_OK on success, appropriate error otherwise

◆ prev_node()

element_type prev_node ( hubbub_treebuilder treebuilder)

Peek at the element below the top of the element stack.

Parameters
treebuilderTreebuilder instance
Returns
Element type of the element one below the top of the stack

◆ process_characters_expect_whitespace()

hubbub_error process_characters_expect_whitespace ( hubbub_treebuilder treebuilder,
const hubbub_token token,
bool  insert_into_current_node 
)

Process a character token in cases where we expect only whitespace.

Parameters
treebuilderThe treebuilder instance
tokenThe character token
insert_into_current_nodeWhether to insert whitespace into current node
Returns
HUBBUB_REPROCESS if the token needs reprocessing (token data updated to skip any leading whitespace), HUBBUB_OK if it contained only whitespace, appropriate error otherwise

◆ process_comment_append()

hubbub_error process_comment_append ( hubbub_treebuilder treebuilder,
const hubbub_token token,
void *  parent 
)

Process a comment token, appending it to the given parent.

Parameters
treebuilderThe treebuilder instance
tokenThe comment token
parentThe node to append to
Returns
HUBBUB_OK on success, appropriate error otherwise

◆ reconstruct_active_formatting_list()

hubbub_error reconstruct_active_formatting_list ( hubbub_treebuilder treebuilder)

Reconstruct the list of active formatting elements.

Parameters
treebuilderTreebuilder instance containing list
Returns
HUBBUB_OK on success, appropriate error otherwise.

◆ remove_node_from_dom()

hubbub_error remove_node_from_dom ( hubbub_treebuilder treebuilder,
void *  node 
)

Remove a node from the DOM.

Parameters
treebuilderTreebuilder instance
nodeNode to remove
Returns
HUBBUB_OK on success, appropriate error otherwise.

◆ reset_insertion_mode()

void reset_insertion_mode ( hubbub_treebuilder treebuilder)

Reset the insertion mode.

Parameters
treebuilderThe treebuilder to reset
Todo:
fragment parsing algorithm