NeoMutt  2025-12-11-58-g09398d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
parse.c
Go to the documentation of this file.
1
23
29
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 node = node_expando_parse_name(str, defs, EP_NO_FLAGS, parsed_until, err);
67 if (node)
68 return node;
69
70 return node_expando_parse(str, defs, EP_NO_FLAGS, parsed_until, err);
71}
72
83bool node_parse_many(struct ExpandoNode *node_cont, const char *str,
84 NodeTextTermFlags term_chars, const struct ExpandoDefinition *defs,
85 const char **parsed_until, struct ExpandoParseError *err)
86{
87 if (!node_cont || !str || !parsed_until || !err)
88 return false;
89
90 while (*str)
91 {
92 if ((str[0] == '&') && (term_chars & NTE_AMPERSAND))
93 break;
94
95 if ((str[0] == '>') && (term_chars & NTE_GREATER))
96 break;
97
98 if ((str[0] == '?') && (term_chars & NTE_QUESTION))
99 break;
100
101 struct ExpandoNode *node = node_parse_one(str, term_chars, defs, parsed_until, err);
102 if (!node)
103 return false;
104
105 node_add_child(node_cont, node);
106 str = *parsed_until;
107 }
108
109 *parsed_until = str;
110 return true;
111}
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:83
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.
struct ExpandoNode * node_expando_parse_name(const char *str, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
Parse an Expando format string.
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:43
Basic Expando Node.
Definition node.h:67
Buffer for parsing errors.
Definition parse.h:37