-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #57 - абстракция IStructure.cs * #57 - token types provider * #57 - DI refactoring * #57 - json highlight * #57 - абстракция IGeneratedRegexContainer * fix * #57 - SG project * #57 - fix SG launch * #57 - tests * #57 - удаление динамического построения RegEx * #57 - убрал лишнее из TokenType * #57 - тест на проверку подстановки * fix
- Loading branch information
Showing
39 changed files
with
479 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/Domain/HydraScript.Domain.FrontEnd/Lexer/IGeneratedRegexContainer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Text.RegularExpressions; | ||
|
||
namespace HydraScript.Domain.FrontEnd.Lexer; | ||
|
||
public interface IGeneratedRegexContainer | ||
{ | ||
public static abstract Regex GetRegex(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/Domain/HydraScript.Domain.FrontEnd/Lexer/IStructure.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Text.RegularExpressions; | ||
using HydraScript.Domain.FrontEnd.Lexer.TokenTypes; | ||
|
||
namespace HydraScript.Domain.FrontEnd.Lexer; | ||
|
||
public interface IStructure : IEnumerable<TokenType> | ||
{ | ||
public Regex Regex { get; } | ||
|
||
public TokenType FindByTag(string tag); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Domain/HydraScript.Domain.FrontEnd/Lexer/ITokenTypesProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using HydraScript.Domain.FrontEnd.Lexer.TokenTypes; | ||
|
||
namespace HydraScript.Domain.FrontEnd.Lexer; | ||
|
||
public interface ITokenTypesProvider | ||
{ | ||
IEnumerable<TokenType> GetTokenTypes(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Domain/HydraScript.Domain.FrontEnd/Lexer/Impl/Structure.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Collections; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using HydraScript.Domain.FrontEnd.Lexer.TokenTypes; | ||
|
||
namespace HydraScript.Domain.FrontEnd.Lexer.Impl; | ||
|
||
public class Structure<TContainer>(ITokenTypesProvider provider) : IStructure | ||
where TContainer : IGeneratedRegexContainer | ||
{ | ||
private Dictionary<string, TokenType> Types { get; } = provider.GetTokenTypes() | ||
.Concat([new EndOfProgramType(), new ErrorType()]) | ||
.ToDictionary(x => x.Tag); | ||
|
||
public Regex Regex { get; } = TContainer.GetRegex(); | ||
|
||
public TokenType FindByTag(string tag) => | ||
Types[tag]; | ||
|
||
public override string ToString() => | ||
new StringBuilder() | ||
.AppendJoin('\n', this) | ||
.ToString(); | ||
|
||
public IEnumerator<TokenType> GetEnumerator() => | ||
Types.Values.GetEnumerator(); | ||
|
||
[ExcludeFromCodeCoverage] | ||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} |
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
src/Domain/HydraScript.Domain.FrontEnd/Lexer/TokenTypes/EndOfProgramType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
namespace HydraScript.Domain.FrontEnd.Lexer.TokenTypes; | ||
|
||
internal record EndOfProgramType() : TokenType("EOP", "", int.MaxValue - 1) | ||
internal record EndOfProgramType() : TokenType(EopTag) | ||
{ | ||
public override bool EndOfProgram() => true; | ||
public const string EopTag = "EOP"; | ||
} |
2 changes: 1 addition & 1 deletion
2
src/Domain/HydraScript.Domain.FrontEnd/Lexer/TokenTypes/ErrorType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
namespace HydraScript.Domain.FrontEnd.Lexer.TokenTypes; | ||
|
||
internal record ErrorType() : TokenType("ERROR", @"\S+", int.MaxValue) | ||
internal record ErrorType() : TokenType("ERROR") | ||
{ | ||
public override bool Error() => true; | ||
} |
3 changes: 1 addition & 2 deletions
3
src/Domain/HydraScript.Domain.FrontEnd/Lexer/TokenTypes/IgnorableType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
namespace HydraScript.Domain.FrontEnd.Lexer.TokenTypes; | ||
|
||
public record IgnorableType(string Tag, string Pattern, int Priority) | ||
: TokenType(Tag, Pattern, Priority) | ||
public record IgnorableType(string Tag) : TokenType(Tag) | ||
{ | ||
public override bool CanIgnore() => true; | ||
} |
8 changes: 2 additions & 6 deletions
8
src/Domain/HydraScript.Domain.FrontEnd/Lexer/TokenTypes/TokenType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
namespace HydraScript.Domain.FrontEnd.Lexer.TokenTypes; | ||
|
||
public record TokenType(string Tag, string Pattern, int Priority) | ||
public record TokenType(string Tag) | ||
{ | ||
public virtual bool CanIgnore() => false; | ||
|
||
public virtual bool EndOfProgram() => false; | ||
|
||
public virtual bool Error() => false; | ||
|
||
public string GetNamedRegex() => $"(?<{Tag}>{Pattern})"; | ||
|
||
public override string ToString() => Tag; | ||
public sealed override string ToString() => Tag; | ||
} |
3 changes: 3 additions & 0 deletions
3
src/Domain/HydraScript.Domain.FrontEnd/Lexer/TokenTypesJson.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
....Infrastructure.LexerRegexGenerator/HydraScript.Infrastructure.LexerRegexGenerator.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
|
||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> | ||
<IsRoslynComponent>true</IsRoslynComponent> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0"/> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0"/> | ||
<PackageReference Include="System.Text.Json" Version="8.0.4"> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
49 changes: 49 additions & 0 deletions
49
...rastructure/HydraScript.Infrastructure.LexerRegexGenerator/PatternGenerator.TokenTypes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace HydraScript.Infrastructure.LexerRegexGenerator; | ||
|
||
public partial class PatternGenerator | ||
{ | ||
private static readonly JsonSerializerOptions JsonSerializerOptions = new() | ||
{ | ||
Converters = { new TokenTypesReadConverter() } | ||
}; | ||
|
||
private record TokenType( | ||
string Tag, | ||
string Pattern, | ||
int Priority) | ||
{ | ||
public string GetNamedRegex() => $"(?<{Tag}>{Pattern})"; | ||
} | ||
|
||
[ExcludeFromCodeCoverage] | ||
private class TokenTypesReadConverter : JsonConverter<IEnumerable<TokenType>> | ||
{ | ||
public override IEnumerable<TokenType> Read( | ||
ref Utf8JsonReader reader, | ||
Type typeToConvert, | ||
JsonSerializerOptions options) | ||
{ | ||
var root = JsonElement.ParseValue(ref reader); | ||
var tokenTypes = root.EnumerateArray() | ||
.Select(element => | ||
{ | ||
var tag = element.GetProperty("tag").GetString()!; | ||
var pattern = element.GetProperty("pattern").GetString()!; | ||
var priority = element.GetProperty("priority").GetInt32(); | ||
|
||
return new TokenType(tag, pattern, priority); | ||
}) | ||
.OrderBy(x => x.Priority); | ||
return tokenTypes; | ||
} | ||
|
||
public override void Write( | ||
Utf8JsonWriter writer, | ||
IEnumerable<TokenType> value, | ||
JsonSerializerOptions options) => throw new NotSupportedException(); | ||
} | ||
} |
Oops, something went wrong.