Skip to content

Commit

Permalink
Merge pull request #50 from furesoft/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
furesoft authored Oct 12, 2024
2 parents 2e79b0c + 74367f9 commit d6bb5de
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 26 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ jobs:
sed -i "s/<Version>.*<\/Version>/<Version>${RELEASE_VERSION}<\/Version>/" Source/Silverfly.Testing/Silverfly.Testing.csproj
sed -i "s/<Version>.*<\/Version>/<Version>${RELEASE_VERSION}<\/Version>/" Source/Silverfly.Generator/Silverfly.Generator.csproj
sed -i "s/<Version>.*<\/Version>/<Version>${RELEASE_VERSION}<\/Version>/" Source/Silverfly.Repl/Silverfly.Repl.csproj
sed -i "s/<Version>.*<\/Version>/<Version>${RELEASE_VERSION}<\/Version>/" Source/Silverfly.TreeVisualizer/Silverfly.TreeVisualizer.csproj
- name: Build and package
run: |
dotnet build -c Release -o ./nuget Source/Silverfly/Silverfly.csproj
dotnet build -c Release -o ./nuget Source/Silverfly.Testing/Silverfly.Testing.csproj
dotnet build -c Release -o ./nuget Source/Silverfly.Repl/Silverfly.Repl.csproj
dotnet build -c Release -o ./nuget Source/Silverfly.TreeVisualizer/Silverfly.TreeVisualizer.csproj
dotnet build -o ./nuget Source/Silverfly.Generator/Silverfly.Generator.csproj
- name: Publish to NuGet
Expand Down Expand Up @@ -92,6 +94,6 @@ jobs:
message: "Update version to ${{ env.RELEASE_VERSION }}"
push: true
new_branch: update-version
add: '["Source/Silverfly/Silverfly.csproj", "Source/Silverfly.Testing/Silverfly.Testing.csproj", "Source/Silverfly.Generator/Silverfly.Generator.csproj", "Source/Silverfly.Repl/Silverfly.Repl.csproj"]'
add: '["Source/Silverfly/Silverfly.csproj", "Source/Silverfly.Testing/Silverfly.Testing.csproj", "Source/Silverfly.Generator/Silverfly.Generator.csproj", "Source/Silverfly.Repl/Silverfly.Repl.csproj","Source/Silverfly.TreeVisualizer/Silverfly.TreeVisualizer.csproj"]'


10 changes: 5 additions & 5 deletions Source/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Silverfly\Silverfly.csproj" />
<ProjectReference Include="..\TestProject\TestProject.csproj" />
<ItemGroup>
<ProjectReference Include="..\Silverfly\Silverfly.csproj" />
<ProjectReference Include="..\TestProject\TestProject.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.70</Version>
<Version>1.0.71</Version>
<OutputType>Exe</OutputType>
<LangVersion>preview</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down
3 changes: 1 addition & 2 deletions Source/Samples/Sample.JSON/JsonGrammar.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Sample.JSON.Nodes;
using Sample.JSON.Parselets;
using Silverfly;

namespace Sample.JSON;
namespace Silverfly.Sample.JSON;

