Skip to content

Commit

Permalink
Fix SPARQL syntax to support internal dot characters
Browse files Browse the repository at this point in the history
  • Loading branch information
althonos committed Feb 25, 2024
1 parent e66b6df commit 4bed022
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/sparql.pest
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@ SPARQL_BlankNodeLabel = ${ "_:" ~ SPARQL_PnLocal }
SPARQL_PnameNs = ${ SPARQL_PnPrefix? ~ ":" }
SPARQL_PnameLn = ${ SPARQL_PnameNs ~ SPARQL_PnLocal }

SPARQL_PnPrefixDotEnding = @{ SPARQL_PnCharsBase ~ SPARQL_PnChars* ~ "." }
SPARQL_PnPrefix = @{ !SPARQL_PnPrefixDotEnding ~ SPARQL_PnCharsBase ~ SPARQL_PnChars* }
SPARQL_PnLocalDotEnding = @{ (SPARQL_PnCharsU | '0'..'9') ~ SPARQL_PnChars* ~ "." }
SPARQL_PnLocal = @{ !SPARQL_PnLocalDotEnding ~ (SPARQL_PnCharsU | '0'..'9') ~ SPARQL_PnChars* } // FIXME
// NOTE: In the SPARQL grammar a local identifier can contain or end with a
// semicolon, however this conflicts with most of the rules including
// several keyword terminals, so I made it so that the rule only accepts
// escaped semi-colons.
SPARQL_PnLocal = @{ (SPARQL_PnCharsU | ":" | ASCII_DIGIT | SPARQL_Plx) ~ (("." ~ (SPARQL_PnChars | SPARQL_Plx)) | SPARQL_PnChars | SPARQL_Plx)* }
SPARQL_PnPrefix = @{ SPARQL_PnCharsBase ~ (("." ~ SPARQL_PnChars) | SPARQL_PnChars)* }

SPARQL_PnChars = @{ SPARQL_PnCharsU | "-" | '0'..'9' | "\u{00B7}" | '\u{0300}'..'\u{036F}' | '\u{203F}'..'\u{2040}' }
SPARQL_PnChars = @{ SPARQL_PnCharsU | "-" | ASCII_DIGIT | "\u{00B7}" | '\u{0300}'..'\u{036F}' | '\u{203F}'..'\u{2040}' }
SPARQL_PnCharsU = @{ SPARQL_PnCharsBase | "_" }
SPARQL_PnCharsBase = @{
'A'..'Z' | 'a'..'z' | '\u{00C0}'..'\u{00D6}' | '\u{00D8}'..'\u{00F6}' | '\u{00F8}'..'\u{02FF}'
ASCII_ALPHA | '\u{00C0}'..'\u{00D6}' | '\u{00D8}'..'\u{00F6}' | '\u{00F8}'..'\u{02FF}'
| '\u{0370}'..'\u{037D}' | '\u{037F}'..'\u{1FFF}' | '\u{200C}'..'\u{200D}' | '\u{2070}'..'\u{218F}'
| '\u{2C00}'..'\u{2FEF}' | '\u{3001}'..'\u{D7FF}' | '\u{F900}'..'\u{FDCF}' | '\u{FDF0}'..'\u{FFFD}'
| '\u{10000}'..'\u{EFFFF}'
}

SPARQL_Plx = @{ SPARQL_Percent | SPARQL_PnLocalEsc }
SPARQL_Percent = @{ "%" ~ SPARQL_Hex ~ SPARQL_Hex }
SPARQL_Hex = @{ ASCII_HEX_DIGIT }

SPARQL_PnLocalEsc = @{ "\\" ~ SPARQL_PnLocalEscChar }
SPARQL_PnLocalEscChar = @{
"_" | "~" | "." | "-" | "!" | "$" | "&" | "\"" | "(" | ")" | "*" | "+" | "," | ";" | "=" | "/" | "?" | "#" | "@" | "%" | ":"
}

0 comments on commit 4bed022

Please sign in to comment.