Skip to content

Commit f751f58

Browse files
author
Paul Braetz
committed
fix dsl generator
1 parent ba3b0ac commit f751f58

File tree

9 files changed

+158
-125
lines changed

9 files changed

+158
-125
lines changed

DslGenerator/DslGenerator.csproj

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,59 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<!--AutoUpdateAssemblyName-->
3-
4-
<PropertyGroup>
5-
<TargetFramework>netstandard2.0</TargetFramework>
6-
<IncludeBuildOutput>false</IncludeBuildOutput>
7-
<developmentDependency>true</developmentDependency>
8-
<NoPackageAnalysis>true</NoPackageAnalysis>
9-
<IsRoslynComponent>true</IsRoslynComponent>
10-
<Nullable>enable</Nullable>
11-
<ImplicitUsings>enable</ImplicitUsings>
12-
</PropertyGroup>
13-
14-
<ItemGroup>
15-
<InternalsVisibleTo Include="RhoMicro.CodeAnalysis.DslGenerator.Tests"/>
16-
</ItemGroup>
17-
18-
<PropertyGroup>
19-
<IsPackable>true</IsPackable>
20-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
21-
<Description>Generates utilities for lexing and parsing domain specific languages, little languages etc.</Description>
22-
<PackageTags>Source Generator</PackageTags>
23-
</PropertyGroup>
24-
25-
<PropertyGroup>
26-
<DefineConstants>$(DefineConstants);DSL_GENERATOR</DefineConstants>
27-
</PropertyGroup>
28-
29-
<ItemGroup>
30-
<PackageReference Update="NETStandard.Library" PrivateAssets="all"/>
31-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0"/>
32-
<PackageReference Include="PolySharp" Version="1.15.0">
33-
<PrivateAssets>all</PrivateAssets>
34-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
35-
</PackageReference>
36-
</ItemGroup>
37-
38-
<ItemGroup>
39-
<PackageReference Include="RhoMicro.CodeAnalysis.UtilityGenerators" Version="15.3.4">
40-
<PrivateAssets>all</PrivateAssets>
41-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
42-
</PackageReference>
43-
<ProjectReference Include="..\Janus.Analyzers\Janus.Analyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
44-
<ProjectReference Include="..\Janus.CodeFixes\Janus.CodeFixes.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
45-
</ItemGroup>
46-
47-
<ItemGroup>
48-
<None Remove="bin\Debug\netstandard2.0\\RhoMicro.CodeAnalysis.DslGenerator.13.0.0.568.dll"/>
49-
</ItemGroup>
50-
51-
<ItemGroup>
52-
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
53-
<None Include="README.md" Pack="true" PackagePath="/" CopyToOutputDirectory="Always"/>
54-
</ItemGroup>
2+
<!--AutoUpdateAssemblyName-->
3+
4+
<PropertyGroup>
5+
<TargetFramework>netstandard2.0</TargetFramework>
6+
<IncludeBuildOutput>false</IncludeBuildOutput>
7+
<developmentDependency>true</developmentDependency>
8+
<NoPackageAnalysis>true</NoPackageAnalysis>
9+
<IsRoslynComponent>true</IsRoslynComponent>
10+
<Nullable>enable</Nullable>
11+
<ImplicitUsings>enable</ImplicitUsings>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<InternalsVisibleTo Include="RhoMicro.CodeAnalysis.DslGenerator.Tests"/>
16+
</ItemGroup>
17+
18+
<PropertyGroup>
19+
<IsPackable>true</IsPackable>
20+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
21+
<Description>Generates utilities for lexing and parsing domain specific languages, little languages etc.</Description>
22+
<PackageTags>Source Generator</PackageTags>
23+
</PropertyGroup>
24+
25+
<PropertyGroup>
26+
<DefineConstants>$(DefineConstants);DSL_GENERATOR</DefineConstants>
27+
</PropertyGroup>
28+
29+
<ItemGroup>
30+
<PackageReference Update="NETStandard.Library" PrivateAssets="all"/>
31+
<PackageReference Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
32+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0"/>
33+
<PackageReference Include="PolySharp" Version="1.15.0">
34+
<PrivateAssets>all</PrivateAssets>
35+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
36+
</PackageReference>
37+
</ItemGroup>
38+
39+
<ItemGroup>
40+
<PackageReference Include="RhoMicro.CodeAnalysis.UtilityGenerators" Version="15.3.4">
41+
<PrivateAssets>all</PrivateAssets>
42+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
43+
</PackageReference>
44+
45+
<ProjectReference Include="..\Janus.Analyzers\Janus.Analyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
46+
<ProjectReference Include="..\Janus.CodeFixes\Janus.CodeFixes.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
47+
<ProjectReference Include="..\Janus.Library\Janus.Library.csproj"/>
48+
</ItemGroup>
49+
50+
<ItemGroup>
51+
<None Remove="bin\Debug\netstandard2.0\\RhoMicro.CodeAnalysis.DslGenerator.13.0.0.568.dll"/>
52+
</ItemGroup>
53+
54+
<ItemGroup>
55+
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
56+
<None Include="README.md" Pack="true" PackagePath="/" CopyToOutputDirectory="Always"/>
57+
</ItemGroup>
5558

