Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
32 changes: 17 additions & 15 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<Project>
<ItemGroup>
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageVersion Include="Scrutor" Version="4.2.2" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
<PackageVersion Include="System.IO.Abstractions" Version="21.0.29" />
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
<PackageVersion Include="Visitor.NET" Version="4.1.2" />
<PackageVersion Include="Visitor.NET.AutoVisitableGen" Version="1.3.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="9.0.2" />
<PackageVersion Include="Scrutor" Version="6.0.1" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
<PackageVersion Include="System.IO.Abstractions" Version="22.0.11" />
<PackageVersion Include="System.Text.Json" Version="9.0.2" />
<PackageVersion Include="Visitor.NET" Version="4.1.2" />
<PackageVersion Include="Visitor.NET.AutoVisitableGen" Version="1.3.0" />
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions ExtendedJavaScriptSubset.sln
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HydraScript.Infrastructure.
EndProject
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}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HydraScript.Domain.Constants", "src\Domain\HydraScript.Domain.Constants\HydraScript.Domain.Constants.csproj", "{E3E558A3-1999-48F9-B53D-2E583C18F000}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -150,6 +152,10 @@ Global
{829111AD-4A5C-4B3D-AC28-208309CE10D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{829111AD-4A5C-4B3D-AC28-208309CE10D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{829111AD-4A5C-4B3D-AC28-208309CE10D6}.Release|Any CPU.Build.0 = Release|Any CPU
{E3E558A3-1999-48F9-B53D-2E583C18F000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E3E558A3-1999-48F9-B53D-2E583C18F000}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3E558A3-1999-48F9-B53D-2E583C18F000}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3E558A3-1999-48F9-B53D-2E583C18F000}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{54CBE5A7-3C3E-44ED-B877-7B08A818083B} = {86CF2A2F-4DFE-48E7-B062-EF824730916A}
Expand All @@ -169,5 +175,6 @@ Global
{1CE98127-3027-4BD4-AAA3-63A589B09E73} = {3F131901-A9EC-451A-B7E9-726887CFE5FB}
{74D1495B-12A4-4E1A-ABE0-93029ECDC5FE} = {B7DDF6C9-B67C-430A-948A-A380EF68DEF1}
{829111AD-4A5C-4B3D-AC28-208309CE10D6} = {3F131901-A9EC-451A-B7E9-726887CFE5FB}
{E3E558A3-1999-48F9-B53D-2E583C18F000} = {F0FC6D23-F932-4C11-8D0F-07894FC61511}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using HydraScript.Domain.BackEnd.Impl.Instructions.WithAssignment;
using HydraScript.Domain.BackEnd.Impl.Instructions.WithJump;
using HydraScript.Domain.BackEnd.Impl.Values;
using HydraScript.Domain.Constants;
using HydraScript.Domain.FrontEnd.Parser;
using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes;
using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Declarations.AfterTypesAreLoaded;
Expand Down Expand Up @@ -82,8 +83,8 @@ public AddressedInstructions Visit(InsideStatementJump visitable)
{
var jumpType = visitable.Keyword switch
{
InsideStatementJump.Break => InsideStatementJumpType.Break,
InsideStatementJump.Continue => InsideStatementJumpType.Continue,
InsideStatementJumpKeyword.Break => InsideStatementJumpType.Break,
InsideStatementJumpKeyword.Continue => InsideStatementJumpType.Continue,
_ => throw new ArgumentOutOfRangeException(
nameof(visitable.Keyword), visitable.Keyword,
"Unsupported keyword inside loop")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HydraScript.Application.StaticAnalysis.Exceptions;
using HydraScript.Domain.Constants;
using HydraScript.Domain.FrontEnd.Parser;
using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes;
using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Declarations;
Expand Down Expand Up @@ -105,18 +106,18 @@ public Type Visit(InsideStatementJump visitable)
{
switch (visitable.Keyword)
{
case InsideStatementJump.Break:
case InsideStatementJumpKeyword.Break:
if (!(visitable.ChildOf<IfStatement>() || visitable.ChildOf<WhileStatement>()))
throw new OutsideOfStatement(
visitable.Segment,
keyword: InsideStatementJump.Break,
visitable.Keyword,
statement: "if|while");
break;
case InsideStatementJump.Continue:
case InsideStatementJumpKeyword.Continue:
if (!visitable.ChildOf<WhileStatement>())
throw new OutsideOfStatement(
visitable.Segment,
keyword: InsideStatementJump.Continue,
visitable.Keyword,
statement: "while");
break;
}
Expand Down
6 changes: 6 additions & 0 deletions src/Domain/HydraScript.Domain.Constants/Eop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace HydraScript.Domain.Constants;

public static class Eop
{
public const string Tag = "EOP";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace HydraScript.Domain.Constants;

public static class InsideStatementJumpKeyword
{
public const string Break = "break";

public const string Continue = "continue";
}
5 changes: 5 additions & 0 deletions src/Domain/HydraScript.Domain.Constants/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices;

// ReSharper disable once UnusedType.Global
public static class IsExternalInit;
130 changes: 130 additions & 0 deletions src/Domain/HydraScript.Domain.Constants/TokenTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
namespace HydraScript.Domain.Constants;

public static class TokenTypes
{
public record Dto(
string Tag,
string Pattern,
int Priority,
bool CanIgnore = false);

public static IEnumerable<Dto> Stream
{
get
{
yield return new(
Tag: "Comment",
Pattern: "[/]{2}.*",
Priority: 0,
CanIgnore: true);

yield return new(
Tag: "Ident",
Pattern: "[a-zA-Z][a-zA-Z0-9]*",
Priority: 50);

yield return new(
Tag: "IntegerLiteral",
Pattern: "[0-9]+",
Priority: 3);

yield return new(
Tag: "FloatLiteral",
Pattern: "[0-9]+[.][0-9]+",
Priority: 2);

yield return new(
Tag: "NullLiteral",
Pattern: "(?<![a-zA-Z0-9])(null)(?![a-zA-Z0-9])",
Priority: 4);

yield return new(
Tag: "BooleanLiteral",
Pattern: "(?<![a-zA-Z0-9])(true|false)(?![a-zA-Z0-9])",
Priority: 5);

yield return new(
Tag: "StringLiteral",
Pattern: """
\"(\\.|[^"\\])*\"
""",
Priority: 6);

yield return new(
Tag: "Keyword",
Pattern:
"(?<![a-zA-Z0-9])(let|const|function|if|else|while|break|continue|return|as|type)(?![a-zA-Z0-9])",
Priority: 11);

yield return new(
Tag: "Print",
Pattern: "[>]{3}",
Priority: 12);

yield return new(
Tag: "Operator",
Pattern: "[+]{1,2}|[-]|[*]|[/]|[%]|([!]|[=])[=]|([<]|[>])[=]?|[!]|[|]{2}|[&]{2}|[~]|[:]{2}",
Priority: 13);

yield return new(
Tag: "Comma",
Pattern: "[,]",
Priority: 100);

yield return new(
Tag: "Dot",
Pattern: "[.]",
Priority: 105);

yield return new(
Tag: "LeftCurl",
Pattern: "[{]",
Priority: 101);

yield return new(
Tag: "RightCurl",
Pattern: "[}]",
Priority: 102);

yield return new(
Tag: "LeftParen",
Pattern: "[(]",
Priority: 103);

yield return new(
Tag: "RightParen",
Pattern: "[)]",
Priority: 104);

yield return new(
Tag: "LeftBracket",
Pattern: "[[]",
Priority: 107);

yield return new(
Tag: "RightBracket",
Pattern: "[]]",
Priority: 109);

yield return new(
Tag: "Assign",
Pattern: "[=]",
Priority: 99);

yield return new(
Tag: "QuestionMark",
Pattern: "[?]",
Priority: 90);

yield return new(
Tag: "Colon",
Pattern: "[:]",
Priority: 91);

yield return new(
Tag: "SemiColon",
Pattern: "[;]",
Priority: 92);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
<PackageReference Include="Visitor.NET.AutoVisitableGen" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\HydraScript.Domain.Constants\HydraScript.Domain.Constants.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace HydraScript.Domain.FrontEnd.Lexer;

public interface IGeneratedRegexContainer
{
public static abstract Regex GetRegex();
public static abstract Regex Regex { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Structure<TContainer>(ITokenTypesProvider provider) : IStructure
.Concat([new EndOfProgramType(), new ErrorType()])
.ToFrozenDictionary(x => x.Tag);

public Regex Regex { get; } = TContainer.GetRegex();
public Regex Regex { get; } = TContainer.Regex;

public TokenType FindByTag(string tag) =>
Types[tag];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using HydraScript.Domain.FrontEnd.Lexer.TokenTypes;

namespace HydraScript.Domain.FrontEnd.Lexer.Impl;

public class TokenTypesProvider : ITokenTypesProvider
{
public IEnumerable<TokenType> GetTokenTypes() =>
Constants.TokenTypes.Stream
.OrderBy(x => x.Priority)
.Select(x => x.CanIgnore
? new IgnorableType(x.Tag)
: new TokenType(x.Tag));
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using HydraScript.Domain.Constants;

namespace HydraScript.Domain.FrontEnd.Lexer.TokenTypes;

internal record EndOfProgramType() : TokenType(EopTag)
{
public const string EopTag = "EOP";
}
internal record EndOfProgramType() : TokenType(Eop.Tag);
Loading