Skip to content

Commit 769cd46

Browse files
committed
Rename parser types and functions
1 parent 11e7ce1 commit 769cd46

File tree

19 files changed

+414
-411
lines changed

19 files changed

+414
-411
lines changed

distr/flecs.c

Lines changed: 206 additions & 205 deletions
Large diffs are not rendered by default.

docs/Quickstart.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ Addon | Description | Define
119119
[Doc](/flecs/group__c__addons__doc.html) | Add documentation to components, systems & more | FLECS_DOC |
120120
[Http](/flecs/group__c__addons__http.html) | Tiny HTTP server for processing simple requests | FLECS_HTTP |
121121
[Rest](/flecs/group__c__addons__rest.html) | REST API for showing entities in the browser | FLECS_REST |
122-
[Script](/flecs/group__c__addons__script.html) | DSL for assets, scenes and configuration | FLECS_SCRIPT |
122+
[Parser](/flecs/group__c__addons__parser.html) | Parser utilities used by script & query DSL | FLECS_PARSER |
123+
[Script](/flecs/group__c__addons__script.html) | DSL for scenes, assets and configuration | FLECS_SCRIPT |
123124
[Stats](/flecs/group__c__addons__stats.html) | Functions for collecting statistics | FLECS_STATS |
124125
[Metrics](/flecs/group__c__addons__metrics.html) | Create metrics from user-defined components | FLECS_METRICS |
125126
[Alerts](/flecs/group__c__addons__alerts.html) | Create alerts from user-defined queries | FLECS_ALERTS |

src/addons/parser/grammar.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* @file addons/parser/grammar.h
3-
* @brief Script grammar parser.
3+
* @brief Grammar parser.
44
*
55
* Macro utilities that facilitate a simple recursive descent parser.
66
*/
77

8-
#ifndef FLECS_SCRIPT_GRAMMAR_H
9-
#define FLECS_SCRIPT_GRAMMAR_H
8+
#ifndef FLECS_PARSER_GRAMMAR_H
9+
#define FLECS_PARSER_GRAMMAR_H
1010

