Skip to content

Commit 65ce830

Browse files
committed
Fix catching number literals immediately followed by &
`mark_end` has to be used with `advance` rather than `skip`, or the text isn't captured properly in the CST (although the named node may still exist) Closes stadelmanma#146
1 parent b3947ae commit 65ce830

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/scanner.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,23 @@ static bool scan_int(TSLexer *lexer) {
6262
while (iswdigit(lexer->lookahead)) {
6363
advance(lexer); // store all digits
6464
}
65+
lexer->mark_end(lexer);
6566

6667
// handle line continuations
6768
if (lexer->lookahead == '&') {
68-
skip(lexer);
69+
advance(lexer);
6970
while (iswspace(lexer->lookahead)) {
70-
skip(lexer);
71+
advance(lexer);
7172
}
7273
// second '&' required to continue the literal
7374
if (lexer->lookahead == '&') {
74-
skip(lexer);
75+
advance(lexer);
7576
// don't return here, as we may have finished literal on first
7677
// line but still have second '&'
7778
scan_int(lexer);
7879
}
7980
}
8081

81-
lexer->mark_end(lexer);
8282
return true;
8383
}
8484

@@ -106,11 +106,11 @@ static bool scan_number(TSLexer *lexer) {
106106
advance(lexer);
107107
if (lexer->lookahead == '+' || lexer->lookahead == '-') {
108108
advance(lexer);
109+
lexer->mark_end(lexer);
109110
}
110111
if (!scan_int(lexer)) {
111112
return true; // valid number token with junk after it
112113
}
113-
lexer->mark_end(lexer);
114114
lexer->result_symbol = FLOAT_LITERAL;
115115
}
116116
}

test/corpus/line_continuations.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,32 @@ end program
273273
(edit_descriptor)
274274
(hollerith_constant)))
275275
(end_program_statement)))
276+
277+
================================================================================
278+
Line continuation immediately after number literal
279+
================================================================================
280+
program test
281+
integer :: b(3) = (/&
282+
1, &
283+
2, &
284+
3&
285+
/)
286+
end program test
287+
--------------------------------------------------------------------------------
288+
(translation_unit
289+
(program
290+
(program_statement
291+
(name))
292+
(variable_declaration
293+
(intrinsic_type)
294+
(init_declarator
295+
(sized_declarator
296+
(identifier)
297+
(size
298+
(number_literal)))
299+
(array_literal
300+
(number_literal)
301+
(number_literal)
302+
(number_literal))))
303+
(end_program_statement
304+
(name))))

0 commit comments

Comments
 (0)