Skip to content

Commit 512ec29

Browse files
committed
jimp: hide irrelevant things from the public API
1 parent 485d191 commit 512ec29

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

jimp.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "stb_c_lexer.h"
55

66
typedef struct {
7+
// TODO: get rid of the dependency on stb_c_lexer.h
78
stb_lexer l;
89
const char *file_path;
910
const char *member;
@@ -22,16 +23,15 @@ bool jimp_array_begin(Jimp *jimp);
2223
bool jimp_array_item(Jimp *jimp);
2324
bool jimp_array_end(Jimp *jimp);
2425

25-
// TODO: should be private
26-
bool jimp_expect_token(Jimp *jimp, long token);
27-
bool jimp_get_and_expect_token(Jimp *jimp, long token);
28-
const char *jimp_token_kind(long token);
29-
3026
#endif // JIMP_H_
3127

3228
#ifdef JIMP_IMPLEMENTATION
3329

34-
const char *jimp_token_kind(long token)
30+
static bool jimp__expect_token(Jimp *jimp, long token);
31+
static bool jimp__get_and_expect_token(Jimp *jimp, long token);
32+
static const char *jimp__token_kind(long token);
33+
34+
static const char *jimp__token_kind(long token)
3535
{
3636
switch (token) {
3737
case CLEX_id : return("identifier");
@@ -74,12 +74,12 @@ const char *jimp_token_kind(long token)
7474

7575
bool jimp_array_begin(Jimp *jimp)
7676
{
77-
return jimp_get_and_expect_token(jimp, '[');
77+
return jimp__get_and_expect_token(jimp, '[');
7878
}
7979

8080
bool jimp_array_end(Jimp *jimp)
8181
{
82-
return jimp_get_and_expect_token(jimp, ']');
82+
return jimp__get_and_expect_token(jimp, ']');
8383
}
8484

8585
bool jimp_array_item(Jimp *jimp)
@@ -104,52 +104,52 @@ void jimp_unknown_member(Jimp *jimp)
104104

105105
bool jimp_object_begin(Jimp *jimp)
106106
{
107-
return jimp_get_and_expect_token(jimp, '{');
107+
return jimp__get_and_expect_token(jimp, '{');
108108
}
109109

110110
bool jimp_object_member(Jimp *jimp)
111111
{
112112
char *point = jimp->l.parse_point;
113113
if (!stb_c_lexer_get_token(&jimp->l)) return false;
114114
if (jimp->l.token == ',') {
115-
if (!jimp_get_and_expect_token(jimp, CLEX_dqstring)) return false;
115+
if (!jimp__get_and_expect_token(jimp, CLEX_dqstring)) return false;
116116
jimp->member = strdup(jimp->l.string); // TODO: memory leak
117-
if (!jimp_get_and_expect_token(jimp, ':')) return false;
117+
if (!jimp__get_and_expect_token(jimp, ':')) return false;
118118
return true;
119119
}
120120
if (jimp->l.token == '}') {
121121
jimp->l.parse_point = point;
122122
return false;
123123
}
124-
if (!jimp_expect_token(jimp, CLEX_dqstring)) return false;
124+
if (!jimp__expect_token(jimp, CLEX_dqstring)) return false;
125125
jimp->member = strdup(jimp->l.string); // TODO: memory leak
126-
if (!jimp_get_and_expect_token(jimp, ':')) return false;
126+
if (!jimp__get_and_expect_token(jimp, ':')) return false;
127127
return true;
128128
}
129129

130130
bool jimp_object_end(Jimp *jimp)
131131
{
132-
return jimp_get_and_expect_token(jimp, '}');
132+
return jimp__get_and_expect_token(jimp, '}');
133133
}
134134

135135
bool jimp_string(Jimp *jimp, const char **string)
136136
{
137-
if (!jimp_get_and_expect_token(jimp, CLEX_dqstring)) return false;
137+
if (!jimp__get_and_expect_token(jimp, CLEX_dqstring)) return false;
138138
*string = strdup(jimp->l.string);
139139
return true;
140140
}
141141

142142
bool jimp_bool(Jimp *jimp, bool *boolean)
143143
{
144-
if (!jimp_get_and_expect_token(jimp, CLEX_id)) return false;
144+
if (!jimp__get_and_expect_token(jimp, CLEX_id)) return false;
145145
if (strcmp(jimp->l.string, "true") == 0) {
146146
*boolean = true;
147147
} else if (strcmp(jimp->l.string, "false") == 0) {
148148
*boolean = false;
149149
} else {
150150
stb_lex_location loc = {0};
151151
stb_c_lexer_get_location(&jimp->l, jimp->l.where_firstchar, &loc);
152-
fprintf(stderr, "%s:%d:%d: ERROR: Expected boolean but got `%s`\n", jimp->file_path, loc.line_number, loc.line_offset + 1, jimp_token_kind(jimp->l.token));
152+
fprintf(stderr, "%s:%d:%d: ERROR: Expected boolean but got `%s`\n", jimp->file_path, loc.line_number, loc.line_offset + 1, jimp__token_kind(jimp->l.token));
153153
return false;
154154
}
155155
return true;
@@ -158,23 +158,23 @@ bool jimp_bool(Jimp *jimp, bool *boolean)
158158
bool jimp_number(Jimp *jimp, long *number)
159159
{
160160
// TODO: there are more things that constitude number in JSON, for example floats. Take all of them into account here.
161-
if (!jimp_get_and_expect_token(jimp, CLEX_intlit)) return false;
161+
if (!jimp__get_and_expect_token(jimp, CLEX_intlit)) return false;
162162
*number = jimp->l.int_number;
163163
return true;
164164
}
165165

166-
bool jimp_get_and_expect_token(Jimp *jimp, long token)
166+
static bool jimp__get_and_expect_token(Jimp *jimp, long token)
167167
{
168168
if (!stb_c_lexer_get_token(&jimp->l)) return false;
169-
return jimp_expect_token(jimp, token);
169+
return jimp__expect_token(jimp, token);
170170
}
171171

172-
bool jimp_expect_token(Jimp *jimp, long token)
172+
static bool jimp__expect_token(Jimp *jimp, long token)
173173
{
174174
if (jimp->l.token != token) {
175175
stb_lex_location loc = {0};
176176
stb_c_lexer_get_location(&jimp->l, jimp->l.where_firstchar, &loc);
177-
fprintf(stderr, "%s:%d:%d: ERROR: expected %s, but got %s\n", jimp->file_path, loc.line_number, loc.line_offset + 1, jimp_token_kind(token), jimp_token_kind(jimp->l.token));
177+
fprintf(stderr, "%s:%d:%d: ERROR: expected %s, but got %s\n", jimp->file_path, loc.line_number, loc.line_offset + 1, jimp__token_kind(token), jimp__token_kind(jimp->l.token));
178178
return false;
179179
}
180180
return true;

0 commit comments

Comments
 (0)