Skip to content

Commit a9cc90d

Browse files
authored
Refactoring/constants (#140) +semver:none
* mass nuget up * fluent assertions pre-license version * upd nuget 2 * Latest language * constants project * remove not used package * small improvement * refactoring - removed json * #139 - property * remove GetNamedRegex func
1 parent 3c8c3d8 commit a9cc90d

34 files changed

+294
-316
lines changed

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
7+
<LangVersion>latest</LangVersion>
78
</PropertyGroup>
89

910
<PropertyGroup>

Directory.Packages.props

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<Project>
2-
<ItemGroup>
3-
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
4-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
5-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0" />
6-
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
7-
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
8-
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
9-
<PackageVersion Include="Scrutor" Version="4.2.2" />
10-
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
11-
<PackageVersion Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
12-
<PackageVersion Include="System.IO.Abstractions" Version="21.0.29" />
13-
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
14-
<PackageVersion Include="Visitor.NET" Version="4.1.2" />
15-
<PackageVersion Include="Visitor.NET.AutoVisitableGen" Version="1.3.0" />
16-
</ItemGroup>
2+
<ItemGroup>
3+
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
4+
<PrivateAssets>all</PrivateAssets>
5+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
6+
</PackageVersion>
7+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" />
8+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.2" />
9+
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
10+
<PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.2" />
11+
<PackageVersion Include="Scrutor" Version="6.0.1" />
12+
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
13+
<PackageVersion Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
14+
<PackageVersion Include="System.IO.Abstractions" Version="22.0.11" />
15+
<PackageVersion Include="System.Text.Json" Version="9.0.2" />
16+
<PackageVersion Include="Visitor.NET" Version="4.1.2" />
17+
<PackageVersion Include="Visitor.NET.AutoVisitableGen" Version="1.3.0" />
18+
</ItemGroup>
1719
</Project>

ExtendedJavaScriptSubset.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HydraScript.Infrastructure.
100100
EndProject
101101
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HydraScript.Infrastructure.LexerRegexGenerator.UnitTests", "tests\HydraScript.Infrastructure.LexerRegexGenerator.UnitTests\HydraScript.Infrastructure.LexerRegexGenerator.UnitTests.csproj", "{829111AD-4A5C-4B3D-AC28-208309CE10D6}"
102102
EndProject
103+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HydraScript.Domain.Constants", "src\Domain\HydraScript.Domain.Constants\HydraScript.Domain.Constants.csproj", "{E3E558A3-1999-48F9-B53D-2E583C18F000}"
104+
EndProject
103105
Global
104106
GlobalSection(SolutionConfigurationPlatforms) = preSolution
105107
Debug|Any CPU = Debug|Any CPU
@@ -150,6 +152,10 @@ Global
150152
{829111AD-4A5C-4B3D-AC28-208309CE10D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
151153
{829111AD-4A5C-4B3D-AC28-208309CE10D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
152154
{829111AD-4A5C-4B3D-AC28-208309CE10D6}.Release|Any CPU.Build.0 = Release|Any CPU
155+
{E3E558A3-1999-48F9-B53D-2E583C18F000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
156+
{E3E558A3-1999-48F9-B53D-2E583C18F000}.Debug|Any CPU.Build.0 = Debug|Any CPU
157+
{E3E558A3-1999-48F9-B53D-2E583C18F000}.Release|Any CPU.ActiveCfg = Release|Any CPU
158+
{E3E558A3-1999-48F9-B53D-2E583C18F000}.Release|Any CPU.Build.0 = Release|Any CPU
153159
EndGlobalSection
154160
GlobalSection(NestedProjects) = preSolution
155161
{54CBE5A7-3C3E-44ED-B877-7B08A818083B} = {86CF2A2F-4DFE-48E7-B062-EF824730916A}
@@ -169,5 +175,6 @@ Global
169175
{1CE98127-3027-4BD4-AAA3-63A589B09E73} = {3F131901-A9EC-451A-B7E9-726887CFE5FB}
170176
{74D1495B-12A4-4E1A-ABE0-93029ECDC5FE} = {B7DDF6C9-B67C-430A-948A-A380EF68DEF1}
171177
{829111AD-4A5C-4B3D-AC28-208309CE10D6} = {3F131901-A9EC-451A-B7E9-726887CFE5FB}
178+
{E3E558A3-1999-48F9-B53D-2E583C18F000} = {F0FC6D23-F932-4C11-8D0F-07894FC61511}
172179
EndGlobalSection
173180
EndGlobal

src/Application/HydraScript.Application.CodeGeneration/Visitors/InstructionProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using HydraScript.Domain.BackEnd.Impl.Instructions.WithAssignment;
55
using HydraScript.Domain.BackEnd.Impl.Instructions.WithJump;
66
using HydraScript.Domain.BackEnd.Impl.Values;
7+
using HydraScript.Domain.Constants;
78
using HydraScript.Domain.FrontEnd.Parser;
89
using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes;
910
using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Declarations.AfterTypesAreLoaded;
@@ -82,8 +83,8 @@ public AddressedInstructions Visit(InsideStatementJump visitable)
8283
{
8384
var jumpType = visitable.Keyword switch
8485
{
85-
InsideStatementJump.Break => InsideStatementJumpType.Break,
86-
InsideStatementJump.Continue => InsideStatementJumpType.Continue,
86+
InsideStatementJumpKeyword.Break => InsideStatementJumpType.Break,
87+
InsideStatementJumpKeyword.Continue => InsideStatementJumpType.Continue,
8788
_ => throw new ArgumentOutOfRangeException(
8889
nameof(visitable.Keyword), visitable.Keyword,
8990
"Unsupported keyword inside loop")

src/Application/HydraScript.Application.StaticAnalysis/Visitors/SemanticChecker.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using HydraScript.Application.StaticAnalysis.Exceptions;
2+
using HydraScript.Domain.Constants;
23
using HydraScript.Domain.FrontEnd.Parser;
34
using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes;
45
using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Declarations;
@@ -105,18 +106,18 @@ public Type Visit(InsideStatementJump visitable)
105106
{
106107
switch (visitable.Keyword)
107108
{
108-
case InsideStatementJump.Break:
109+
case InsideStatementJumpKeyword.Break:
109110
if (!(visitable.ChildOf<IfStatement>() || visitable.ChildOf<WhileStatement>()))
110111
throw new OutsideOfStatement(
111112
visitable.Segment,
112-
keyword: InsideStatementJump.Break,
113+
visitable.Keyword,
113114
statement: "if|while");
114115
break;
115-
case InsideStatementJump.Continue:
116+
case InsideStatementJumpKeyword.Continue:
116117
if (!visitable.ChildOf<WhileStatement>())
117118
throw new OutsideOfStatement(
118119
visitable.Segment,
119-
keyword: InsideStatementJump.Continue,
120+
visitable.Keyword,
120121
statement: "while");
121122
break;
122123
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace HydraScript.Domain.Constants;
2+
3+
public static class Eop
4+
{
5+
public const string Tag = "EOP";
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace HydraScript.Domain.Constants;
2+
3+
public static class InsideStatementJumpKeyword
4+
{
5+
public const string Break = "break";
6+
7+
public const string Continue = "continue";
8+
}
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;
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
public static IEnumerable<Dto> Stream
12+
{
13+
get
14+
{
15+
yield return new(
16+
Tag: "Comment",
17+
Pattern: "[/]{2}.*",
18+
Priority: 0,
19+
CanIgnore: true);
20+
21+
yield return new(
22+
Tag: "Ident",
23+
Pattern: "[a-zA-Z][a-zA-Z0-9]*",
24+
Priority: 50);
25+
26+
yield return new(
27+
Tag: "IntegerLiteral",
28+
Pattern: "[0-9]+",
29+
Priority: 3);
30+
31+
yield return new(
32+
Tag: "FloatLiteral",
33+
Pattern: "[0-9]+[.][0-9]+",
34+
Priority: 2);
35+
36+
yield return new(
37+
Tag: "NullLiteral",
38+
Pattern: "(?<![a-zA-Z0-9])(null)(?![a-zA-Z0-9])",
39+
Priority: 4);
40+
41+
yield return new(
42+
Tag: "BooleanLiteral",
43+
Pattern: "(?<![a-zA-Z0-9])(true|false)(?![a-zA-Z0-9])",
44+
Priority: 5);
45+
46+
yield return new(
47+
Tag: "StringLiteral",
48+
Pattern: """
49+
\"(\\.|[^"\\])*\"
50+
""",
51+
Priority: 6);
52+
53+
yield return new(
54+
Tag: "Keyword",
55+
Pattern:
56+
"(?<![a-zA-Z0-9])(let|const|function|if|else|while|break|continue|return|as|type)(?![a-zA-Z0-9])",
57+
Priority: 11);
58+
59+
yield return new(
60+
Tag: "Print",
61+
Pattern: "[>]{3}",
62+
Priority: 12);
63+
64+
yield return new(
65+
Tag: "Operator",
66+
Pattern: "[+]{1,2}|[-]|[*]|[/]|[%]|([!]|[=])[=]|([<]|[>])[=]?|[!]|[|]{2}|[&]{2}|[~]|[:]{2}",
67+
Priority: 13);
68+
69+
yield return new(
70+
Tag: "Comma",
71+
Pattern: "[,]",
72+
Priority: 100);
73+
74+
yield return new(
75+
Tag: "Dot",
76+
Pattern: "[.]",
77+
Priority: 105);
78+
79+
yield return new(
80+
Tag: "LeftCurl",
81+
Pattern: "[{]",
82+
Priority: 101);
83+
84+
yield return new(
85+
Tag: "RightCurl",
86+
Pattern: "[}]",
87+
Priority: 102);
88+
89+
yield return new(
90+
Tag: "LeftParen",
91+
Pattern: "[(]",
92+
Priority: 103);
93+
94+
yield return new(
95+
Tag: "RightParen",
96+
Pattern: "[)]",
97+
Priority: 104);
98+
99+
yield return new(
100+
Tag: "LeftBracket",
101+
Pattern: "[[]",
102+
Priority: 107);
103+
104+
yield return new(
105+
Tag: "RightBracket",
106+
Pattern: "[]]",
107+
Priority: 109);
108+
109+
yield return new(
110+
Tag: "Assign",
111+
Pattern: "[=]",
112+
Priority: 99);
113+
114+
yield return new(
115+
Tag: "QuestionMark",
116+
Pattern: "[?]",
117+
Priority: 90);
118+
119+
yield return new(
120+
Tag: "Colon",
121+
Pattern: "[:]",
122+
Priority: 91);
123+
124+
yield return new(
125+
Tag: "SemiColon",
126+
Pattern: "[;]",
127+
Priority: 92);
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)