8 /* Include collection library headers */
9 #include <derp/common.h>
10 #include <derp/vector.h>
12 /* Forward declarations */
13 typedef struct ical_parser ical_parser_t;
14 typedef struct ical_property ical_property_t;
15 typedef struct ical_parameter ical_parameter_t;
16 typedef struct ical_component ical_component_t;
21 ICAL_ERROR_MEMORY = -1,
22 ICAL_ERROR_PARSE = -2,
23 ICAL_ERROR_INVALID_PARAMETER = -3,
27 /* Error information structure */
29 const char *message; /* Error message (valid until next parse operation) */
30 int line; /* Line number where error occurred (1-based, 0 if unknown) */
31 int column; /* Column number where error occurred (1-based, 0 if unknown) */
32 bool has_location; /* Whether line/column information is available */
35 /* iCalendar parameter structure */
36 struct ical_parameter {
37 char *name; /* Parameter name (uppercase) */
38 char *value; /* Parameter value */
41 /* iCalendar property structure */
42 struct ical_property {
43 char *name; /* Property name (uppercase) */
44 vector *parameters; /* Vector of ical_parameter_t* */
45 char *value; /* Property value */
48 /* iCalendar component structure */
49 struct ical_component {
50 char *type; /* Component type (uppercase, e.g., "VCALENDAR", "VEVENT") */
51 vector *properties; /* Vector of ical_property_t* */
52 vector *subcomponents; /* Vector of ical_component_t* (nested components) */
55 /* Parser (opaque, stateful - maintains error state between operations) */
59 * Create a new iCalendar parser
60 * @note Parser maintains error state; create separate parsers for concurrent use
62 ical_parser_t *ical_parser_create(void);
65 * Free an iCalendar parser and all associated memory
67 void ical_parser_destroy(ical_parser_t *parser);
70 * Parse iCalendar data from a string
71 * @note Sets *calendar to NULL on failure
72 * @return ical_component_t* representing the VCALENDAR on success, NULL on failure
74 ical_error_t ical_parser_parse_string(ical_parser_t *parser, const char *input, ical_component_t **calendar);
77 * Parse iCalendar data from a file
78 * @note Sets *calendar to NULL on failure
79 * @note Advances file position to end of parsed content
80 * @return ical_component_t* representing the VCALENDAR on success, NULL on failure
82 ical_error_t ical_parser_parse_file(ical_parser_t *parser, FILE *file, ical_component_t **calendar);
85 * Get detailed error information from the parser
86 * @note Message pointer is valid until the next parse operation
88 ical_error_info_t ical_parser_get_error_info(ical_parser_t *parser);
91 * Convert error code to human-readable string
93 const char *ical_error_string(ical_error_t error);
96 * Free an iCalendar component and all its associated memory
98 void ical_component_free(ical_component_t *component);
101 * Free an iCalendar property and all its associated memory
103 void ical_property_free(ical_property_t *property);
106 * Free an iCalendar parameter and all its associated memory
108 void ical_parameter_free(ical_parameter_t *parameter);
110 #endif /* ICAL_PARSER_H */