5659
</Project>

DslGenerator/Lexing/Lexeme.cs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,35 @@ namespace RhoMicro.CodeAnalysis.DslGenerator.Lexing;
88
[IncludeFile]
99
#endif
1010
[UnionType<String, Char, StringSlice>]
11-
[UnionTypeSettings(
12-
ToStringSetting = ToStringSetting.Simple,
13-
Miscellaneous = MiscellaneousSettings.Default | MiscellaneousSettings.EmitGeneratedSourceCode)]
11+
[UnionTypeSettings(ToStringSetting = ToStringSetting.Simple)]
1412
internal readonly partial struct Lexeme : IEquatable<String>, IEquatable<Char>, IEquatable<StringSlice>
1513
{
16-
public Int32 Length => Match(
17-
s => s.Length,
18-
s => 1,
19-
s => s.Length);
14+
public Int32 Length => Switch(
15+
onString: s => s.Length,
16+
onChar: s => 1,
17+
onStringSlice: s => s.Length);
18+
2019
public static Lexeme Empty { get; } = String.Empty;
21-
public Boolean Equals(Lexeme other) =>
22-
Match(other.Equals, other.Equals, other.Equals);
23-
public override Int32 GetHashCode() =>
24-
Match(v => v.GetHashCode(), v => v.GetHashCode(), v => v.GetHashCode());
20+
2521
public Boolean Equals(Char c) =>
26-
Match(
27-
s => s.Length == 1 && s[0] == c,
28-
thisChar => thisChar == c,
29-
s => s.Equals(c));
22+
Switch(
23+
onString: s => s.Length == 1 && s[0] == c,
24+
onChar: thisChar => thisChar == c,
25+
onStringSlice: s => s.Equals(c));
26+
3027
public Boolean Equals(String s) =>
31-
Match(
32-
thisString => thisString == s,
33-
c => s.Length == 1 && s[0] == c,
34-
slice => slice.Equals(s));
28+
Switch(
29+
onString: thisString => thisString == s,
30+
onChar: c => s.Length == 1 && s[0] == c,
31+
onStringSlice: slice => slice.Equals(s));
32+
3533
public Boolean Equals(StringSlice s) =>
36-
Match(s.Equals, s.Equals, s.Equals);
34+
Switch(s.Equals, s.Equals, s.Equals);
35+
3736
public String ToEscapedString() =>
3837
ToString()?
39-
.Replace("\n", "\\n")
40-
.Replace("\r", "\\r")
41-
.Replace("\t", "\\t")
42-
?? String.Empty;
38+
.Replace("\n", "\\n")
39+
.Replace("\r", "\\r")
40+
.Replace("\t", "\\t")
41+
?? String.Empty;
4342
}

DslGenerator/Lexing/SourceText.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ namespace RhoMicro.CodeAnalysis.DslGenerator.Lexing;
1212
internal readonly partial struct SourceText : IDisposable
1313
{
1414
public String ToString(CancellationToken cancellationToken) =>
15-
Match(
16-
s => s,
17-
s =>
15+
Switch(
16+
onString: s => s,
17+
onStream: s =>
1818
{
1919
cancellationToken.ThrowIfCancellationRequested();
2020
var reader = new StreamReader(s);
2121
var resultBuilder = new StringBuilder();
2222
var line = reader.ReadLine();
23-
while(line != null)
23+
while (line != null)
2424
{
2525
cancellationToken.ThrowIfCancellationRequested();
2626
_ = resultBuilder.AppendLine(line);
@@ -31,10 +31,12 @@ public String ToString(CancellationToken cancellationToken) =>
3131

3232
return result;
3333
});
34+
3435
public static SourceText Empty { get; } = String.Empty;
36+
3537
public void Dispose()
3638
{
37-
if(TryAsStream(out var s))
39+
if (TryCastToStream(out var s))
3840
s.Dispose();
3941
}
4042
}

0 commit comments

Comments
 (0)