56 if ((ctr == 0) && (((*start == end_terminator) && (prev !=
'%')) || (*start ==
'&')))
62 if ((prev ==
'%') && (*start ==
'<'))
67 if ((*start ==
'>') && (prev !=
'%'))
91 if ((ctr == 0) && (*start == end_terminator) && (prev !=
'%'))
97 if ((prev ==
'%') && (*start ==
'<'))
102 if ((*start ==
'>') && (prev !=
'%'))
126 const char **parsed_until,
130 if (!str || (*str ==
'\0'))
133 while (*str && (end ? (str <= end) :
true))
138 ((condition_start ==
CON_START) && ((*str ==
'?') || (*str ==
'<'))))
145 *parsed_until = str + 1;
149 else if ((*str ==
'?') || (*str ==
'<'))
151 bool old_style = (*str ==
'?');
152 char end_terminator = old_style ?
'?' :
'>';
155 const char *next = NULL;
167 _(
"Conditional expando is missing '%c'"),
'?');
174 const char *start_true = str;
177 bool only_true = (*end_true == end_terminator);
178 bool invalid = ((*end_true !=
'&') && !only_true);
186 _(
"Conditional expando is missing '&' or '%c'"), end_terminator);
191 const char *if_true_parsed = NULL;
194 while (start_true < end_true)
197 &if_true_parsed, defs, err);
207 start_true = if_true_parsed;
212 *parsed_until = end_true + 1;
217 const char *start_false = end_true + 1;
221 if (*end_false != end_terminator)
227 _(
"Conditional expando is missing '%c'"), end_terminator);
233 const char *if_false_parsed = NULL;
236 while (start_false < end_false)
239 &if_false_parsed, defs, err);
250 start_false = if_false_parsed;
253 *parsed_until = end_false + 1;
285 ASSERT(
false &&
"Internal parsing error");
Define an Expando format string.
#define EP_NO_FLAGS
No flags are set.
uint8_t ExpandoParserFlags
Flags for expando_parse(), e.g. EP_CONDITIONAL.
#define EP_CONDITIONAL
Expando is being used as a condition.
const char * skip_until_ch(const char *start, char terminator)
Search a string for a terminator character.
static const char * skip_until_if_true_end(const char *start, char end_terminator)
Search for the end of an 'if true' condition.
static const char * skip_until_if_false_end(const char *start, char end_terminator)
Search for the end of an 'if false' condition.
struct ExpandoNode * node_parse(const char *str, const char *end, enum ExpandoConditionStart condition_start, const char **parsed_until, const struct ExpandoDefinition *defs, struct ExpandoParseError *err)
Parse a format string into ExpandoNodes.
struct ExpandoNode * node_condbool_parse(const char *str, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, const char **parsed_until, struct ExpandoParseError *err)
Parse a CondBool format string - Implements ExpandoDefinition::parse() -.
Convenience wrapper for the library headers.
void node_add_child(struct ExpandoNode *node, struct ExpandoNode *child)
Add a child to an ExpandoNode.
void node_free(struct ExpandoNode **ptr)
Free an ExpandoNode and its private data.
Expando Node for a Conditional Boolean.
struct ExpandoNode * node_condition_new(struct ExpandoNode *condition, struct ExpandoNode *node_true, struct ExpandoNode *node_false)
Create a new Condition Expando Node.
Expando Node for a Condition.
ExpandoConditionStart
Signals node_parse() if the parsing started in a conditional statement or not.
@ CON_NO_CONDITION
Parser is not currently in a condition.
@ CON_START
Parser is working on a condition.
struct ExpandoNode * node_container_new(void)
Create a new Container ExpandoNode.
Expando Node for a Container.
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.
Expando Node for an Expando.
struct ExpandoNode * node_text_new(const char *start, const char *end)
Create a new Text ExpandoNode.
struct ExpandoNode * node_text_parse(const char *str, const char *end, const char **parsed_until)
Extract a block of text.
Definition of a format string.
Buffer for parsing errors.
const char * position
Position of error in original string.
char message[256]
Error message.