Skip to content

Commit e6e7900

Browse files
authored
Rename lexer struct, param, and functions (#35)
1. `lexerstate` should be `rbs_lexer_t` instead 2. Params representing `rbs_lexer_t` should be named `lexer` instead of `state` 3. `rbsparser_next_token` should be called `rbs_lexer_next_token` After this PR, all structs & functions we want to expose should have `rbs_` prefix.
1 parent 496bfef commit e6e7900

File tree

7 files changed

+764
-764
lines changed

7 files changed

+764
-764
lines changed

ext/rbs_extension/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static VALUE parse_type_try(VALUE a) {
129129
return ruby_ast;
130130
}
131131

132-
static lexstate *alloc_lexer_from_buffer(rbs_allocator_t *allocator, VALUE string, rb_encoding *encoding, int start_pos, int end_pos) {
132+
static rbs_lexer_t *alloc_lexer_from_buffer(rbs_allocator_t *allocator, VALUE string, rb_encoding *encoding, int start_pos, int end_pos) {
133133
if (start_pos < 0 || end_pos < 0) {
134134
rb_raise(rb_eArgError, "negative position range: %d...%d", start_pos, end_pos);
135135
}
@@ -286,12 +286,12 @@ static VALUE rbsparser_lex(VALUE self, VALUE buffer, VALUE end_pos) {
286286

287287
rbs_allocator_t allocator;
288288
rbs_allocator_init(&allocator);
289-
lexstate *lexer = alloc_lexer_from_buffer(&allocator, string, encoding, 0, FIX2INT(end_pos));
289+
rbs_lexer_t *lexer = alloc_lexer_from_buffer(&allocator, string, encoding, 0, FIX2INT(end_pos));
290290

291291
VALUE results = rb_ary_new();
292292
rbs_token_t token = NullToken;
293293
while (token.type != pEOF) {
294-
token = rbsparser_next_token(lexer);
294+
token = rbs_lexer_next_token(lexer);
295295
VALUE type = ID2SYM(rb_intern(rbs_token_type_str(token.type)));
296296
VALUE location = rbs_new_location(buffer, token.range);
297297
VALUE pair = rb_ary_new3(2, type, location);

include/rbs/lexer.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ typedef struct {
134134
bool first_token_of_line; /* This flag is used for tLINECOMMENT */
135135
unsigned int last_char; /* Last peeked character */
136136
const rbs_encoding_t *encoding;
137-
} lexstate;
137+
} rbs_lexer_t;
138138

139139
extern rbs_token_t NullToken;
140140
extern rbs_position_t NullPosition;
141141
extern rbs_range_t NULL_RANGE;
142142

143-
char *rbs_peek_token(lexstate *state, rbs_token_t tok);
143+
char *rbs_peek_token(rbs_lexer_t *lexer, rbs_token_t tok);
144144
int rbs_token_chars(rbs_token_t tok);
145145
int rbs_token_bytes(rbs_token_t tok);
146146

@@ -154,29 +154,29 @@ const char *rbs_token_type_str(enum RBSTokenType type);
154154
/**
155155
* Read next character.
156156
* */
157-
unsigned int rbs_peek(lexstate *state);
157+
unsigned int rbs_peek(rbs_lexer_t *lexer);
158158

159159
/**
160160
* Skip one character.
161161
* */
162-
void rbs_skip(lexstate *state);
162+
void rbs_skip(rbs_lexer_t *lexer);
163163

164164
/**
165165
* Skip n characters.
166166
* */
167-
void rbs_skipn(lexstate *state, size_t size);
167+
void rbs_skipn(rbs_lexer_t *lexer, size_t size);
168168

169169
/**
170170
* Return new rbs_token_t with given type.
171171
* */
172-
rbs_token_t rbs_next_token(lexstate *state, enum RBSTokenType type);
172+
rbs_token_t rbs_next_token(rbs_lexer_t *lexer, enum RBSTokenType type);
173173

174174
/**
175175
* Return new rbs_token_t with EOF type.
176176
* */
177-
rbs_token_t rbs_next_eof_token(lexstate *state);
177+
rbs_token_t rbs_next_eof_token(rbs_lexer_t *lexer);
178178

179-
rbs_token_t rbsparser_next_token(lexstate *state);
179+
rbs_token_t rbs_lexer_next_token(rbs_lexer_t *lexer);
180180

181181
void rbs_print_token(rbs_token_t tok);
182182

include/rbs/parser.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef struct rbs_error_t {
4444
* An RBS parser is a LL(3) parser.
4545
* */
4646
typedef struct {
47-
lexstate *lexstate;
47+
rbs_lexer_t *rbs_lexer_t;
4848

4949
rbs_token_t current_token;
5050
rbs_token_t next_token; /* The first lookahead token */
@@ -83,14 +83,14 @@ void rbs_parser_push_typevar_table(rbs_parser_t *parser, bool reset);
8383
NODISCARD bool rbs_parser_insert_typevar(rbs_parser_t *parser, rbs_constant_id_t id);
8484

8585
/**
86-
* Allocate new lexstate object.
86+
* Allocate new rbs_lexer_t object.
8787
*
8888
* ```
8989
* VALUE string = rb_funcall(buffer, rb_intern("content"), 0);
90-
* rbs_lexer_new(string, 0, 31) // New lexstate with buffer content
90+
* rbs_lexer_new(string, 0, 31) // New rbs_lexer_t with buffer content
9191
* ```
9292
* */
93-
lexstate *rbs_lexer_new(rbs_allocator_t *, rbs_string_t string, const rbs_encoding_t *encoding, int start_pos, int end_pos);
93+
rbs_lexer_t *rbs_lexer_new(rbs_allocator_t *, rbs_string_t string, const rbs_encoding_t *encoding, int start_pos, int end_pos);
9494

9595
/**
9696
* Allocate new rbs_parser_t object.

0 commit comments

Comments
 (0)