Skip to content

Commit

Permalink
Fixes an ambiguity with identifiers and keywords. (#32)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
almann authored Jun 4, 2021
1 parent d257e3e commit e08a7cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions partiql-parser/src/partiql.pest
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ StringContent = {
Identifier = { NonQuotedIdentifier | QuotedIdentifier }

NonQuotedIdentifier = @{
!Keyword ~ NonQuotedIdentifierStart ~ NonQuotedIdentifierCont*
!(Keyword) ~ NonQuotedIdentifierStart ~ NonQuotedIdentifierCont*
}

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

Keyword = { SqlKeyword | PartiqlKeyword }
Keyword = @{
(SqlKeyword | PartiqlKeyword) ~ !NonQuotedIdentifierCont
}

SqlKeyword = _{
Absolute_
Expand Down
9 changes: 8 additions & 1 deletion partiql-parser/src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ mod test {
"WHERE" => keyword("WHERE")
]
)]
#[case::some_keywords(
#[case::some_identifiers(
scanner_test_case![
"moo_cow_1999" => identifier("moo_cow_1999"),
" ",
Expand All @@ -518,6 +518,13 @@ mod test {
"$$$$" => identifier("$$$$")
]
)]
#[case::identifiers_with_keywords_in_them(
scanner_test_case![
"moowhere" => identifier("moowhere"),
" ",
"selecty" => identifier("selecty"),
]
)]
#[case::quoted_identifiers(
scanner_test_case![
" ",
Expand Down

0 comments on commit e08a7cf

Please sign in to comment.