SQL Syntax highlighter support (oracle dialect) for q-quoted string literals#295
Conversation
…iterals (introduced since Oracle 10 R2). Fixes issue TurboPack#294
There was a problem hiding this comment.
Pull request overview
Adds Oracle q-quoted (alternative quoting mechanism) string literal recognition to the SQL highlighter when SQLDialect = sqlOracle, fixing incorrect tokenization/highlighting for this syntax.
Changes:
- Introduces a dedicated range state (
rsOracleQQuoteString) and scanner (OracleQQuoteProc) to tokenizeq'<delim>...<closing-delim>'as a single string token. - Detects
q/Qquote starts in the identifier dispatch path and switches into the new q-quote parsing mode. - Persists the q-quote closing delimiter across line ranges by encoding it into
GetRange/SetRange.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| function TSynSQLSyn.GetRange: Pointer; | ||
| begin | ||
| Result := Pointer(fRange); | ||
| Result := Pointer((Ord(fRange) and $FF) or (Ord(FOracleQQuoteClosingDelimiter) shl 8)); | ||
| end; |
There was a problem hiding this comment.
The range state is being bit-packed into a Pointer using hard-coded masks/shifts ($FF and shl 8). Please introduce named constants (e.g., RangeMask/DelimiterShift) and add a brief comment documenting the encoding layout, so future range-state additions don’t accidentally break persistence across lines.
| procedure TSynSQLSyn.SetRange(Value: Pointer); | ||
| var | ||
| EncodedRange: NativeUInt; | ||
| begin | ||
| fRange := TRangeState(Value); | ||
| EncodedRange := NativeUInt(Value); | ||
| fRange := TRangeState(EncodedRange and $FF); | ||
| FOracleQQuoteClosingDelimiter := WideChar((EncodedRange shr 8) and $FFFF); |
There was a problem hiding this comment.
SetRange decodes the packed range using magic numbers ($FF, shr 8, $FFFF). Consider centralizing this encode/decode logic (shared constants or small helpers) and documenting the expected bit widths; otherwise expanding TRangeState beyond 0..255 would silently corrupt the restored range.
This is a screenshot of TSynEdit with TSynSQLSyn (with Dialect=sqlOracle) displaying the correct string literals highlighting for q-quoted string literals after having applied my fix
this fixes issue #294 I just reported: in the issue report there is a screenshot of the current behavior of the highlighter without my fix and a detailed description of the oracle syntax being supported
Thank you and have a nice day