public class JsonGrammar : Parser
{
Expand Down
1 change: 1 addition & 0 deletions Source/Samples/Sample.JSON/ReplInstance.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Silverfly.Repl;
using Silverfly.Sample.JSON;

namespace Sample.JSON;

Expand Down
2 changes: 1 addition & 1 deletion Source/Samples/Sample.JSON/Sample.JSON.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.70</Version>
<Version>1.0.71</Version>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down
2 changes: 1 addition & 1 deletion Source/Samples/Sample.Rockstar/Sample.Rockstar.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.70</Version>
<Version>1.0.71</Version>
<OutputType>Exe</OutputType>
<LangVersion>preview</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down
10 changes: 5 additions & 5 deletions Source/Silverfly.Generator/Silverfly.Generator.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.70</Version>
<Version>1.0.71</Version>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -21,16 +21,16 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Fody" Version="6.8.1">
<PackageReference Include="Fody" Version="6.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Source/Silverfly.Repl/Silverfly.Repl.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.70</Version>
<Version>1.0.71</Version>
<LangVersion>preview</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>Silverfly.Repl</Title>
Expand Down
10 changes: 5 additions & 5 deletions Source/Silverfly.Testing/Silverfly.Testing.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.70</Version>
<Version>1.0.71</Version>
<LangVersion>preview</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>Silverfly.Testing</Title>
<Copyright>furesoft</Copyright>
<RepositoryUrl>https://github.com/furesoft/Silverfly</RepositoryUrl>
<Description>A little framework to build parsers</Description>
<PackageTags>parser, pratt</PackageTags>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Verify" Version="20.6.0"/>
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="Verify.NUnit" Version="20.6.0" />
<PackageReference Include="Verify" Version="26.6.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="Verify.NUnit" Version="26.6.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
</ItemGroup>

Expand Down
13 changes: 13 additions & 0 deletions Source/Silverfly.TreeVisualizer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Spectre.Console;
using Spectre.Console.Cli;

namespace Silverfly.TreeVisualizer;

public class Program
{
public static int Main(string[] args)
{
var app = new CommandApp<TreeCommand>();
return app.Run(args);
}
}
30 changes: 30 additions & 0 deletions Source/Silverfly.TreeVisualizer/Silverfly.TreeVisualizer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackAsTool>true</PackAsTool>
<ToolCommandName>silver-tree</ToolCommandName>

<Version>1.0.70</Version>
<LangVersion>preview</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>Silverfly.TreeVisualizer</Title>
<Copyright>furesoft</Copyright>
<RepositoryUrl>https://github.com/furesoft/Silverfly</RepositoryUrl>
<Description>A tool to view Silverfly trees</Description>
<PackageTags>parser, pratt, silverfly, ast</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Spectre.Console" Version="0.49.1" />
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Silverfly\Silverfly.csproj" />
</ItemGroup>

</Project>
108 changes: 108 additions & 0 deletions Source/Silverfly.TreeVisualizer/TreeCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System.Collections;
using System.ComponentModel;
using System.Reflection;
using Silverfly.Nodes;
using Spectre.Console;
using Spectre.Console.Cli;

namespace Silverfly.TreeVisualizer;

internal sealed class TreeCommand : Command<TreeCommand.Settings>
{
public sealed class Settings : CommandSettings
{
[Description("Path to the assembly containing the parsers")]
[CommandArgument(0, "<assembly>")]
public string? AssemblyPath { get; set; }

[CommandOption("-p|--parser")]
[Description("Specify the parser to use")]
public string? Parser { get; set; }

[Description("The source to parse")]
[CommandOption("-s|--source")]
public string Source { get; set; }

Check warning on line 24 in Source/Silverfly.TreeVisualizer/TreeCommand.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Non-nullable property 'Source' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 24 in Source/Silverfly.TreeVisualizer/TreeCommand.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Non-nullable property 'Source' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

public override int Execute(CommandContext context, Settings settings)
{
var parserAssembly = Assembly.LoadFrom(Path.Combine(Environment.CurrentDirectory, settings.AssemblyPath));

Check warning on line 29 in Source/Silverfly.TreeVisualizer/TreeCommand.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference argument for parameter 'path2' in 'string Path.Combine(string path1, string path2)'.

Check warning on line 29 in Source/Silverfly.TreeVisualizer/TreeCommand.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference argument for parameter 'path2' in 'string Path.Combine(string path1, string path2)'.
var parserType = parserAssembly.GetType(settings.Parser);

Check warning on line 30 in Source/Silverfly.TreeVisualizer/TreeCommand.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference argument for parameter 'name' in 'Type? Assembly.GetType(string name)'.

Check warning on line 30 in Source/Silverfly.TreeVisualizer/TreeCommand.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference argument for parameter 'name' in 'Type? Assembly.GetType(string name)'.
var parserInstance = (Parser)Activator.CreateInstance(parserType);

Check warning on line 31 in Source/Silverfly.TreeVisualizer/TreeCommand.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference argument for parameter 'type' in 'object? Activator.CreateInstance(Type type)'.

Check warning on line 31 in Source/Silverfly.TreeVisualizer/TreeCommand.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Converting null literal or possible null value to non-nullable type.

Check warning on line 31 in Source/Silverfly.TreeVisualizer/TreeCommand.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference argument for parameter 'type' in 'object? Activator.CreateInstance(Type type)'.

var parsed = parserInstance.Parse(settings.Source);

Check warning on line 33 in Source/Silverfly.TreeVisualizer/TreeCommand.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Dereference of a possibly null reference.

parserInstance.PrintMessages();

var root = new Tree(parsed.Tree.GetType().Name);

BuildTree(root, parsed.Tree);

AnsiConsole.Write(root);

return 0;
}

private string[] ignorePropNames = ["Tag", "Range", "Parent"];

private void BuildTree(IHasTreeNodes node, AstNode parsedTree)
{
if (parsedTree is BlockNode block)
{
foreach (var child in block.Children)
{
BuildTreeChild(node, child);
}
}
else
{
BuildTreeChild(node, parsedTree);
}
}

private void BuildTreeChild(IHasTreeNodes node, object child)
{
var childType = child.GetType();
var childNode = node.AddNode(childType.Name);

foreach (var property in childType.GetProperties(BindingFlags.Instance | BindingFlags.Public))
{
if (ignorePropNames.Contains(property.Name))
{
continue;
}

var propValue = property.GetValue(child);

if (propValue is LiteralNode literal)
{
childNode.AddNode($"{property.Name}={literal.Value}");
continue;
}
if (propValue is NameNode nameNode)
{
childNode.AddNode($"{property.Name}={nameNode.Token}");
continue;
}

if (propValue is Token token)
{
childNode.AddNode($"{property.Name}={token}");
continue;
}
else if (propValue is IEnumerable enumerable)
{
var itemNode = childNode.AddNode($"{property.Name}");
foreach (var item in enumerable)
{
BuildTreeChild(itemNode, item);
}
}

if (propValue is AstNode childBlock)
{
BuildTreeChild(childNode, childBlock);
}
}
}
}
6 changes: 6 additions & 0 deletions Source/Silverfly.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Rockstar", "Samples\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Brainfuck", "Samples\Sample.Brainfuck\Sample.Brainfuck.csproj", "{C43A7724-4D0D-4600-9778-E479F8BD946B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silverfly.TreeVisualizer", "Silverfly.TreeVisualizer\Silverfly.TreeVisualizer.csproj", "{A0D943E1-2579-4C51-84C6-375374FA0104}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -71,6 +73,10 @@ Global
{C43A7724-4D0D-4600-9778-E479F8BD946B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C43A7724-4D0D-4600-9778-E479F8BD946B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C43A7724-4D0D-4600-9778-E479F8BD946B}.Release|Any CPU.Build.0 = Release|Any CPU
{A0D943E1-2579-4C51-84C6-375374FA0104}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0D943E1-2579-4C51-84C6-375374FA0104}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0D943E1-2579-4C51-84C6-375374FA0104}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0D943E1-2579-4C51-84C6-375374FA0104}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions Source/Silverfly/Parselets/EnumParselet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

namespace Silverfly.Parselets;

/// <summary>
/// Produces a <see cref="LiteralNode" />
/// </summary>
/// <typeparam name="TRegister"></typeparam>
public class EnumParselet<TRegister> : IPrefixParselet
where TRegister : struct
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Silverfly/Silverfly.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.70</Version>
<Version>1.0.71</Version>
<LangVersion>preview</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>Silverfly</Title>
Expand Down
6 changes: 3 additions & 3 deletions Source/TestProject/TestProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />

<ProjectReference Include="..\Silverfly.Testing\Silverfly.Testing.csproj" />
<ProjectReference Include="..\Silverfly\Silverfly.csproj" />
Expand Down

0 comments on commit d6bb5de

Please sign in to comment.