diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 3c134ace..93f4734f 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -110,7 +110,7 @@ jobs:
publish-nuget:
name: Publish as dotnet tool to NuGet
- runs-on: ubuntu-latest
+ runs-on: windows-latest
needs: publish-release
steps:
- name: Checkout
@@ -120,10 +120,10 @@ jobs:
with:
dotnet-version: 10.0.x
- name: Build
- run: dotnet build ./src/HydraScript/HydraScript.csproj -c Release -v n \
- /p:Version=${{ needs.publish-release.outputs.determined_version }} \
+ run: dotnet build ./src/HydraScript/HydraScript.csproj -c Release -v n `
+ /p:Version=${{ needs.publish-release.outputs.determined_version }} `
/p:PublishAot=false /p:PublishSingleFile=false
- name: Publish
- run: dotnet nuget push ./src/HydraScript/bin/Release/*.nupkg \
- --api-key ${{ secrets.NUGET_API_KEY }} \
+ run: dotnet nuget push ./src/HydraScript/bin/Release/*.nupkg `
+ --api-key ${{ secrets.NUGET_API_KEY }} `
--source https://api.nuget.org/v3/index.json
\ No newline at end of file
diff --git a/Directory.Packages.props b/Directory.Packages.props
index 84754d44..0e3eb7ec 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -1,18 +1,18 @@
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/Readme.md b/Readme.md
index 976b7d86..14b84f5a 100644
--- a/Readme.md
+++ b/Readme.md
@@ -84,6 +84,20 @@ type composite = {
}
```
+#### Strings
+
+Strings support following operations:
+- index access, returns `string`:
+```
+let str = "str"
+>>> str[1] // t
+```
+- length getter:
+```
+let str = "str"
+>>> ~str // 3
+```
+
### Variables
For declaring mutable variables use `let`:
@@ -165,8 +179,8 @@ array = array ++ [5, 7] // concatenation
| ! | unary | boolean | boolean |
| - | unary | number | number |
| ++ | binary | [] | [] |
-| :: | binary | [] и number | void |
-| ~ | unary | [] | number |
+| :: | binary | [] and number | void |
+| ~ | unary | [] or string | number |
### Conditionals
diff --git a/src/Application/HydraScript.Application.StaticAnalysis/IDefaultValueForTypeCalculator.cs b/src/Application/HydraScript.Application.StaticAnalysis/IDefaultValueForTypeCalculator.cs
deleted file mode 100644
index ba34c898..00000000
--- a/src/Application/HydraScript.Application.StaticAnalysis/IDefaultValueForTypeCalculator.cs
+++ /dev/null
@@ -1,6 +0,0 @@
-namespace HydraScript.Application.StaticAnalysis;
-
-public interface IDefaultValueForTypeCalculator
-{
- public object? GetDefaultValueForType(Type type);
-}
\ No newline at end of file
diff --git a/src/Application/HydraScript.Application.StaticAnalysis/IExplicitCastValidator.cs b/src/Application/HydraScript.Application.StaticAnalysis/IExplicitCastValidator.cs
deleted file mode 100644
index 97efe0ff..00000000
--- a/src/Application/HydraScript.Application.StaticAnalysis/IExplicitCastValidator.cs
+++ /dev/null
@@ -1,6 +0,0 @@
-namespace HydraScript.Application.StaticAnalysis;
-
-public interface IExplicitCastValidator
-{
- bool IsAllowed(Type from, Type to);
-}
\ No newline at end of file
diff --git a/src/Application/HydraScript.Application.StaticAnalysis/IHydraScriptTypesService.cs b/src/Application/HydraScript.Application.StaticAnalysis/IHydraScriptTypesService.cs
new file mode 100644
index 00000000..cabbd2d3
--- /dev/null
+++ b/src/Application/HydraScript.Application.StaticAnalysis/IHydraScriptTypesService.cs
@@ -0,0 +1,22 @@
+namespace HydraScript.Application.StaticAnalysis;
+
+public interface IHydraScriptTypesService
+{
+ public Type Number { get; }
+
+ public Type Boolean { get; }
+
+ public Type String { get; }
+
+ public Type Undefined { get; }
+
+ public Type Void { get; }
+
+ public IEnumerable GetDefaultTypes();
+
+ public bool Contains(Type type);
+
+ public object? GetDefaultValueForType(Type type);
+
+ public bool IsExplicitCastAllowed(Type from, Type to);
+}
\ No newline at end of file
diff --git a/src/Application/HydraScript.Application.StaticAnalysis/IJavaScriptTypesProvider.cs b/src/Application/HydraScript.Application.StaticAnalysis/IJavaScriptTypesProvider.cs
deleted file mode 100644
index 42e79dac..00000000
--- a/src/Application/HydraScript.Application.StaticAnalysis/IJavaScriptTypesProvider.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace HydraScript.Application.StaticAnalysis;
-
-public interface IJavaScriptTypesProvider
-{
- public IEnumerable GetDefaultTypes();
-
- public bool Contains(Type type);
-}
\ No newline at end of file
diff --git a/src/Application/HydraScript.Application.StaticAnalysis/ITypeDeclarationsResolver.cs b/src/Application/HydraScript.Application.StaticAnalysis/ITypeDeclarationsResolver.cs
index d7ac8ff2..99553c85 100644
--- a/src/Application/HydraScript.Application.StaticAnalysis/ITypeDeclarationsResolver.cs
+++ b/src/Application/HydraScript.Application.StaticAnalysis/ITypeDeclarationsResolver.cs
@@ -7,4 +7,6 @@ public interface ITypeDeclarationsResolver
public void Store(TypeDeclaration declaration);
public void Resolve();
+
+ IHydraScriptTypesService TypesService { get; }
}
\ No newline at end of file
diff --git a/src/Application/HydraScript.Application.StaticAnalysis/Impl/DefaultValueForTypeCalculator.cs b/src/Application/HydraScript.Application.StaticAnalysis/Impl/DefaultValueForTypeCalculator.cs
deleted file mode 100644
index 3812ba6d..00000000
--- a/src/Application/HydraScript.Application.StaticAnalysis/Impl/DefaultValueForTypeCalculator.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using HydraScript.Domain.IR.Types;
-
-namespace HydraScript.Application.StaticAnalysis.Impl;
-
-internal class DefaultValueForTypeCalculator : IDefaultValueForTypeCalculator
-{
- public object? GetDefaultValueForType(Type type)
- {
- if (type is NullableType)
- return null;
- if (type.Equals("boolean"))
- return false;
- if (type.Equals("number"))
- return 0;
- if (type.Equals("string"))
- return string.Empty;
- if (type.Equals("void"))
- return new object();
- if (type.Equals(new NullType()))
- return null;
- if (type is ArrayType)
- return new List
\ No newline at end of file
diff --git a/tests/HydraScript.IntegrationTests/Samples/string_reversed.js b/tests/HydraScript.IntegrationTests/Samples/string_reversed.js
new file mode 100644
index 00000000..d6ccd61a
--- /dev/null
+++ b/tests/HydraScript.IntegrationTests/Samples/string_reversed.js
@@ -0,0 +1,8 @@
+let str = "string"
+let i = ~str - 1
+let revStr: string
+while (i >= 0) {
+ revStr = revStr + str[i]
+ i = i - 1
+}
+>>> revStr
\ No newline at end of file
diff --git a/tests/HydraScript.UnitTests/Application/ExplicitCastValidatorTests.cs b/tests/HydraScript.UnitTests/Application/HydraScriptTypesServiceTests.cs
similarity index 55%
rename from tests/HydraScript.UnitTests/Application/ExplicitCastValidatorTests.cs
rename to tests/HydraScript.UnitTests/Application/HydraScriptTypesServiceTests.cs
index 6e6fd65a..fac4678f 100644
--- a/tests/HydraScript.UnitTests/Application/ExplicitCastValidatorTests.cs
+++ b/tests/HydraScript.UnitTests/Application/HydraScriptTypesServiceTests.cs
@@ -3,13 +3,13 @@
namespace HydraScript.UnitTests.Application;
-public class ExplicitCastValidatorTests
+public class HydraScriptTypesServiceTests
{
- private readonly ExplicitCastValidator _explicitCastValidator = new();
+ private readonly HydraScriptTypesService _typesService = new();
[Theory, MemberData(nameof(ConversionsData))]
- public void IsAllowed_Always_Success(Type from, Type to, bool expected) =>
- _explicitCastValidator.IsAllowed(from, to).Should().Be(expected);
+ public void IsExplicitCastAllowed_Always_Success(Type from, Type to, bool expected) =>
+ _typesService.IsExplicitCastAllowed(from, to).Should().Be(expected);
public static TheoryData ConversionsData =>
new()
@@ -25,4 +25,13 @@ public void IsAllowed_Always_Success(Type from, Type to, bool expected) =>
{ new ArrayType("number"), "number", false },
{ new ArrayType("number"), new NullableType("boolean"), false },
};
+
+ [Fact]
+ public void GetDefaultValueForType_NullableTypes_ReturnsNull()
+ {
+ var calculator = new HydraScriptTypesService();
+ Assert.Null(calculator.GetDefaultValueForType(new NullableType(new Any())));
+ Assert.Null(calculator.GetDefaultValueForType(new NullType()));
+ Assert.Null(calculator.GetDefaultValueForType(new ObjectType([])));
+ }
}
\ No newline at end of file
diff --git a/tests/HydraScript.UnitTests/Domain/IR/TypeTests.cs b/tests/HydraScript.UnitTests/Domain/IR/TypeTests.cs
index 39d5e8ce..25d54428 100644
--- a/tests/HydraScript.UnitTests/Domain/IR/TypeTests.cs
+++ b/tests/HydraScript.UnitTests/Domain/IR/TypeTests.cs
@@ -1,4 +1,3 @@
-using HydraScript.Application.StaticAnalysis.Impl;
using HydraScript.Domain.IR.Types;
namespace HydraScript.UnitTests.Domain.IR;
@@ -40,13 +39,4 @@ public void TypeWrappingTest()
str = new ArrayType(str);
Assert.Equal("string?[]", str.ToString());
}
-
- [Fact]
- public void DefaultValueTest()
- {
- var calculator = new DefaultValueForTypeCalculator();
- Assert.Null(calculator.GetDefaultValueForType(new NullableType(new Any())));
- Assert.Null(calculator.GetDefaultValueForType(new NullType()));
- Assert.Null(calculator.GetDefaultValueForType(new ObjectType([])));
- }
}
\ No newline at end of file