@@ -41,12 +41,24 @@ macro_rules! define_keywords {
4141 ( $(
4242 $ident: ident $( = $string_keyword: expr) ?
4343 ) ,* ) => {
44- $( kw_def!( $ident $( = $string_keyword) ?) ; ) *
44+ #[ derive( Debug , Clone , Copy , PartialEq , PartialOrd , Eq , Ord ) ]
45+ #[ allow( non_camel_case_types) ]
46+ pub enum Keyword {
47+ NoKeyword ,
48+ $( $ident) ,*
49+ }
4550
51+ pub const ALL_KEYWORDS_INDEX : & [ Keyword ] = & [
52+ $( Keyword :: $ident) ,*
53+ ] ;
54+
55+ $( kw_def!( $ident $( = $string_keyword) ?) ; ) *
4656 pub const ALL_KEYWORDS : & [ & str ] = & [
4757 $( $ident) ,*
4858 ] ;
49- }
59+
60+ } ;
61+
5062}
5163
5264// The following keywords should be sorted to be able to match using binary search
@@ -434,20 +446,52 @@ define_keywords!(
434446
435447/// These keywords can't be used as a table alias, so that `FROM table_name alias`
436448/// can be parsed unambiguously without looking ahead.
437- pub const RESERVED_FOR_TABLE_ALIAS : & [ & str ] = & [
449+ pub const RESERVED_FOR_TABLE_ALIAS : & [ Keyword ] = & [
438450 // Reserved as both a table and a column alias:
439- WITH , SELECT , WHERE , GROUP , HAVING , ORDER , TOP , LIMIT , OFFSET , FETCH , UNION , EXCEPT , INTERSECT ,
451+ Keyword :: WITH ,
452+ Keyword :: SELECT ,
453+ Keyword :: WHERE ,
454+ Keyword :: GROUP ,
455+ Keyword :: HAVING ,
456+ Keyword :: ORDER ,
457+ Keyword :: TOP ,
458+ Keyword :: LIMIT ,
459+ Keyword :: OFFSET ,
460+ Keyword :: FETCH ,
461+ Keyword :: UNION ,
462+ Keyword :: EXCEPT ,
463+ Keyword :: INTERSECT ,
440464 // Reserved only as a table alias in the `FROM`/`JOIN` clauses:
441- ON , JOIN , INNER , CROSS , FULL , LEFT , RIGHT , NATURAL , USING ,
465+ Keyword :: ON ,
466+ Keyword :: JOIN ,
467+ Keyword :: INNER ,
468+ Keyword :: CROSS ,
469+ Keyword :: FULL ,
470+ Keyword :: LEFT ,
471+ Keyword :: RIGHT ,
472+ Keyword :: NATURAL ,
473+ Keyword :: USING ,
442474 // for MSSQL-specific OUTER APPLY (seems reserved in most dialects)
443- OUTER ,
475+ Keyword :: OUTER ,
444476] ;
445477
446478/// Can't be used as a column alias, so that `SELECT <expr> alias`
447479/// can be parsed unambiguously without looking ahead.
448- pub const RESERVED_FOR_COLUMN_ALIAS : & [ & str ] = & [
480+ pub const RESERVED_FOR_COLUMN_ALIAS : & [ Keyword ] = & [
449481 // Reserved as both a table and a column alias:
450- WITH , SELECT , WHERE , GROUP , HAVING , ORDER , LIMIT , OFFSET , FETCH , UNION , EXCEPT , INTERSECT ,
451- // Reserved only as a column alias in the `SELECT` clause:
452- FROM ,
482+ Keyword :: WITH ,
483+ Keyword :: SELECT ,
484+ Keyword :: WHERE ,
485+ Keyword :: GROUP ,
486+ Keyword :: HAVING ,
487+ Keyword :: ORDER ,
488+ Keyword :: TOP ,
489+ Keyword :: LIMIT ,
490+ Keyword :: OFFSET ,
491+ Keyword :: FETCH ,
492+ Keyword :: UNION ,
493+ Keyword :: EXCEPT ,
494+ Keyword :: INTERSECT ,
495+ // Reserved only as a column alias in the `SELECT` clause
496+ Keyword :: FROM ,
453497] ;
0 commit comments