1111
#if defined(ECS_TARGET_CLANG)
1212
/* Ignore unused enum constants in switch as it would blow up the parser code */
@@ -29,7 +29,7 @@
2929
.pub.name = script_name,\
3030
.pub.code = expr\
3131
};\
32-
ecs_script_parser_t parser = {\
32+
ecs_parser_t parser = {\
3333
.script = flecs_script_impl(&script),\
3434
.name = script_name,\
3535
.code = expr,\
@@ -39,10 +39,10 @@
3939

4040
/* Definitions for parser functions */
4141
#define ParserBegin\
42-
ecs_script_tokenizer_t _tokenizer;\
42+
ecs_tokenizer_t _tokenizer;\
4343
ecs_os_zeromem(&_tokenizer);\
4444
_tokenizer.tokens = _tokenizer.stack.tokens;\
45-
ecs_script_tokenizer_t *tokenizer = &_tokenizer;
45+
ecs_tokenizer_t *tokenizer = &_tokenizer;
4646

4747
#define ParserEnd\
4848
Error("unexpected end of rule (parser error)");\
@@ -118,8 +118,8 @@
118118
#define Until(until, ...)\
119119
{\
120120
ecs_assert(tokenizer->stack.count < 256, ECS_INTERNAL_ERROR, NULL);\
121-
ecs_script_token_t *t = &tokenizer->stack.tokens[tokenizer->stack.count ++];\
122-
if (!(pos = flecs_script_until(parser, pos, t, until))) {\
121+
ecs_token_t *t = &tokenizer->stack.tokens[tokenizer->stack.count ++];\
122+
if (!(pos = flecs_tokenizer_until(parser, pos, t, until))) {\
123123
goto error;\
124124
}\
125125
}\
@@ -129,19 +129,19 @@
129129
#define Parse(...)\
130130
{\
131131
ecs_assert(tokenizer->stack.count < 256, ECS_INTERNAL_ERROR, NULL);\
132-
ecs_script_token_t *t = &tokenizer->stack.tokens[tokenizer->stack.count ++];\
133-
if (!(pos = flecs_script_token(parser, pos, t, false))) {\
132+
ecs_token_t *t = &tokenizer->stack.tokens[tokenizer->stack.count ++];\
133+
if (!(pos = flecs_token(parser, pos, t, false))) {\
134134
goto error;\
135135
}\
136136
switch(t->kind) {\
137137
__VA_ARGS__\
138138
default:\
139139
if (t->value) {\
140140
Error("unexpected %s'%s'", \
141-
flecs_script_token_kind_str(t->kind), t->value);\
141+
flecs_token_kind_str(t->kind), t->value);\
142142
} else {\
143143
Error("unexpected %s", \
144-
flecs_script_token_kind_str(t->kind));\
144+
flecs_token_kind_str(t->kind));\
145145
}\
146146
}\
147147
}
@@ -197,9 +197,9 @@
197197
/* Same as Parse, but doesn't error out if token is not in handled cases */
198198
#define LookAhead(...)\
199199
const char *lookahead;\
200-
ecs_script_token_t lookahead_token;\
200+
ecs_token_t lookahead_token;\
201201
const char *old_lh_token_cur = parser->token_cur;\
202-
if ((lookahead = flecs_script_token(parser, pos, &lookahead_token, true))) {\
202+
if ((lookahead = flecs_token(parser, pos, &lookahead_token, true))) {\
203203
tokenizer->stack.tokens[tokenizer->stack.count ++] = lookahead_token;\
204204
switch(lookahead_token.kind) {\
205205
__VA_ARGS__\

src/addons/parser/parser.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11

22
/**
3-
* @file addons/script/parser.h
3+
* @file addons/parser/parser.h
44
* @brief Script parser.
55
*/
66

7-
#ifndef FLECS_SCRIPT_PARSER_H
8-
#define FLECS_SCRIPT_PARSER_H
7+
#ifndef FLECS_PARSER_H
8+
#define FLECS_PARSER_H
99

1010
#include "../../private_api.h"
1111
#include <ctype.h>
1212

1313
typedef struct ecs_script_impl_t ecs_script_impl_t;
1414
typedef struct ecs_script_scope_t ecs_script_scope_t;
1515

16-
typedef struct ecs_script_parser_t {
17-
ecs_script_impl_t *script;
18-
ecs_script_scope_t *scope;
19-
16+
typedef struct ecs_parser_t {
2017
const char *name;
2118
const char *code;
2219

@@ -26,11 +23,15 @@ typedef struct ecs_script_parser_t {
2623
bool significant_newline;
2724
bool merge_variable_members;
2825

26+
/* For script parser */
27+
ecs_script_impl_t *script;
28+
ecs_script_scope_t *scope;
29+
2930
/* For term parser */
3031
ecs_term_t *term;
3132
ecs_oper_kind_t extra_oper;
3233
ecs_term_ref_t *extra_args;
33-
} ecs_script_parser_t;
34+
} ecs_parser_t;
3435

3536
#include "tokenizer.h"
3637

src/addons/parser/tokenizer.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
out->kind = _kind;\
3232
return pos + 1;
3333

34-
const char* flecs_script_token_kind_str(
35-
ecs_script_token_kind_t kind)
34+
const char* flecs_token_kind_str(
35+
ecs_token_kind_t kind)
3636
{
3737
switch(kind) {
3838
case EcsTokUnknown:
@@ -101,8 +101,8 @@ const char* flecs_script_token_kind_str(
101101
}
102102
}
103103

104-
const char* flecs_script_token_str(
105-
ecs_script_token_kind_t kind)
104+
const char* flecs_token_str(
105+
ecs_token_kind_t kind)
106106
{
107107
switch(kind) {
108108
case EcsTokUnknown: return "unknown token";
@@ -163,7 +163,7 @@ const char* flecs_script_token_str(
163163
}
164164

165165
const char* flecs_scan_whitespace(
166-
ecs_script_parser_t *parser,
166+
ecs_parser_t *parser,
167167
const char *pos)
168168
{
169169
(void)parser;
@@ -183,7 +183,7 @@ const char* flecs_scan_whitespace(
183183

184184
static
185185
const char* flecs_scan_whitespace_and_comment(
186-
ecs_script_parser_t *parser,
186+
ecs_parser_t *parser,
187187
const char *pos)
188188
{
189189
repeat_skip_whitespace_comment:
@@ -219,10 +219,10 @@ bool flecs_script_is_identifier(
219219
return isalpha(c) || (c == '_') || (c == '$') || (c == '#');
220220
}
221221

222-
const char* flecs_script_identifier(
223-
ecs_script_parser_t *parser,
222+
const char* flecs_tokenizer_identifier(
223+
ecs_parser_t *parser,
224224
const char *pos,
225-
ecs_script_token_t *out)
225+
ecs_token_t *out)
226226
{
227227
if (out) {
228228
out->kind = EcsTokIdentifier;
@@ -330,9 +330,9 @@ bool flecs_script_is_number(
330330

331331
static
332332
const char* flecs_script_number(
333-
ecs_script_parser_t *parser,
333+
ecs_parser_t *parser,
334334
const char *pos,
335-
ecs_script_token_t *out)
335+
ecs_token_t *out)
336336
{
337337
out->kind = EcsTokNumber;
338338
out->value = parser->token_cur;
@@ -387,7 +387,7 @@ const char* flecs_script_number(
387387

388388
static
389389
const char* flecs_script_skip_string(
390-
ecs_script_parser_t *parser,
390+
ecs_parser_t *parser,
391391
const char *pos,
392392
char delim)
393393
{
@@ -409,9 +409,9 @@ const char* flecs_script_skip_string(
409409

410410
static
411411
const char* flecs_script_string(
412-
ecs_script_parser_t *parser,
412+
ecs_parser_t *parser,
413413
const char *pos,
414-
ecs_script_token_t *out)
414+
ecs_token_t *out)
415415
{
416416
const char *end = flecs_script_skip_string(parser, pos + 1, '"');
417417
if (!end) {
@@ -433,9 +433,9 @@ const char* flecs_script_string(
433433

434434
static
435435
const char* flecs_script_multiline_string(
436-
ecs_script_parser_t *parser,
436+
ecs_parser_t *parser,
437437
const char *pos,
438-
ecs_script_token_t *out)
438+
ecs_token_t *out)
439439
{
440440
char ch;
441441
const char *end = pos + 1;
@@ -462,10 +462,10 @@ const char* flecs_script_multiline_string(
462462
return end + 2;
463463
}
464464

465-
const char* flecs_script_until(
466-
ecs_script_parser_t *parser,
465+
const char* flecs_tokenizer_until(
466+
ecs_parser_t *parser,
467467
const char *pos,
468-
ecs_script_token_t *out,
468+
ecs_token_t *out,
469469
char until)
470470
{
471471
parser->pos = pos;
@@ -511,10 +511,10 @@ const char* flecs_script_until(
511511
return pos;
512512
}
513513

514-
const char* flecs_script_token(
515-
ecs_script_parser_t *parser,
514+
const char* flecs_token(
515+
ecs_parser_t *parser,
516516
const char *pos,
517-
ecs_script_token_t *out,
517+
ecs_token_t *out,
518518
bool is_lookahead)
519519
{
520520
parser->pos = pos;
@@ -600,7 +600,7 @@ const char* flecs_script_token(
600600
return flecs_script_multiline_string(parser, pos, out);
601601

602602
} else if (flecs_script_is_identifier(pos[0])) {
603-
return flecs_script_identifier(parser, pos, out);
603+
return flecs_tokenizer_identifier(parser, pos, out);
604604
}
605605

606606
if (!is_lookahead) {

src/addons/parser/tokenizer.h

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
2-
* @file addons/script/tokenizer.h
3-
* @brief Script tokenizer.
2+
* @file addons/parser/tokenizer.h
3+
* @brief Parser tokenizer.
44
*/
55

6-
#ifndef FLECS_SCRIPT_TOKENIZER_H
7-
#define FLECS_SCRIPT_TOKENIZER_H
6+
#ifndef FLECS_PARSER_TOKENIZER_H
7+
#define FLECS_PARSER_TOKENIZER_H
88

99
/* Tokenizer */
10-
typedef enum ecs_script_token_kind_t {
10+
typedef enum ecs_token_kind_t {
1111
EcsTokEnd = '\0',
1212
EcsTokUnknown,
1313
EcsTokScopeOpen = '{',
@@ -60,48 +60,48 @@ typedef enum ecs_script_token_kind_t {
6060
EcsTokKeywordMatch = 132,
6161
EcsTokAddAssign = 133,
6262
EcsTokMulAssign = 134,
63-
} ecs_script_token_kind_t;
63+
} ecs_token_kind_t;
6464

65-
typedef struct ecs_script_token_t {
65+
typedef struct ecs_token_t {
6666
const char *value;
67-
ecs_script_token_kind_t kind;
68-
} ecs_script_token_t;
67+
ecs_token_kind_t kind;
68+
} ecs_token_t;
6969

70-
typedef struct ecs_script_tokens_t {
70+
typedef struct ecs_tokens_t {
7171
int32_t count;
72-
ecs_script_token_t tokens[256];
73-
} ecs_script_tokens_t;
72+
ecs_token_t tokens[256];
73+
} ecs_tokens_t;
7474

75-
typedef struct ecs_script_tokenizer_t {
76-
ecs_script_tokens_t stack;
77-
ecs_script_token_t *tokens;
78-
} ecs_script_tokenizer_t;
75+
typedef struct ecs_tokenizer_t {
76+
ecs_tokens_t stack;
77+
ecs_token_t *tokens;
78+
} ecs_tokenizer_t;
7979

80-
const char* flecs_script_until(
81-
ecs_script_parser_t *parser,
80+
const char* flecs_tokenizer_until(
81+
ecs_parser_t *parser,
8282
const char *ptr,
83-
ecs_script_token_t *out,
83+
ecs_token_t *out,
8484
char until);
8585

86-
const char* flecs_script_token_kind_str(
87-
ecs_script_token_kind_t kind);
86+
const char* flecs_token_kind_str(
87+
ecs_token_kind_t kind);
8888

89-
const char* flecs_script_token_str(
90-
ecs_script_token_kind_t kind);
89+
const char* flecs_token_str(
90+
ecs_token_kind_t kind);
9191

92-
const char* flecs_script_token(
93-
ecs_script_parser_t *parser,
92+
const char* flecs_token(
93+
ecs_parser_t *parser,
9494
const char *ptr,
95-
ecs_script_token_t *out,
95+
ecs_token_t *out,
9696
bool is_lookahead);
9797

9898
const char* flecs_scan_whitespace(
99-
ecs_script_parser_t *parser,
99+
ecs_parser_t *parser,
100100
const char *pos);
101101

102-
const char* flecs_script_identifier(
103-
ecs_script_parser_t *parser,
102+
const char* flecs_tokenizer_identifier(
103+
ecs_parser_t *parser,
104104
const char *pos,
105-
ecs_script_token_t *out);
105+
ecs_token_t *out);
106106

107107
#endif

0 commit comments

Comments
 (0)