@@ -16,6 +16,7 @@ public class TerminalGenerator : IIncrementalGenerator
1616 {
1717 private const string RegexAttrName = "Regex" ;
1818 private const string RegexAttrFullName = RegexAttrName + "Attribute" ;
19+ private const string Any = "true /* . (RegexAnyChar) */" ;
1920
2021 public void Initialize ( IncrementalGeneratorInitializationContext context )
2122 {
@@ -180,14 +181,10 @@ private string GenerateDfaCode(DfaState start, int startIndent)
180181 var currentState = {{ start . Id }} ;
181182 var lastAccept = -1;
182183 {{ ( start . IsFinal ? "lastAccept = currentPos;" : "" ) }}
183- //System.Diagnostics.Debugger.Launch();
184184
185185 while (currentPos <= length)
186186 {
187187 var c = currentPos < length ? input[currentPos] : '\0';
188- if (c == '\0')
189- {
190- }
191188 var transitionFound = false;
192189 switch (currentState)
193190 {
@@ -198,7 +195,6 @@ private string GenerateDfaCode(DfaState start, int startIndent)
198195 sb . AppendLine ( $$ """
199196 case {{ state . Id }} :
200197 {{ generateStateTransitions ( state , indent ) }}
201- break;
202198 """ ) ;
203199
204200 sb . AppendLine ( $$ """
@@ -218,10 +214,11 @@ private string GenerateDfaCode(DfaState start, int startIndent)
218214 static string generateStateTransitions ( DfaState state , IndentHelper indent )
219215 {
220216 var sb = new StringBuilder ( ) ;
221-
217+ var hasAny = false ;
222218 foreach ( var transition in state . Transitions )
223219 {
224220 var condition = generateTransitionCondition ( transition . Condition ) ;
221+ hasAny |= condition == Any ;
225222 sb . AppendLine ( $$ """
226223 if ({{ condition }} )
227224 {
@@ -233,7 +230,15 @@ static string generateStateTransitions(DfaState state, IndentHelper indent)
233230 }
234231 """ ) ;
235232 }
236- sb . Append ( "transitionFound = false;" ) ;
233+
234+ if ( ! hasAny )
235+ {
236+ sb . Append ( """
237+ transitionFound = false;
238+ break;
239+ """ ) ;
240+ }
241+
237242 return indent . Apply ( sb ) . ToString ( ) ;
238243
239244 static string generateTransitionCondition ( RegexNode node )
@@ -242,7 +247,7 @@ static string generateTransitionCondition(RegexNode node)
242247 {
243248 RegexEndOfLine x => $@ "c == '\0' /* { x } */",
244249 RegexChar rc => $ """ c == '{ EscapeChar ( rc . Value ) } ' /* { rc } */""" ,
245- RegexAnyChar => "true /* RegexAnyChar */" ,
250+ RegexAnyChar => Any ,
246251 NegatedCharClassGroup rcc when rcc . ToString ( ) == $@ "[^[\n]]" => $@ "c is not '\n' and not '\0' /* { rcc } */",
247252 RangesCharClass rcc => GenerateRangeCondition ( rcc ) ,
248253 WordCharClass wcc => $ """ { ( wcc . Negated ? "!" : "" ) } (char.IsLetterOrDigit(c) || c == '_')""" ,
0 commit comments