Skip to content

Commit e08a7cf

Browse files
authored
Fixes an ambiguity with identifiers and keywords. (#32)
Previously, `SELECTY` would be parsed as keyword `SELECT` identifier `Y`. This fixes the negative look-ahead assertion for keywords to make sure a non-quoted identifier character follows and similarly adds a look-ahead assertion for the prefix of identifiers to not be keywords (which includes the previous assertion). Also fixes a unit test name for identifiers.
1 parent d257e3e commit e08a7cf

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

partiql-parser/src/partiql.pest

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ StringContent = {
155155
Identifier = { NonQuotedIdentifier | QuotedIdentifier }
156156

157157
NonQuotedIdentifier = @{
158-
!Keyword ~ NonQuotedIdentifierStart ~ NonQuotedIdentifierCont*
158+
!(Keyword) ~ NonQuotedIdentifierStart ~ NonQuotedIdentifierCont*
159159
}
160160

161161
NonQuotedIdentifierStart = _{ "_" | "$" | 'a'..'z' | 'A'..'Z' }
@@ -173,7 +173,9 @@ QuotedIdentifierContent = {
173173
// Keywords
174174
//
175175

176-
Keyword = { SqlKeyword | PartiqlKeyword }
176+
Keyword = @{
177+
(SqlKeyword | PartiqlKeyword) ~ !NonQuotedIdentifierCont
178+
}
177179

178180
SqlKeyword = _{
179181
Absolute_

partiql-parser/src/scanner.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ mod test {
509509
"WHERE" => keyword("WHERE")
510510
]
511511
)]
512-
#[case::some_keywords(
512+
#[case::some_identifiers(
513513
scanner_test_case![
514514
"moo_cow_1999" => identifier("moo_cow_1999"),
515515
" ",
@@ -518,6 +518,13 @@ mod test {
518518
"$$$$" => identifier("$$$$")
519519
]
520520
)]
521+
#[case::identifiers_with_keywords_in_them(
522+
scanner_test_case![
523+
"moowhere" => identifier("moowhere"),
524+
" ",
525+
"selecty" => identifier("selecty"),
526+
]
527+
)]
521528
#[case::quoted_identifiers(
522529
scanner_test_case![
523530
" ",

0 commit comments

Comments
 (0)