@@ -188,7 +188,7 @@ private bool TryParseCreate(ParserContext context)
188188 {
189189 declaredMaxLength = numericValue . AsInt32 ;
190190 }
191- else if ( lengthToken is UnquotedString unquoted && unquoted . Span . Equals ( "MAX" , StringComparison . OrdinalIgnoreCase ) )
191+ else if ( context . MatchContextual ( ContextualKeyword . Max ) )
192192 {
193193 throw new NotSupportedException ( $ "{ type } (MAX) and other LOB types aren't modeled yet.") ;
194194 }
@@ -492,7 +492,7 @@ private static SimulatedStatementOutcome ProcessHeapInsert(HeapTable destination
492492 /// <param name="sourceColumnNames">For MERGE only: the source alias's column names. <see langword="null"/> for plain INSERT.</param>
493493 private static OutputProjection ? TryParseOutputClause ( ParserContext context , HeapTable destinationTable , ( string SourceAlias , string [ ] SourceColumns , SqlType [ ] SourceTypes ) ? sourceColumnNames )
494494 {
495- if ( context . Token is not UnquotedString unquoted || ! unquoted . Span . Equals ( "OUTPUT" , StringComparison . OrdinalIgnoreCase ) )
495+ if ( ! context . MatchContextual ( ContextualKeyword . Output ) )
496496 return null ;
497497
498498 var expressions = new List < Expression > ( ) ;
@@ -628,7 +628,8 @@ private static SimulatedStatementOutcome ParseMerge(ParserContext context)
628628 ? table
629629 : throw SimulatedSqlException . InvalidObjectName ( destinationTableToken ) ;
630630
631- if ( context . GetNextRequired ( ) is not UnquotedString usingKw || ! usingKw . Span . Equals ( "USING" , StringComparison . OrdinalIgnoreCase ) )
631+ context . MoveNextRequired ( ) ;
632+ if ( ! context . MatchContextual ( ContextualKeyword . Using ) )
632633 throw SimulatedSqlException . SyntaxErrorNear ( context ) ;
633634
634635 if ( context . GetNextRequired ( ) is not Operator { Character : '(' } )
@@ -694,7 +695,7 @@ private static SimulatedStatementOutcome ParseMerge(ParserContext context)
694695 if ( context . Token is ReservedKeyword { Keyword : Keyword . Not } )
695696 {
696697 context . MoveNextRequired ( ) ;
697- if ( context . Token is not UnquotedString matchedKw || ! matchedKw . Span . Equals ( "MATCHED" , StringComparison . OrdinalIgnoreCase ) )
698+ if ( ! context . MatchContextual ( ContextualKeyword . Matched ) )
698699 throw SimulatedSqlException . SyntaxErrorNear ( context ) ;
699700 if ( context . GetNextRequired ( ) is not ReservedKeyword { Keyword : Keyword . Then } )
700701 throw SimulatedSqlException . SyntaxErrorNear ( context ) ;
@@ -750,7 +751,7 @@ private static SimulatedStatementOutcome ParseMerge(ParserContext context)
750751 {
751752 context . MoveNextOptional ( ) ;
752753 }
753- if ( context . Token is UnquotedString tail && ! tail . Span . Equals ( "OUTPUT" , StringComparison . OrdinalIgnoreCase ) )
754+ if ( context . Token is UnquotedString && ! context . MatchContextual ( ContextualKeyword . Output ) )
754755 context . MoveNextOptional ( ) ;
755756 }
756757 }
@@ -1080,7 +1081,7 @@ private bool TryParseAlter(ParserContext context)
10801081 return false ;
10811082
10821083 var afterDatabase = context . GetNextRequired ( ) ;
1083- if ( afterDatabase is UnquotedString unquoted && unquoted . Span . Equals ( "SCOPED" , StringComparison . OrdinalIgnoreCase ) )
1084+ if ( context . MatchContextual ( ContextualKeyword . Scoped ) )
10841085 return TryParseAlterDatabaseScopedConfiguration ( context ) ;
10851086
10861087 // Otherwise a database name (or CURRENT). The simulator has one
@@ -1094,10 +1095,8 @@ private bool TryParseAlterDatabaseSet(ParserContext context)
10941095 if ( context . GetNextRequired ( ) is not ReservedKeyword { Keyword : Keyword . Set } )
10951096 return false ;
10961097
1097- if ( context . GetNextRequired ( ) is not UnquotedString option )
1098- return false ;
1099-
1100- if ( ! option . Span . Equals ( "COMPATIBILITY_LEVEL" , StringComparison . OrdinalIgnoreCase ) )
1098+ context . MoveNextRequired ( ) ;
1099+ if ( ! context . MatchContextual ( ContextualKeyword . Compatibility_Level ) )
11011100 return false ;
11021101
11031102 if ( context . GetNextRequired ( ) is not Operator { Character : '=' } )
@@ -1116,19 +1115,15 @@ private bool TryParseAlterDatabaseSet(ParserContext context)
11161115
11171116 private bool TryParseAlterDatabaseScopedConfiguration ( ParserContext context )
11181117 {
1119- if ( context . GetNextRequired ( ) is not UnquotedString configToken
1120- || ! configToken . Span . Equals ( "CONFIGURATION" , StringComparison . OrdinalIgnoreCase ) )
1121- {
1118+ context . MoveNextRequired ( ) ;
1119+ if ( ! context . MatchContextual ( ContextualKeyword . Configuration ) )
11221120 return false ;
1123- }
11241121
11251122 if ( context . GetNextRequired ( ) is not ReservedKeyword { Keyword : Keyword . Set } )
11261123 return false ;
11271124
1128- if ( context . GetNextRequired ( ) is not UnquotedString option )
1129- return false ;
1130-
1131- if ( ! option . Span . Equals ( "VERBOSE_TRUNCATION_WARNINGS" , StringComparison . OrdinalIgnoreCase ) )
1125+ context . MoveNextRequired ( ) ;
1126+ if ( ! context . MatchContextual ( ContextualKeyword . Verbose_Truncation_Warnings ) )
11321127 return false ;
11331128
11341129 if ( context . GetNextRequired ( ) is not Operator { Character : '=' } )
@@ -1149,16 +1144,14 @@ private bool TryParseAlterDatabaseScopedConfiguration(ParserContext context)
11491144 /// </summary>
11501145 private bool TryParseDbcc ( ParserContext context )
11511146 {
1152- if ( context . GetNextRequired ( ) is not UnquotedString action )
1153- return false ;
1154-
1147+ context . MoveNextRequired ( ) ;
11551148 bool turningOn ;
1156- if ( action . Span . Equals ( "TRACEON" , StringComparison . OrdinalIgnoreCase ) )
1157- turningOn = true ;
1158- else if ( action . Span . Equals ( "TRACEOFF" , StringComparison . OrdinalIgnoreCase ) )
1159- turningOn = false ;
1160- else
1161- return false ;
1149+ switch ( context . AsContextual ( ) )
1150+ {
1151+ case ContextualKeyword . TraceOn : turningOn = true ; break ;
1152+ case ContextualKeyword . TraceOff : turningOn = false ; break ;
1153+ default : return false ;
1154+ }
11621155
11631156 if ( context . GetNextRequired ( ) is not Operator { Character : '(' } )
11641157 return false ;
0 commit comments