@@ -41,6 +41,12 @@ public void Reset()
4141 _trailingComments = null ;
4242 }
4343
44+ internal RuleApplication GetLiteralAt ( ParsePosition position )
45+ {
46+ var col = GetLine ( position . Line ) ? . GetOrCreateColumn ( position . Col ) ;
47+ return col ? . Applications . Values . FirstOrDefault ( r => r . Rule . IsLiteral && r . IsPositive ) ;
48+ }
49+
4450 /// <summary>
4551 /// Gets the position of the next token, starting from the given position
4652 /// </summary>
@@ -49,7 +55,7 @@ public void Reset()
4955 public ParsePosition NextTokenPosition ( ParsePosition position )
5056 {
5157 var line = position . Line ;
52- var col = position . Col + 1 ;
58+ var col = position . Col ;
5359 while ( line < _memoTable . Count )
5460 {
5561 var memoLine = _memoTable [ line ] ;
@@ -398,7 +404,12 @@ public RuleApplication Match(ParseContext context)
398404 public void Apply ( TextEdit edit )
399405 {
400406 var refreshLineIndices = false ;
401- for ( int i = 0 ; i <= edit . End . Line && i < _memoTable . Count ; i ++ )
407+ var lastEffectiveLength = edit . End . Line ;
408+ if ( edit . End . Col == 0 && edit . NewText != null && edit . NewText . Length > 0 && edit . NewText [ edit . NewText . Length - 1 ] . Length == 0 )
409+ {
410+ lastEffectiveLength -- ;
411+ }
412+ for ( int i = 0 ; i <= lastEffectiveLength && i < _memoTable . Count ; i ++ )
402413 {
403414 var line = GetLine ( i ) ;
404415
@@ -592,5 +603,17 @@ private static void MoveOverWhitespace(ParseContext context, ref ParsePosition p
592603 }
593604 position = new ParsePosition ( lineNo , 0 ) ;
594605 }
606+
607+ /// <summary>
608+ /// Determines whether the given rule application is obsoleted
609+ /// </summary>
610+ /// <param name="ruleApplication">the rule application to check</param>
611+ /// <returns>true, if the rule application is on a line that has been obsoleted</returns>
612+ /// <exception cref="NotImplementedException"></exception>
613+ public bool IsObsoleted ( RuleApplication ruleApplication )
614+ {
615+ var line = ruleApplication . Line ;
616+ return line == null || ( line . LineNo >= _memoTable . Count || _memoTable [ line . LineNo ] != line ) ;
617+ }
595618 }
596619}
0 commit comments