feat: give column data types a dedicated syntax-highlight colour
Both Node::Ident and Word carried a highlight_override field, and both were dead — the walker driver discarded the Ident's and walk_word hardcoded Keyword. So column types (int, serial, …) rendered identically to table/column names. Wire both overrides through, and add a dedicated HighlightClass::Type with its own theme colour (tok_type), distinct from keyword-purple and identifier-teal. The three type Ident slots opt in, so canonical types and the advanced-mode single-word SQL aliases (float, varchar, …) render as types; the two-word `double precision` alias opts in via a new Word::type_keyword constructor. ADR-0022 Amendment 4.
This commit is contained in:
@@ -47,6 +47,12 @@ use crate::dsl::walker::outcome::MatchedPath;
|
||||
pub enum HighlightClass {
|
||||
Keyword,
|
||||
Identifier,
|
||||
/// Column data-type keyword (`int`, `serial`, `text`, …).
|
||||
/// Distinct from `Keyword` and `Identifier` so learners can
|
||||
/// tell "this is a type" from a clause keyword or a name they
|
||||
/// invented (ADR-0022 Amendment 4). Assigned via a type slot's
|
||||
/// `highlight_override`, not by byte shape.
|
||||
Type,
|
||||
Number,
|
||||
String,
|
||||
Punct,
|
||||
@@ -191,6 +197,21 @@ impl Word {
|
||||
}
|
||||
}
|
||||
|
||||
/// A keyword that highlights as a column **type** rather than a
|
||||
/// clause keyword (ADR-0022 Amendment 4). The one user today is
|
||||
/// the two-word `double precision` SQL alias (ADR-0035 §3): it
|
||||
/// is matched as keyword tokens, not an `IdentSource::Types`
|
||||
/// `Ident`, so without this it would render keyword-coloured
|
||||
/// while its single-word synonyms (`float`, `real`) render as
|
||||
/// types.
|
||||
pub const fn type_keyword(primary: &'static str) -> Self {
|
||||
Self {
|
||||
primary,
|
||||
aliases: &[],
|
||||
highlight_override: Some(HighlightClass::Type),
|
||||
}
|
||||
}
|
||||
|
||||
/// Case-insensitive match against the primary or any alias.
|
||||
pub fn matches(&self, candidate: &str) -> bool {
|
||||
if candidate.eq_ignore_ascii_case(self.primary) {
|
||||
|
||||
Reference in New Issue
Block a user