/// open a pair. This allows for complex behavior without having to bog down the tokenizer
/// with figuring out which type of asterisk we have. Default behavior is that open and close
/// are enabled, so we just have to figure out when to turn it off.
-void mmd_assign_ambidextrous_tokens_in_block(mmd_engine * e, token * block, const char * str, size_t start_offset) {
+void mmd_assign_ambidextrous_tokens_in_block(mmd_engine * e, token * block, size_t start_offset) {
if (block == NULL || block->child == NULL)
return;
token * t = block->child;
+ char * str = e->dstr->str;
+
while (t != NULL) {
switch (t->type) {
case BLOCK_META:
case BLOCK_TABLE:
case BLOCK_TERM:
// Assign child tokens of blocks
- mmd_assign_ambidextrous_tokens_in_block(e, t, str, start_offset);
+ mmd_assign_ambidextrous_tokens_in_block(e, t, start_offset);
break;
case CRITIC_SUB_DIV:
// Divide this into two tokens
/// Parse part of the string into a token tree
token * mmd_engine_parse_substring(mmd_engine * e, size_t byte_start, size_t byte_len) {
+ // Free existing parse tree
+ if (e->root)
+ token_tree_free(e->root);
+
+ // New parse tree
// Reset definition stack
e->definition_stack->size = 0;
if (doc) {
// Parse blocks for pairs
- mmd_assign_ambidextrous_tokens_in_block(e, doc, e->dstr->str, 0);
+ mmd_assign_ambidextrous_tokens_in_block(e, doc, 0);
// Prepare stack to be used for token pairing
// This avoids allocating/freeing one for each iteration.
/// Parse the entire string into a token tree
void mmd_engine_parse_string(mmd_engine * e) {
- // Free existing parse tree
- if (e->root)
- token_tree_free(e->root);
-
- // New parse tree
e->root = mmd_engine_parse_substring(e, 0, e->dstr->currentStringLength);
}