@@ -5,8 +5,8 @@ Subject: Allow to parse macro identifiers in variable decls
5
5
6
6
---
7
7
grammar.js | 2 +
8
- src/scanner.c | 128 +++++++++++++++++++++++++++++++++++++++-- ---------
9
- 2 files changed, 103 insertions(+), 27 deletions(-)
8
+ src/scanner.c | 141 +++++++++++++++++++++++++++++++++++++++++ ---------
9
+ 2 files changed, 119 insertions(+), 24 deletions(-)
10
10
11
11
diff --git a/grammar.js b/grammar.js
12
12
index 6e79004..40ac8b7 100644
@@ -29,7 +29,7 @@ index 6e79004..40ac8b7 100644
29
29
optional(seq(',',
30
30
commaSep1(
31
31
diff --git a/src/scanner.c b/src/scanner.c
32
- index b768d99..e477df4 100644
32
+ index b768d99..e5a37ee 100644
33
33
--- a/src/scanner.c
34
34
+++ b/src/scanner.c
35
35
@@ -1,4 +1,5 @@
@@ -65,10 +65,23 @@ index b768d99..e477df4 100644
65
65
+ // Returns NULL on error, otherwise an allocated char array for an identifier
66
66
+ static String *scan_identifier(TSLexer *lexer) {
67
67
if (!iswalpha(lexer->lookahead)) {
68
+ - return false;
68
69
+ return NULL;
69
- + }
70
+ }
71
+ -
72
+ - lexer->result_symbol = STRING_LITERAL_KIND;
73
+ -
74
+ - // We need two characters of lookahead to see `_"`
75
+ - char current_char = '\0';
76
+ -
70
77
+ String *possible_identifier = ts_calloc(1, sizeof(String));
71
- + while (is_identifier_char(lexer->lookahead) && !lexer->eof(lexer)) {
78
+ while (is_identifier_char(lexer->lookahead) && !lexer->eof(lexer)) {
79
+ - current_char = lexer->lookahead;
80
+ - // Don't capture the trailing underscore as part of the kind identifier
81
+ - if (lexer->lookahead == '_') {
82
+ - lexer->mark_end(lexer);
83
+ - }
84
+ - advance(lexer);
72
85
+ array_push(possible_identifier, lexer->lookahead);
73
86
+ // Don't capture the trailing underscore as part of the kind identifier
74
87
+ // If another user of this function wants to mark the end again after
@@ -91,32 +104,16 @@ index b768d99..e477df4 100644
91
104
+ static bool scan_string_literal_kind(TSLexer *lexer, String *identifier) {
92
105
+ if (identifier->size == 0) {
93
106
+ return false;
94
- + }
95
- +
107
+ }
108
+
109
+ - if ((current_char != '_') || (lexer->lookahead != '"' && lexer->lookahead != '\'')) {
96
110
+ char last_char = identifier->contents[identifier->size - 1];
97
111
+ if ((last_char != '_') ||
98
112
+ (lexer->lookahead != '"' && lexer->lookahead != '\'')) {
99
113
return false;
100
114
}
101
115
102
- lexer->result_symbol = STRING_LITERAL_KIND;
103
- -
104
- - // We need two characters of lookahead to see `_"`
105
- - char current_char = '\0';
106
- -
107
- - while (is_identifier_char(lexer->lookahead) && !lexer->eof(lexer)) {
108
- - current_char = lexer->lookahead;
109
- - // Don't capture the trailing underscore as part of the kind identifier
110
- - if (lexer->lookahead == '_') {
111
- - lexer->mark_end(lexer);
112
- - }
113
- - advance(lexer);
114
- - }
115
- -
116
- - if ((current_char != '_') || (lexer->lookahead != '"' && lexer->lookahead != '\'')) {
117
- - return false;
118
- - }
119
- -
116
+ + lexer->result_symbol = STRING_LITERAL_KIND;
120
117
return true;
121
118
}
122
119
0 commit comments