fix: apply some clang-tidy lints

syntax_id
Amaan Qureshi 2023-07-26 20:25:12 +07:00
parent 4ca44145dd
commit bae4cdccbf
No known key found for this signature in database
GPG Key ID: E67890ADC4227273
1 changed files with 26 additions and 30 deletions

56
src/scanner.c vendored

@ -16,7 +16,7 @@ enum TokenType {
/* Pretty much all of this code is taken from the Julia tree-sitter
parser.
Julia has similar problems with multiline comments that can be nested,
line comments, as well as line and multiline strings.
@ -59,9 +59,9 @@ static void free_stack(Stack *stack) {
free(stack);
}
static void push(Stack *stack, char c, bool triple) {
static void push(Stack *stack, char chr, bool triple) {
if (stack->len >= TREE_SITTER_SERIALIZATION_BUFFER_SIZE) exit(1);
stack->arr[stack->len++] = triple ? (c + 1) : c;
stack->arr[stack->len++] = (Delimiter)(triple ? (chr + 1) : chr);
}
static Delimiter pop(Stack *stack) {
@ -128,18 +128,17 @@ static bool scan_string_content(TSLexer *lexer, Stack *stack) {
// otherwise, if this is the start, determine if it is an
// interpolated identifier.
// otherwise, it's just string content, so continue
else {
advance(lexer);
if (iswalpha(lexer->lookahead) || lexer->lookahead == '{') {
// this must be a string interpolation, let's
// fail so we parse it as such
return false;
}
lexer->result_symbol = STRING_CONTENT;
mark_end(lexer);
return true;
advance(lexer);
if (iswalpha(lexer->lookahead) || lexer->lookahead == '{') {
// this must be a string interpolation, let's
// fail so we parse it as such
return false;
}
} else if (lexer->lookahead == '\\') {
lexer->result_symbol = STRING_CONTENT;
mark_end(lexer);
return true;
}
if (lexer->lookahead == '\\') {
// if we see a \, then this might possibly escape a dollar sign
// in which case, we need to not defer to the interpolation
has_content = true;
@ -167,7 +166,7 @@ static bool scan_string_content(TSLexer *lexer, Stack *stack) {
^
where we are at the `f`, we should quit after
reading `foo`, and ascribe it to STRING_CONTENT.
Then, we restart and try to read the end.
This is to prevent `foo` from being absorbed into
the STRING_END token.
@ -192,19 +191,17 @@ static bool scan_string_content(TSLexer *lexer, Stack *stack) {
}
pop(stack);
return true;
} else {
if (has_content) {
mark_end(lexer);
lexer->result_symbol = STRING_CONTENT;
return true;
} else {
pop(stack);
advance(lexer);
mark_end(lexer);
lexer->result_symbol = STRING_END;
return true;
}
}
if (has_content) {
mark_end(lexer);
lexer->result_symbol = STRING_CONTENT;
return true;
}
pop(stack);
advance(lexer);
mark_end(lexer);
lexer->result_symbol = STRING_END;
return true;
}
advance(lexer);
has_content = true;
@ -262,13 +259,12 @@ static bool scan_whitespace_and_comments(TSLexer *lexer) {
if (lexer->lookahead == '/') {
return false;
} else {
return true;
}
return true;
}
}
static bool scan_for_word(TSLexer *lexer, char* word, unsigned len) {
static bool scan_for_word(TSLexer *lexer, const char* word, unsigned len) {
skip(lexer);
for (unsigned i = 0; i < len; i++) {
if (lexer->lookahead != word[i]) return false;