aboutsummaryrefslogtreecommitdiff
path: root/src/wmap_parser.h
blob: fa4371b671e7e065085461dcf17c3b60dbe9cad1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#ifndef WMAP_PARSER_H
#define WMAP_PARSER_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define WMAP_MAX_NAME_LEN 64
#define WMAP_MAX_TEXT_LEN 256
#define WMAP_MAX_COMPONENTS 1024
#define WMAP_MAX_DEPENDENCIES 2048
#define WMAP_MAX_NOTES 256
#define WMAP_MAX_STAGES 4
#define WMAP_MAX_GROUPS 128
#define WMAP_MAX_GROUP_MEMBERS 32
#define WMAP_MAX_INERTIAS 256
#define WMAP_MAX_EVOLUTIONS 256

#ifdef __mc68000__
#define WMAP_68K_INLINE static
#define WMAP_68K_FAST_CALL __attribute__((regparm(2)))
#else
#define WMAP_68K_INLINE static
#define WMAP_68K_FAST_CALL
#endif

/* Public Types */

typedef enum {
    WMAP_SHAPE_NONE = 0,
    WMAP_SHAPE_X,
    WMAP_SHAPE_SQUARE,
    WMAP_SHAPE_TRIANGLE,
    WMAP_SHAPE_CIRCLE
} wmap_shape_t;

typedef enum {
    WMAP_STAGE_I = 1,
    WMAP_STAGE_II = 2,
    WMAP_STAGE_III = 3,
    WMAP_STAGE_IV = 4
} wmap_stage_t;

typedef struct {
    char name[WMAP_MAX_NAME_LEN];
    float x, y;
    wmap_shape_t shape;
} wmap_component_t;

typedef struct {
    char from[WMAP_MAX_NAME_LEN];
    char to[WMAP_MAX_NAME_LEN];
    int is_arrow;
} wmap_dependency_t;

typedef struct {
    float x, y;
    char text[WMAP_MAX_TEXT_LEN];
} wmap_note_t;

typedef struct {
    wmap_stage_t stage;
    float value;
} wmap_stage_data_t;

typedef struct {
    char members[WMAP_MAX_GROUP_MEMBERS][WMAP_MAX_NAME_LEN];
    int member_count;
} wmap_group_t;

typedef struct {
    char name[WMAP_MAX_NAME_LEN];
} wmap_inertia_t;

typedef struct {
    char name[WMAP_MAX_NAME_LEN];
    float change;
} wmap_evolution_t;

typedef struct {
    wmap_component_t components[WMAP_MAX_COMPONENTS];
    wmap_dependency_t dependencies[WMAP_MAX_DEPENDENCIES];
    wmap_note_t notes[WMAP_MAX_NOTES];
    wmap_stage_data_t stages[WMAP_MAX_STAGES];
    wmap_group_t groups[WMAP_MAX_GROUPS];
    wmap_inertia_t inertias[WMAP_MAX_INERTIAS];
    wmap_evolution_t evolutions[WMAP_MAX_EVOLUTIONS];

    int component_count;
    int dependency_count;
    int note_count;
    int stage_count;
    int group_count;
    int inertia_count;
    int evolution_count;
} wmap_map_t;

/* Internal Types (needed for implementation) */

typedef enum {
    WMAP_TOKEN_EOF = 0,
    WMAP_TOKEN_IDENTIFIER,
    WMAP_TOKEN_NUMBER,
    WMAP_TOKEN_LPAREN,
    WMAP_TOKEN_RPAREN,
    WMAP_TOKEN_LBRACKET,
    WMAP_TOKEN_RBRACKET,
    WMAP_TOKEN_COMMA,
    WMAP_TOKEN_ARROW,
    WMAP_TOKEN_DASH,
    WMAP_TOKEN_PLUS,
    WMAP_TOKEN_MINUS,
    WMAP_TOKEN_NEWLINE,
    WMAP_TOKEN_ERROR
} wmap_token_type_t;

typedef struct {
    const char* input;
    int pos;
    int line;
    int col;
    wmap_token_type_t current_token;
    char token_text[WMAP_MAX_NAME_LEN];
    float token_number;
} wmap_lexer_t;

typedef struct {
    wmap_lexer_t lexer;
    wmap_map_t* map;
    int error_count;
} wmap_parser_t;

/* Public API */

/**
 * Parse WMAP content from a string
 * @param input The WMAP content as a null-terminated string
 * @return Pointer to parsed map structure, or NULL on failure
 */
wmap_map_t* wmap_parse_string(const char* input);

/**
 * Parse WMAP content from a file
 * @param filename Path to the WMAP file
 * @return Pointer to parsed map structure, or NULL on failure
 */
wmap_map_t* wmap_parse_file(const char* filename);

/**
 * Free memory allocated for a parsed map
 * @param map Pointer to the map structure to free
 */
void wmap_map_free(wmap_map_t* map);

/**
 * Validate input size and format before parsing
 * @param input The input string to validate
 * @param max_size Maximum allowed size in bytes
 * @return 1 if valid, 0 if invalid
 */
int wmap_validate_input(const char* input, size_t max_size);

#endif