Skip to content

Commit b265e20

Browse files
authored
fix: detect eof as end of parsing in scanner (#37)
Fixes: #36
1 parent 735f02b commit b265e20

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

corpus/subject.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,14 @@ feat!: allow provided config object to extend other configs
136136
(type))
137137
(overflow)))
138138

139+
================================================================================
140+
fix #36
141+
================================================================================
142+
feat(test):
143+
--------------------------------------------------------------------------------
144+
145+
(source
146+
(ERROR
147+
(prefix
148+
(type)
149+
(scope))))

src/scanner.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ bool tree_sitter_gitcommit_external_scanner_scan(void *payload, TSLexer *lexer,
5959
if (valid_symbols[CONVENTIONNAL_SUBJECT]) {
6060
lexer->result_symbol = CONVENTIONNAL_SUBJECT;
6161

62+
if (lexer->lookahead == '\n' || lexer->lookahead == '\r' ||
63+
lexer->lookahead == '\0') {
64+
return false;
65+
}
66+
6267
while (lexer->lookahead != '\n' && lexer->lookahead != '\r' &&
63-
50 > lexer->get_column(lexer)) {
68+
lexer->lookahead != '\0' && 50 > lexer->get_column(lexer)) {
6469
lexer->advance(lexer, false);
6570
}
6671

0 commit comments

Comments
 (0)