-
Notifications
You must be signed in to change notification settings - Fork 139
/
utility_functions.h
74 lines (51 loc) · 2.68 KB
/
utility_functions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef UTILITY_FUNCTIONS_H
#define UTILITY_FUNCTIONS_H
#include <stdbool.h>
#include <glib.h>
#include "markdown_peg.h"
/* utility_functions.h - List manipulation functions, element
* constructors, and macro definitions for leg markdown parser. */
/* cons - cons an element onto a list, returning pointer to new head */
element * cons(element *new, element *list);
/* reverse - reverse a list, returning pointer to new list */
element *reverse(element *list);
/* concat_string_list - concatenates string contents of list of STR elements.
* Frees STR elements as they are added to the concatenation. */
GString *concat_string_list(element *list);
/**********************************************************************
Global variables used in parsing
***********************************************************************/
extern char *charbuf; /* Buffer of characters to be parsed. */
extern element *references; /* List of link references found. */
extern element *notes; /* List of footnotes found. */
extern element *parse_result; /* Results of parse. */
extern int syntax_extensions; /* Syntax extensions selected. */
/**********************************************************************
Auxiliary functions for parsing actions.
These make it easier to build up data structures (including lists)
in the parsing actions.
***********************************************************************/
/* mk_element - generic constructor for element */
element * mk_element(int key);
/* mk_str - constructor for STR element */
element * mk_str(char *string);
/* mk_str_from_list - makes STR element by concatenating a
* reversed list of strings, adding optional extra newline */
element * mk_str_from_list(element *list, bool extra_newline);
/* mk_list - makes new list with key 'key' and children the reverse of 'lst'.
* This is designed to be used with cons to build lists in a parser action.
* The reversing is necessary because cons adds to the head of a list. */
element * mk_list(int key, element *lst);
/* mk_link - constructor for LINK element */
element * mk_link(element *label, char *url, char *title);
/* extension = returns true if extension is selected */
bool extension(int ext);
/* match_inlines - returns true if inline lists match (case-insensitive...) */
bool match_inlines(element *l1, element *l2);
/* find_reference - return true if link found in references matching label.
* 'link' is modified with the matching url and title. */
bool find_reference(link *result, element *label);
/* find_note - return true if note found in notes matching label.
if found, 'result' is set to point to matched note. */
bool find_note(element **result, char *label);
#endif