NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
parse.h File Reference

Expando Parsing. More...

#include <stdbool.h>
#include "node_text.h"
+ Include dependency graph for parse.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ExpandoParseError
 Buffer for parsing errors. More...
 

Functions

struct ExpandoNodenode_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.
 
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.
 

Detailed Description

Expando Parsing.

Authors
  • Tóth János
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file parse.h.

Function Documentation

◆ node_parse_one()

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.

Parameters
[in]strString to parse
[in]term_charsTerminator characters, e.g. NTE_GREATER
[in]defsExpando definitions
[out]parsed_untilFirst character after parsed string
[out]errBuffer for errors
Return values
ptrExpando Node

Definition at line 49 of file parse.c.

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}
#define EP_NO_FLAGS
No flags are set.
Definition: definition.h:34
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.
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
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
Basic Expando Node.
Definition: node.h:67
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ node_parse_many()

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.

Parameters
[in]node_contContainer for the results
[in]strString to parse
[in]term_charsTerminator characters, e.g. NTE_GREATER
[in]defsExpando definitions
[out]parsed_untilFirst character after parsed string
[out]errBuffer for errors
Return values
trueSuccess

Definition at line 81 of file parse.c.

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}
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
void node_add_child(struct ExpandoNode *node, struct ExpandoNode *child)
Add a child to an ExpandoNode.
Definition: node.c:76
#define NTE_QUESTION
'?' Question mark
Definition: node_text.h:36
#define NTE_GREATER
'>' Greater than
Definition: node_text.h:35
#define NTE_AMPERSAND
'&' Ampersand
Definition: node_text.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function: