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 while (*str && (
end ? (str <=
end) : 1))
135 ((condition_start ==
CON_START) && ((*str ==
'?') || (*str ==
'<'))))
142 *parsed_until = str + 1;
146 else if ((*str ==
'?') || (*str ==
'<'))
148 bool old_style = (*str ==
'?');
149 char end_terminator = old_style ?
'?' :
'>';
152 const char *
next = NULL;
164 _(
"Conditional expando is missing '%c'"),
'?');
171 const char *start_true = str;
174 bool only_true = (*end_true == end_terminator);
175 bool invalid = ((*end_true !=
'&') && !only_true);
183 _(
"Conditional expando is missing '&' or '%c'"), end_terminator);
188 const char *if_true_parsed = NULL;
191 while (start_true < end_true)
194 &if_true_parsed, defs, error);
203 start_true = if_true_parsed;
206 if ((start_true == end_true) && !node_true)
213 *parsed_until = end_true + 1;
218 const char *start_false = end_true + 1;
222 if (*end_false != end_terminator)
228 _(
"Conditional expando is missing '%c'"), end_terminator);
234 const char *if_false_parsed = NULL;
237 while (start_false < end_false)
240 &if_false_parsed, defs, error);
250 start_false = if_false_parsed;
253 if ((start_false == end_false) && !node_false)
258 *parsed_until = end_false + 1;
290 ASSERT(
false &&
"Internal parsing error");
304 if (!
string || !*
string)
310 const char *
end = NULL;
311 const char *
start = string;
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.
void node_tree_parse(struct ExpandoNode **root, const char *string, const struct ExpandoDefinition *defs, struct ExpandoParseError *error)
Parse a format string into ExpandoNodes.
struct ExpandoNode * node_parse(const char *str, const char *end, enum ExpandoConditionStart condition_start, const char **parsed_until, const struct ExpandoDefinition *defs, struct ExpandoParseError *error)
Parse a format string into ExpandoNodes.
struct ExpandoNode * node_condbool_parse(const char *str, const char **parsed_until, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, struct ExpandoParseError *error)
Parse a CondBool format string - Implements ExpandoDefinition::parse() -.
Convenience wrapper for the library headers.
struct ExpandoNode * node_new(void)
Create a new empty ExpandoNode.
void node_append(struct ExpandoNode **root, struct ExpandoNode *new_node)
Append an ExpandoNode to an existing node.
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_expando_parse(const char *str, const char **parsed_until, const struct ExpandoDefinition *defs, ExpandoParserFlags flags, struct ExpandoParseError *error)
Parse an Expando format string.
Expando Node for an Expando.
void node_padding_repad(struct ExpandoNode **parent)
Rearrange Padding in a tree of ExpandoNodes.
Expando Node for Padding.
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.
const char * end
End of string data.
struct ExpandoNode * next
Linked list.
const char * start
Start of string data.
Buffer for parsing errors.
const char * position
Position of error in original string.
char message[256]
Error message.