Skip to content

Commit

Permalink
update again (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonspark authored Jan 15, 2025
1 parent 0610ec8 commit 9b38c6b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions lang/semgrep-grammars/src/semgrep-kotlin/src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,23 @@ static bool scan_whitespace_and_comments(TSLexer *lexer) {
return lexer->lookahead != '/';
}

// Test for any identifier character other than the first character.
// This is meant to match the regexp [\p{L}_\p{Nd}]
// as found in '_alpha_identifier' (see grammar.js).
static bool is_word_char(int32_t c) {
return (iswalnum(c) || c == '_');
}

// Scan for [the end of] a nonempty alphanumeric identifier or
// alphanumeric keyword (including '_').
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;
skip(lexer);
}
// check that the identifier stops here
if (is_word_char(lexer->lookahead)) return false;
return true;
}

Expand Down Expand Up @@ -288,10 +299,8 @@ static bool scan_automatic_semicolon(TSLexer *lexer) {

if (sameline) {
switch (lexer->lookahead) {
// Don't insert a semicolon before an else
case 'e':
return !scan_for_word(lexer, "lse", 3);

// Insert imaginary semicolon before an 'import' but not in front
// of other words or keywords starting with 'i'
case 'i':
return scan_for_word(lexer, "mport", 5);

Expand All @@ -300,6 +309,7 @@ static bool scan_automatic_semicolon(TSLexer *lexer) {
lexer->mark_end(lexer);
return true;

// Don't insert a semicolon in other cases
default:
return false;
}
Expand Down Expand Up @@ -538,4 +548,4 @@ void tree_sitter_kotlin_external_scanner_deserialize(void *payload, const char *
} else {
array_clear(stack);
}
}
}

0 comments on commit 9b38c6b

Please sign in to comment.