Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging #354

Merged
merged 23 commits into from
Dec 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5db0cc0
Merge pull request #350 from Luthetus/main
Luthetus Nov 28, 2024
5191834
Merge pull request #351 from Luthetus/beta
Luthetus Nov 28, 2024
059fcb8
Merge pull request #45 from Luthetus/staging
huntercfreeman Nov 28, 2024
423a25e
Update versions
huntercfreeman Nov 28, 2024
e2e166e
Goal: Track the OpenBraceToken and CloseBraceToken pairs that occur i…
huntercfreeman Dec 3, 2024
383253d
String interpolated, different color for the expressions
huntercfreeman Dec 4, 2024
d7ac96a
String interpolation: '{{'
huntercfreeman Dec 4, 2024
c389a7e
String interpolation: end with expression edge case
huntercfreeman Dec 4, 2024
5af27c7
Verbatim string
huntercfreeman Dec 4, 2024
518a1d6
LexStringRaw
huntercfreeman Dec 4, 2024
30327fd
LexStringEitherInterpolationAndOrVerbatim(...)
huntercfreeman Dec 4, 2024
c0629ff
interpolated raw progress
huntercfreeman Dec 4, 2024
665d03e
Single interpolation raw string case
huntercfreeman Dec 4, 2024
d1b45a4
Interpolation and raw mixtures
huntercfreeman Dec 4, 2024
50088b0
Raw string final content is interpolated bug fix
huntercfreeman Dec 4, 2024
75a7e04
Alternate escape character syntax highlighting (progress)
huntercfreeman Dec 4, 2024
5fd3647
Alternate colors for contiguous escape characters
huntercfreeman Dec 4, 2024
bd41102
List<TextEditorTextSpan> EscapeCharacterList instead of ImmutableArray
huntercfreeman Dec 5, 2024
401bd2a
All the speed issues were in 'CSharpBinder.Main.StartBinderSession(Re…
huntercfreeman Dec 5, 2024
9b80d11
Change solution wide re-render throttle
huntercfreeman Dec 5, 2024
40ad74a
Update README.md
huntercfreeman Dec 5, 2024
fba5a09
Fix: autocomplete with compiler service
huntercfreeman Dec 5, 2024
5efaef2
Merge pull request #353 from huntercfreeman/optimizations
Luthetus Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
LexStringEitherInterpolationAndOrVerbatim(...)
huntercfreeman committed Dec 4, 2024
commit 30327fdb97ca80194369e2f63c646567fa81fc21
118 changes: 65 additions & 53 deletions Source/Lib/CompilerServices/CSharp/LexerCase/CSharpLexer.cs
Original file line number Diff line number Diff line change
@@ -187,15 +187,47 @@ public override void Lex()
break;
case '$':
if (_stringWalker.NextCharacter == '"')
LexStringInterpolation(_stringWalker, _syntaxTokenList);
{
LexStringEitherInterpolationAndOrVerbatim(
_stringWalker,
_syntaxTokenList,
useInterpolation: true,
useVerbatim: false);
}
else if (_stringWalker.PeekCharacter(1) == '@' && _stringWalker.PeekCharacter(2) == '"')
{
LexStringEitherInterpolationAndOrVerbatim(
_stringWalker,
_syntaxTokenList,
useInterpolation: true,
useVerbatim: true);
}
else
{
LexerUtils.LexDollarSignToken(_stringWalker, _syntaxTokenList);
}
break;
case '@':
if (_stringWalker.NextCharacter == '"')
LexStringVerbatim(_stringWalker, _syntaxTokenList);
{
LexStringEitherInterpolationAndOrVerbatim(
_stringWalker,
_syntaxTokenList,
useInterpolation: false,
useVerbatim: true);
}
else if (_stringWalker.PeekCharacter(1) == '$' && _stringWalker.PeekCharacter(2) == '"')
{
LexStringEitherInterpolationAndOrVerbatim(
_stringWalker,
_syntaxTokenList,
useInterpolation: true,
useVerbatim: true);
}
else
{
LexerUtils.LexAtToken(_stringWalker, _syntaxTokenList);
}
break;
case ':':
LexerUtils.LexColonToken(_stringWalker, _syntaxTokenList);
@@ -225,21 +257,46 @@ public override void Lex()
_syntaxTokenList.Add(new EndOfFileToken(endOfFileTextSpan));
}

