From 463d64219b2f47c9bfb50d05a7f4d2b2a4293a97 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Mon, 17 Nov 2014 21:04:42 +0100 Subject: Switch cmark_node_inl over to cmark_node --- src/inlines.c | 75 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 37 deletions(-) (limited to 'src/inlines.c') diff --git a/src/inlines.c b/src/inlines.c index e3d71f7..313dfe5 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -4,6 +4,7 @@ #include #include "config.h" +#include "node.h" #include "ast.h" #include "references.h" #include "cmark.h" @@ -16,7 +17,7 @@ typedef struct DelimiterStack { struct DelimiterStack *previous; struct DelimiterStack *next; - node_inl *first_inline; + cmark_node *first_inline; int delim_count; unsigned char delim_char; int position; @@ -31,8 +32,8 @@ typedef struct Subject { delimiter_stack *delimiters; } subject; -static node_inl *parse_inlines_from_subject(subject* subj); -static int parse_inline(subject* subj, node_inl ** last); +static cmark_node *parse_inlines_from_subject(subject* subj); +static int parse_inline(subject* subj, cmark_node ** last); static void subject_from_buf(subject *e, strbuf *buffer, reference_map *refmap); static int subject_find_special_char(subject *subj); @@ -105,12 +106,12 @@ static inline chunk take_while(subject* subj, int (*f)(int)) // Append inline list b to the end of inline list a. // Return pointer to head of new list. -static inline cmark_node_inl* cmark_append_inlines(cmark_node_inl* a, cmark_node_inl* b) +static inline cmark_node* cmark_append_inlines(cmark_node* a, cmark_node* b) { if (a == NULL) { // NULL acts like an empty list return b; } - cmark_node_inl* cur = a; + cmark_node* cur = a; while (cur->next != NULL) { cur = cur->next; } @@ -146,7 +147,7 @@ static int scan_to_closing_backticks(subject* subj, int openticklength) // Parse backtick code section or raw backticks, return an inline. // Assumes that the subject has a backtick at the current position. -static node_inl* handle_backticks(subject *subj) +static cmark_node* handle_backticks(subject *subj) { chunk openticks = take_while(subj, isbacktick); int startpos = subj->pos; @@ -222,7 +223,7 @@ static delimiter_stack * push_delimiter(subject *subj, unsigned char c, bool can_open, bool can_close, - node_inl *inl_text) + cmark_node *inl_text) { delimiter_stack *istack = (delimiter_stack*)malloc(sizeof(delimiter_stack)); @@ -245,10 +246,10 @@ static delimiter_stack * push_delimiter(subject *subj, // Parse strong/emph or a fallback. // Assumes the subject has '_' or '*' at the current position. -static node_inl* handle_strong_emph(subject* subj, unsigned char c, node_inl **last) +static cmark_node* handle_strong_emph(subject* subj, unsigned char c, cmark_node **last) { int numdelims; - node_inl * inl_text; + cmark_node * inl_text; bool can_open, can_close; numdelims = scan_delims(subj, c, &can_open, &can_close); @@ -268,7 +269,7 @@ static void process_emphasis(subject *subj, delimiter_stack *stack_bottom) delimiter_stack *closer = subj->delimiters; delimiter_stack *opener, *tempstack, *nextstack; int use_delims; - node_inl *inl, *tmp, *emph; + cmark_node *inl, *tmp, *emph; // move back to first relevant delim. while (closer != NULL && closer->previous != stack_bottom) { @@ -302,8 +303,8 @@ static void process_emphasis(subject *subj, delimiter_stack *stack_bottom) // remove used delimiters from stack elements and associated inlines. opener->delim_count -= use_delims; closer->delim_count -= use_delims; - inl->content.literal.len = opener->delim_count; - closer->first_inline->content.literal.len = closer->delim_count; + inl->as.literal.len = opener->delim_count; + closer->first_inline->as.literal.len = closer->delim_count; // free delimiters between opener and closer tempstack = closer->previous; @@ -318,7 +319,7 @@ static void process_emphasis(subject *subj, delimiter_stack *stack_bottom) emph = use_delims == 1 ? make_emph(inl->next) : make_strong(inl->next); emph->next = closer->first_inline; inl->next = emph; - tmp = emph->content.inlines; + tmp = emph->first_child; while (tmp->next != NULL && tmp->next != closer->first_inline) { tmp = tmp->next; } @@ -327,10 +328,10 @@ static void process_emphasis(subject *subj, delimiter_stack *stack_bottom) // if opener has 0 delims, remove it and its associated inline if (opener->delim_count == 0) { // replace empty opener inline with emph - chunk_free(&(inl->content.literal)); - inl->tag = emph->tag; + chunk_free(&(inl->as.literal)); + inl->type = emph->type; inl->next = emph->next; - inl->content.inlines = emph->content.inlines; + inl->first_child = emph->first_child; free(emph); emph = inl; // remove opener from stack @@ -343,7 +344,7 @@ static void process_emphasis(subject *subj, delimiter_stack *stack_bottom) tmp = closer->first_inline; emph->next = tmp->next; tmp->next = NULL; - cmark_free_inlines(tmp); + cmark_free_nodes(tmp); // remove closer from stack tempstack = closer->next; remove_delimiter(subj, closer); @@ -363,7 +364,7 @@ static void process_emphasis(subject *subj, delimiter_stack *stack_bottom) } // Parse backslash-escape or just a backslash, returning an inline. -static node_inl* handle_backslash(subject *subj) +static cmark_node* handle_backslash(subject *subj) { advance(subj); unsigned char nextchar = peek_char(subj); @@ -380,7 +381,7 @@ static node_inl* handle_backslash(subject *subj) // Parse an entity or a regular "&" string. // Assumes the subject has an '&' character at the current position. -static node_inl* handle_entity(subject* subj) +static cmark_node* handle_entity(subject* subj) { strbuf ent = GH_BUF_INIT; size_t len; @@ -401,7 +402,7 @@ static node_inl* handle_entity(subject* subj) // Like make_str, but parses entities. // Returns an inline sequence consisting of str and entity elements. -static node_inl *make_str_with_entities(chunk *content) +static cmark_node *make_str_with_entities(chunk *content) { strbuf unescaped = GH_BUF_INIT; @@ -459,7 +460,7 @@ unsigned char *clean_title(chunk *title) // Parse an autolink or HTML tag. // Assumes the subject has a '<' character at the current position. -static node_inl* handle_pointy_brace(subject* subj) +static cmark_node* handle_pointy_brace(subject* subj) { int matchlen = 0; chunk contents; @@ -543,7 +544,7 @@ static int link_label(subject* subj, chunk *raw_label) } // Return a link, an image, or a literal close bracket. -static node_inl* handle_close_bracket(subject* subj, node_inl **last) +static cmark_node* handle_close_bracket(subject* subj, cmark_node **last) { int initial_pos; int starturl, endurl, starttitle, endtitle, endall; @@ -555,8 +556,8 @@ static node_inl* handle_close_bracket(subject* subj, node_inl **last) unsigned char *url, *title; delimiter_stack *opener; delimiter_stack *tempstack; - node_inl *link_text; - node_inl *inl; + cmark_node *link_text; + cmark_node *inl; chunk raw_label; advance(subj); // advance past ] @@ -642,12 +643,12 @@ noMatch: match: inl = opener->first_inline; - inl->tag = is_image ? INL_IMAGE : INL_LINK; - chunk_free(&inl->content.literal); - inl->content.linkable.label = link_text; + inl->type = is_image ? NODE_IMAGE : NODE_LINK; + chunk_free(&inl->as.literal); + inl->as.link.label = link_text; process_emphasis(subj, opener->previous); - inl->content.linkable.url = url; - inl->content.linkable.title = title; + inl->as.link.url = url; + inl->as.link.title = title; inl->next = NULL; *last = inl; @@ -671,7 +672,7 @@ match: // Parse a hard or soft linebreak, returning an inline. // Assumes the subject has a newline at the current position. -static node_inl* handle_newline(subject *subj) +static cmark_node* handle_newline(subject *subj) { int nlpos = subj->pos; // skip over newline @@ -690,11 +691,11 @@ static node_inl* handle_newline(subject *subj) } // Parse inlines til end of subject, returning inlines. -extern node_inl* parse_inlines_from_subject(subject* subj) +extern cmark_node* parse_inlines_from_subject(subject* subj) { - node_inl* result = NULL; - node_inl** last = &result; - node_inl* first = NULL; + cmark_node* result = NULL; + cmark_node** last = &result; + cmark_node* first = NULL; while (!is_eof(subj) && parse_inline(subj, last)) { if (!first) { first = *last; @@ -741,9 +742,9 @@ static int subject_find_special_char(subject *subj) // Parse an inline, advancing subject, and add it to last element. // Adjust tail to point to new last element of list. // Return 0 if no inline can be parsed, 1 otherwise. -static int parse_inline(subject* subj, node_inl ** last) +static int parse_inline(subject* subj, cmark_node ** last) { - node_inl* new_inl = NULL; + cmark_node* new_inl = NULL; chunk contents; unsigned char c; int endpos; @@ -811,7 +812,7 @@ static int parse_inline(subject* subj, node_inl ** last) return 1; } -extern node_inl* parse_inlines(strbuf *input, reference_map *refmap) +extern cmark_node* parse_inlines(strbuf *input, reference_map *refmap) { subject subj; subject_from_buf(&subj, input, refmap); -- cgit v1.2.3