mirror of
https://github.com/apple/pkl.git
synced 2026-03-28 03:51:14 +01:00
Correctly handle EOF after unmatched backtick (#1187)
This commit is contained in:
@@ -489,7 +489,7 @@ public class Lexer {
|
||||
}
|
||||
|
||||
private void lexQuotedIdentifier() {
|
||||
while (lookahead != '`' && lookahead != '\n' && lookahead != '\r') {
|
||||
while (lookahead != '`' && lookahead != '\n' && lookahead != '\r' && lookahead != EOF) {
|
||||
nextChar();
|
||||
}
|
||||
if (lookahead == '`') {
|
||||
@@ -705,6 +705,13 @@ public class Lexer {
|
||||
}
|
||||
|
||||
private ParserError unexpectedChar(char got, String didYouMean) {
|
||||
if (got == EOF) {
|
||||
return unexpectedChar("EOF", didYouMean);
|
||||
}
|
||||
return lexError("unexpectedCharacter", got, didYouMean);
|
||||
}
|
||||
|
||||
private ParserError unexpectedChar(String got, String didYouMean) {
|
||||
return lexError("unexpectedCharacter", got, didYouMean);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.pkl.parser
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
|
||||
class LexerTest {
|
||||
|
||||
@@ -46,4 +47,10 @@ class LexerTest {
|
||||
assertThat(Lexer.maybeQuoteIdentifier("this")).isEqualTo("`this`")
|
||||
assertThat(Lexer.maybeQuoteIdentifier("😀")).isEqualTo("`😀`")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun lexSingleBacktick() {
|
||||
val thrown = assertThrows<ParserError> { Lexer("`").next() }
|
||||
assertThat(thrown).hasMessageContaining("Unexpected character `EOF`")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user