private void LexStringInterpolation(StringWalker stringWalker, List<ISyntaxToken> syntaxTokenList)
private void LexStringEitherInterpolationAndOrVerbatim(
StringWalker stringWalker,
List<ISyntaxToken> syntaxTokenList,
bool useInterpolation,
bool useVerbatim)
{
var entryPositionIndex = stringWalker.PositionIndex;

_ = stringWalker.ReadCharacter(); // Move past the '$' (dollar sign character)
if (useInterpolation)
_ = stringWalker.ReadCharacter(); // Move past the '$' (dollar sign character)
if (useVerbatim)
_ = stringWalker.ReadCharacter(); // Move past the '@' (at character)

_ = stringWalker.ReadCharacter(); // Move past the '"' (double quote character)

while (!stringWalker.IsEof)
{
if (stringWalker.CurrentCharacter == '\"')
{
_ = stringWalker.ReadCharacter();
break;
if (useVerbatim && stringWalker.NextCharacter == '\"')
{
if (_escapeCharacterList is not null)
{
_escapeCharacterList.Add(new TextEditorTextSpan(
stringWalker.PositionIndex,
stringWalker.PositionIndex + 2,
(byte)GenericDecorationKind.EscapeCharacter,
stringWalker.ResourceUri,
stringWalker.SourceText));
}

_ = stringWalker.ReadCharacter();
}
else
{
_ = stringWalker.ReadCharacter();
break;
}
}
else if (stringWalker.CurrentCharacter == '\\')
else if (!useVerbatim && stringWalker.CurrentCharacter == '\\')
{
if (_escapeCharacterList is not null)
{
@@ -254,7 +311,7 @@ private void LexStringInterpolation(StringWalker stringWalker, List<ISyntaxToken
// Presuming the escaped text is 2 characters, then read an extra character.
_ = stringWalker.ReadCharacter();
}
else if (stringWalker.CurrentCharacter == '{')
else if (useInterpolation && stringWalker.CurrentCharacter == '{')
{
if (stringWalker.NextCharacter == '{')
{
@@ -318,51 +375,6 @@ private void LexInterpolatedExpression(StringWalker stringWalker, List<ISyntaxTo
_ = stringWalker.ReadCharacter();
}

private void LexStringVerbatim(StringWalker stringWalker, List<ISyntaxToken> syntaxTokenList)
{
var entryPositionIndex = stringWalker.PositionIndex;

_ = stringWalker.ReadCharacter(); // Move past the '@' (at character)
_ = stringWalker.ReadCharacter(); // Move past the '"' (double quote character)

while (!stringWalker.IsEof)
{
if (stringWalker.CurrentCharacter == '\"')
{
if (stringWalker.NextCharacter == '\"')
{
if (_escapeCharacterList is not null)
{
_escapeCharacterList.Add(new TextEditorTextSpan(
stringWalker.PositionIndex,
stringWalker.PositionIndex + 2,
(byte)GenericDecorationKind.EscapeCharacter,
stringWalker.ResourceUri,
stringWalker.SourceText));
}

_ = stringWalker.ReadCharacter();
}
else
{
_ = stringWalker.ReadCharacter();
break;
}
}

_ = stringWalker.ReadCharacter();
}

var textSpan = new TextEditorTextSpan(
entryPositionIndex,
stringWalker.PositionIndex,
(byte)GenericDecorationKind.StringLiteral,
stringWalker.ResourceUri,
stringWalker.SourceText);

_syntaxTokenList.Add(new StringLiteralToken(textSpan));
}

private void LexStringRaw(StringWalker stringWalker, List<ISyntaxToken> syntaxTokenList)
{
var entryPositionIndex = stringWalker.PositionIndex;