Skip to content

Commit 95a3073

Browse files
committed
refactoring - removed json
1 parent 11ce578 commit 95a3073

File tree

18 files changed

+198
-252
lines changed

18 files changed

+198
-252
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
1313
<PackageVersion Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
1414
<PackageVersion Include="System.IO.Abstractions" Version="22.0.11" />
15+
<PackageVersion Include="System.Text.Json" Version="9.0.2" />
1516
<PackageVersion Include="Visitor.NET" Version="4.1.2" />
1617
<PackageVersion Include="Visitor.NET.AutoVisitableGen" Version="1.3.0" />
1718
</ItemGroup>

src/Domain/HydraScript.Domain.Constants/HydraScript.Domain.Constants.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<InternalsVisibleTo Include="HydraScript.Infrastructure.LexerRegexGenerator" />
9+
</ItemGroup>
10+
711
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// ReSharper disable once CheckNamespace
2+
namespace System.Runtime.CompilerServices;
3+
4+
// ReSharper disable once UnusedType.Global
5+
public static class IsExternalInit;

src/Domain/HydraScript.Domain.Constants/StringSyntaxAttribute.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
namespace HydraScript.Domain.Constants;
2+
3+
public static class TokenTypes
4+
{
5+
public record Dto(
6+
string Tag,
7+
string Pattern,
8+
int Priority,
9+
bool CanIgnore = false)
10+
{
11+
internal string GetNamedRegex() => $"(?<{Tag}>{Pattern})";
12+
}
13+
14+
public static IEnumerable<Dto> Stream
15+
{
16+
get
17+
{
18+
yield return new(
19+
Tag: "Comment",
20+
Pattern: "[/]{2}.*",
21+
Priority: 0,
22+
CanIgnore: true);
23+
24+
yield return new(
25+
Tag: "Ident",
26+
Pattern: "[a-zA-Z][a-zA-Z0-9]*",
27+
Priority: 50);
28+
29+
yield return new(
30+
Tag: "IntegerLiteral",
31+
Pattern: "[0-9]+",
32+
Priority: 3);
33+
34+
yield return new(
35+
Tag: "FloatLiteral",
36+
Pattern: "[0-9]+[.][0-9]+",
37+
Priority: 2);
38+
39+
yield return new(
40+
Tag: "NullLiteral",
41+
Pattern: "(?<![a-zA-Z0-9])(null)(?![a-zA-Z0-9])",
42+
Priority: 4);
43+
44+
yield return new(
45+
Tag: "BooleanLiteral",
46+
Pattern: "(?<![a-zA-Z0-9])(true|false)(?![a-zA-Z0-9])",
47+
Priority: 5);
48+
49+
yield return new(
50+
Tag: "StringLiteral",
51+
Pattern: """
52+
\"(\\.|[^"\\])*\"
53+
""",
54+
Priority: 6);
55+
56+
yield return new(
57+
Tag: "Keyword",
58+
Pattern:
59+
"(?<![a-zA-Z0-9])(let|const|function|if|else|while|break|continue|return|as|type)(?![a-zA-Z0-9])",
60+
Priority: 11);
61+
62+
yield return new(
63+
Tag: "Print",
64+
Pattern: "[>]{3}",
65+
Priority: 12);
66+
67+
yield return new(
68+
Tag: "Operator",
69+
Pattern: "[+]{1,2}|[-]|[*]|[/]|[%]|([!]|[=])[=]|([<]|[>])[=]?|[!]|[|]{2}|[&]{2}|[~]|[:]{2}",
70+
Priority: 13);
71+
72+
yield return new(
73+
Tag: "Comma",
74+
Pattern: "[,]",
75+
Priority: 100);
76+
77+
yield return new(
78+
Tag: "Dot",
79+
Pattern: "[.]",
80+
Priority: 105);
81+
82+
yield return new(
83+
Tag: "LeftCurl",
84+
Pattern: "[{]",
85+
Priority: 101);
86+
87+
yield return new(
88+
Tag: "RightCurl",
89+
Pattern: "[}]",
90+
Priority: 102);
91+
92+
yield return new(
93+
Tag: "LeftParen",
94+
Pattern: "[(]",
95+
Priority: 103);
96+
97+
yield return new(
98+
Tag: "RightParen",
99+
Pattern: "[)]",
100+
Priority: 104);
101+
102+
yield return new(
103+
Tag: "LeftBracket",
104+
Pattern: "[[]",
105+
Priority: 107);
106+
107+
yield return new(
108+
Tag: "RightBracket",
109+
Pattern: "[]]",
110+
Priority: 109);
111+
112+
yield return new(
113+
Tag: "Assign",
114+
Pattern: "[=]",
115+
Priority: 99);
116+
117+
yield return new(
118+
Tag: "QuestionMark",
119+
Pattern: "[?]",
120+
Priority: 90);
121+
122+
yield return new(
123+
Tag: "Colon",
124+
Pattern: "[:]",
125+
Priority: 91);
126+
127+
yield return new(
128+
Tag: "SemiColon",
129+
Pattern: "[;]",
130+
Priority: 92);
131+
}
132+
}
133+
}

src/Domain/HydraScript.Domain.Constants/TokenTypesJson.cs

Lines changed: 0 additions & 122 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using HydraScript.Domain.FrontEnd.Lexer.TokenTypes;
2+
3+
namespace HydraScript.Domain.FrontEnd.Lexer.Impl;
4+
5+
public class TokenTypesProvider : ITokenTypesProvider
6+
{
7+
public IEnumerable<TokenType> GetTokenTypes() =>
8+
Constants.TokenTypes.Stream
9+
.OrderBy(x => x.Priority)
10+
.Select(x => x.CanIgnore
11+
? new IgnorableType(x.Tag)
12+
: new TokenType(x.Tag));
13+
}

src/HydraScript/HydraScript.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111
<ItemGroup>
1212
<PackageReference Include="System.CommandLine" />
1313
<PackageReference Include="System.CommandLine.Hosting" />
14+
<PackageReference Include="System.Text.Json" />
1415
</ItemGroup>
1516

1617
<ItemGroup>
1718
<InternalsVisibleTo Include="HydraScript.IntegrationTests" />
1819
</ItemGroup>
1920

21+
<PropertyGroup>
22+
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
23+
</PropertyGroup>
24+
2025
</Project>

src/Infrastructure/HydraScript.Infrastructure.LexerRegexGenerator/DefaultTokenTypesJsonStringProvider.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using HydraScript.Domain.Constants;
2+
3+
namespace HydraScript.Infrastructure.LexerRegexGenerator;
4+
5+
internal class DefaultTokenTypesStreamProvider :
6+
ITokenTypesStreamProvider
7+
{
8+
public IEnumerable<TokenTypes.Dto> TokenTypesStream { get; } = TokenTypes.Stream;
9+
}

0 commit comments

Comments
 (0)