NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
parse.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stdbool.h>
32#include <stdio.h>
33#include "parse.h"
34#include "definition.h"
35#include "node.h"
36#include "node_condition.h"
37#include "node_expando.h"
38#include "node_text.h"
39
49struct ExpandoNode *node_parse_one(const char *str, NodeTextTermFlags term_chars,
50 const struct ExpandoDefinition *defs,
51 const char **parsed_until, struct ExpandoParseError *err)
52{
53 if (!str || (*str == '\0') || !defs || !parsed_until || !err)
54 return NULL;
55
56 struct ExpandoNode *node = NULL;
57
58 node = node_text_parse(str, term_chars, parsed_until);
59 if (node)
60 return node;
61
62 node = node_condition_parse(str, term_chars, defs, parsed_until, err);
63 if (node)
64 return node;
65
66 // TODO parser for %{name}
67
68 return node_expando_parse(str, defs, EP_NO_FLAGS, parsed_until, err);
69}
70
81bool node_parse_many(struct ExpandoNode *node_cont, const char *str,
82 NodeTextTermFlags term_chars, const struct ExpandoDefinition *defs,
83 const char **parsed_until, struct ExpandoParseError *err)
84{
85 if (!node_cont || !str || !parsed_until || !err)
86 return false;
87
88 while (*str)
89 {
90 if ((str[0] == '&') && (term_chars & NTE_AMPERSAND))
91 break;
92
93 if ((str[0] == '>') && (term_chars & NTE_GREATER))
94 break;
95
96 if ((str[0] == '?') && (term_chars & NTE_QUESTION))
97 break;
98
99 struct ExpandoNode *node = node_parse_one(str, term_chars, defs, parsed_until, err);
100 if (!node)
101 return false;
102
103 node_add_child(node_cont, node);
104 str = *parsed_until;
105 }
106
107 *parsed_until = str;
108 return true;
109}
Define an Expando format string.
#define EP_NO_FLAGS
No flags are set.
Definition: definition.h:34
struct ExpandoNode * node_parse_one(const char *str, NodeTextTermFlags term_chars, const struct ExpandoDefinition *defs, const char **parsed_until, struct ExpandoParseError *err)
Parse a single Expando from a format string.
Definition: parse.c:49
bool node_parse_many(struct ExpandoNode *node_cont, const char *str, NodeTextTermFlags term_chars, const struct ExpandoDefinition *defs, const char **parsed_until, struct ExpandoParseError *err)
Parse a format string.
Definition: parse.c:81
Expando Parsing.
void node_add_child(struct ExpandoNode *node, struct ExpandoNode *child)
Add a child to an ExpandoNode.
Definition: node.c:76
Basic Expando Node.
struct ExpandoNode * node_condition_parse(const char *str, NodeTextTermFlags term_chars, const struct ExpandoDefinition *defs, const char **parsed_until, struct ExpandoParseError *err)
Parse a conditional Expando.
Expando Node for a Condition.
struct ExpandoNode * node_expando_parse(const char *str, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
Parse an Expando format string.
Definition: node_expando.c:284
Expando Node for an Expando.
struct ExpandoNode * node_text_parse(const char *str, NodeTextTermFlags term_chars, const char **parsed_until)
Extract a block of text.
Definition: node_text.c:86
Expando Node for Text.
#define NTE_QUESTION
'?' Question mark
Definition: node_text.h:36
#define NTE_GREATER
'>' Greater than
Definition: node_text.h:35
uint8_t NodeTextTermFlags
Special characters that end a text string.
Definition: node_text.h:32
#define NTE_AMPERSAND
'&' Ampersand
Definition: node_text.h:34
Definition of a format string.
Definition: definition.h:44
Basic Expando Node.
Definition: node.h:67
Buffer for parsing errors.
Definition: parse.h:37