Skip to content

Commit

Permalink
#57 - абстракция IStructure.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Stepami committed Aug 2, 2024
1 parent 8d2d18f commit 95d2b06
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Domain/HydraScript.Domain.FrontEnd/Lexer/ILexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace HydraScript.Domain.FrontEnd.Lexer;

public interface ILexer
{
public Structure Structure { get; }
public IStructure Structure { get; }

public List<Token> GetTokens(string text);
}
11 changes: 11 additions & 0 deletions src/Domain/HydraScript.Domain.FrontEnd/Lexer/IStructure.cs
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace HydraScript.Domain.FrontEnd.Lexer.Impl;

public class RegexLexer(Structure structure, ITextCoordinateSystemComputer computer) : ILexer, IEnumerable<Token>
public class RegexLexer(IStructure structure, ITextCoordinateSystemComputer computer) : ILexer, IEnumerable<Token>
{
private IReadOnlyList<int> _lines = [];
private string _text = "";

public Structure Structure { get; } = structure;
public IStructure Structure { get; } = structure;

public List<Token> GetTokens(string text)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using System.Text.RegularExpressions;
using HydraScript.Domain.FrontEnd.Lexer.TokenTypes;

namespace HydraScript.Domain.FrontEnd.Lexer;
namespace HydraScript.Domain.FrontEnd.Lexer.Impl;

public class Structure : IEnumerable<TokenType>
public class Structure : IStructure
{
public Structure(List<TokenType> types)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class LoggingLexer(
private readonly InputFile _inputFile = inputFile.Value;

[ExcludeFromCodeCoverage]
public Structure Structure => lexer.Structure;
public IStructure Structure => lexer.Structure;

public List<Token> GetTokens(string text)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using HydraScript.Domain.FrontEnd.Lexer;
using HydraScript.Domain.FrontEnd.Lexer.Impl;
using HydraScript.Domain.FrontEnd.Lexer.TokenTypes;

namespace HydraScript.Infrastructure;
Expand All @@ -14,7 +15,7 @@ internal static class StructureInstance
};

private static Structure? _instance;
public static Structure Get
public static IStructure Get
{
get
{
Expand Down
2 changes: 1 addition & 1 deletion tests/HydraScript.Tests/Unit/FrontEnd/StructureTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HydraScript.Domain.FrontEnd.Lexer;
using HydraScript.Domain.FrontEnd.Lexer.Impl;
using HydraScript.Domain.FrontEnd.Lexer.TokenTypes;
using Xunit;

Expand Down

0 comments on commit 95d2b06

Please sign in to comment.