Skip to content

Commit f10909a

Browse files
Extract common lexer code into helpers (#79214)
1 parent a3d9132 commit f10909a

File tree

4 files changed

+82
-73
lines changed

4 files changed

+82
-73
lines changed

src/Compilers/CSharp/Portable/Parser/AbstractLexer.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
using System;
66
using System.Collections.Generic;
7-
using Microsoft.CodeAnalysis.CSharp.Symbols;
8-
using Microsoft.CodeAnalysis.CSharp.Syntax;
97
using Microsoft.CodeAnalysis.Text;
108

119
namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax
@@ -21,6 +19,8 @@ protected AbstractLexer(SourceText text)
2119
this.TextWindow = new SlidingTextWindow(text);
2220
}
2321

22+
protected int LexemeStartPosition => this.TextWindow.LexemeStartPosition;
23+
2424
public virtual void Dispose()
2525
{
2626
this.TextWindow.Dispose();
@@ -131,9 +131,18 @@ protected XmlSyntaxDiagnosticInfo MakeError(int position, int width, XmlParseErr
131131

132132
private int GetLexemeOffsetFromPosition(int position)
133133
{
134-
return position >= TextWindow.LexemeStartPosition ? position - TextWindow.LexemeStartPosition : position;
134+
return position >= LexemeStartPosition ? position - LexemeStartPosition : position;
135135
}
136136

137+
protected string GetNonInternedLexemeText()
138+
=> TextWindow.GetText(intern: false);
139+
140+
protected string GetInternedLexemeText()
141+
=> TextWindow.GetText(intern: true);
142+
143+
protected int CurrentLexemeWidth
144+
=> this.TextWindow.Position - LexemeStartPosition;
145+
137146
protected static SyntaxDiagnosticInfo MakeError(ErrorCode code)
138147
{
139148
return new SyntaxDiagnosticInfo(code);

0 commit comments

Comments
 (0)