Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project/aot trimming/building #479

Open
wants to merge 104 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
bc52c18
lexer builder without reflection
b3b00 Aug 6, 2024
1b2e75e
lexer builder without reflection : many lexemes for an enum value
b3b00 Aug 6, 2024
c25c081
lexer builder without reflection : lexeme labels
b3b00 Aug 6, 2024
0ef565c
parser builder : initial
b3b00 Aug 6, 2024
616e1bb
AOT parser build : initial
b3b00 Aug 6, 2024
20ed473
parser build : WIP
b3b00 Aug 7, 2024
a5f44e0
parser build : concrete syntax tree visitors
b3b00 Aug 7, 2024
cf5023d
parser build : retyping done
b3b00 Aug 7, 2024
c6bc79e
wip
b3b00 Aug 7, 2024
4ff0f61
parser build : operations
b3b00 Aug 7, 2024
97dbbe4
almost done for EBNF
b3b00 Aug 7, 2024
addf95c
parser build : RuleParser is now AOT compliant
b3b00 Aug 7, 2024
3639423
unit tests
b3b00 Aug 7, 2024
fec2689
fixing UT
b3b00 Aug 7, 2024
bb63f1d
build lexer : config and comments , initial wip
b3b00 Aug 8, 2024
6fdac63
lexer build : comments done
b3b00 Aug 8, 2024
c2b5826
lexer build : lexer config done
b3b00 Aug 8, 2024
c01fad4
build :
b3b00 Aug 8, 2024
491f3bb
lexer build : regexes
b3b00 Aug 8, 2024
a641dd7
parser build : indetned while unit test , not working
b3b00 Aug 8, 2024
5bbd284
.
b3b00 Aug 8, 2024
258c6ae
parser build : indented while unit test working
b3b00 Aug 8, 2024
16741a7
lexer build : lexer post processor and generic lexer extensions
b3b00 Aug 8, 2024
9284e71
parser and lexer build : lexer callbacks and lexer postprocess wip
b3b00 Aug 8, 2024
4190a26
lexer build : modes and labels initial
b3b00 Aug 9, 2024
dce3b40
fix lexer post processor unit test
b3b00 Aug 9, 2024
5c2bc9b
lexer builder : modes
b3b00 Aug 9, 2024
27a6c0f
i18n and cleaning
b3b00 Aug 9, 2024
f934724
.
b3b00 Aug 9, 2024
19797d6
remove warnings
b3b00 Aug 9, 2024
940f79e
benchmarking
b3b00 Aug 9, 2024
dcf9d70
benchmarking program
b3b00 Aug 9, 2024
9569fde
.
b3b00 Aug 9, 2024
b606c65
.
b3b00 Aug 9, 2024
426723f
.
b3b00 Aug 9, 2024
52f8e40
clean compilation warnings
b3b00 Aug 9, 2024
c6f42e1
.
b3b00 Sep 2, 2024
8e3825c
.
b3b00 Sep 3, 2024
6eb5439
.
b3b00 Sep 3, 2024
8478289
.
b3b00 Sep 3, 2024
6e5f1da
working with indented while lexer
b3b00 Sep 3, 2024
b45d47e
manage modes : working with XML
b3b00 Sep 3, 2024
2a4bf4f
fix channels
b3b00 Sep 3, 2024
7999186
extensions : wip
b3b00 Sep 3, 2024
34b6203
extensions : ok
b3b00 Sep 3, 2024
e889b27
move generator to main sly project
b3b00 Sep 3, 2024
ec0637a
parser generator : initial wip
b3b00 Sep 4, 2024
6b63101
parser generator : wip
b3b00 Sep 4, 2024
6898a86
parser generator : working :)
b3b00 Sep 4, 2024
e449a13
perser generator : working Indented While
b3b00 Sep 4, 2024
89f2c28
parser generator : working XML
b3b00 Sep 4, 2024
b0fc3ed
respect parser generator visibility
b3b00 Sep 5, 2024
ba50d18
fixing issues with unit tests
b3b00 Sep 5, 2024
d3e4de9
parser generator : template parser WIP
b3b00 Sep 5, 2024
7735b54
UT template : fix operations
b3b00 Sep 6, 2024
84449a3
lexer callbacks unit test
b3b00 Sep 6, 2024
52308cc
post process lexer test
b3b00 Sep 6, 2024
ced756e
- token callbacks
b3b00 Sep 6, 2024
780cb03
remove dead code
b3b00 Sep 6, 2024
752aa13
.
b3b00 Sep 7, 2024
32f50ad
reafcto aot lexer builder :
b3b00 Sep 9, 2024
b53d562
refacto aot lexer builder :
b3b00 Sep 9, 2024
0e2a8d0
refacto aot lexer : labels
b3b00 Sep 9, 2024
1bc8094
refacto aot lexer : labels
b3b00 Sep 9, 2024
383dc00
- parser : syntax tree node names
b3b00 Sep 10, 2024
d0925f6
fix unit tests
b3b00 Sep 10, 2024
ec49f5f
.
b3b00 Sep 10, 2024
997fb28
Merge branch 'dev' into project/aot-trimming/building
b3b00 Sep 10, 2024
97c8e1b
generator : explicit tokens unit tests
b3b00 Sep 10, 2024
9d0cb6f
Update dotnetcore.yml
b3b00 Sep 10, 2024
da8b702
Update dotnetcore.yml
b3b00 Sep 10, 2024
058ff7c
Update sly.csproj
b3b00 Sep 10, 2024
10dab63
Update dotnetcore.yml
b3b00 Sep 10, 2024
16a5716
fix usings
b3b00 Sep 11, 2024
5987e28
Update dotnetcore.yml
b3b00 Sep 11, 2024
5414fab
fix unit tests
b3b00 Sep 11, 2024
020124a
3.5.0-alpha2
b3b00 Sep 11, 2024
ce7b243
generator errors
b3b00 Sep 11, 2024
711c18b
coverlet : excludes samples
b3b00 Sep 11, 2024
87e35b2
cleaning
b3b00 Sep 11, 2024
2e28dff
3.5.0-alpha2
b3b00 Sep 11, 2024
c29f305
parser generator must inherit from AbstractParserGenerator<>
b3b00 Sep 11, 2024
2941348
3.5.0-alpha4 : declare sly nuget as a source generator
b3b00 Sep 11, 2024
6a3c777
Update ParserSyntaxWalker.cs
b3b00 Sep 11, 2024
e83fc1e
Update CslyParserGenerator.cs
b3b00 Sep 11, 2024
d498846
sonar linting
b3b00 Sep 12, 2024
06995fa
sonar linting
b3b00 Sep 12, 2024
65f5173
.
b3b00 Sep 12, 2024
14d985a
cleaning
b3b00 Sep 12, 2024
de58be5
linting
b3b00 Sep 12, 2024
bf1d110
linting
b3b00 Sep 12, 2024
742760b
tame complexity
b3b00 Sep 12, 2024
4494979
taming complexity
b3b00 Sep 12, 2024
dbdb65b
taming complexity
b3b00 Sep 12, 2024
e9c58f5
linting
b3b00 Sep 12, 2024
530183f
fix
b3b00 Sep 12, 2024
be17c25
fix
b3b00 Sep 12, 2024
8cfe208
UT
b3b00 Sep 12, 2024
bb67682
fix
b3b00 Sep 12, 2024
a2f3351
3.5.0-alpha5
b3b00 Sep 12, 2024
1f3e919
using type parameters to type parser generator (avoid typeof in attr…
b3b00 Sep 13, 2024
7f5675a
remove [ParserGenerator] parameters
b3b00 Sep 13, 2024
2ebbe5b
remove deadcode
b3b00 Sep 13, 2024
d825f75
3.5.0-alpha6
b3b00 Sep 13, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
output: 'lcov.net7.0.info'
threshold: 80
outputFormat: 'lcov'
excludes: '[program]*,[expressionParser]*,[jsonparser]*,[while]*,[indentedWhile]*,[SimpleExpressionParser]*,[GenericLexerWithCallbacks]*,[indented]*,[postProcessedLexerParser]*,[XML]*,[SimpleTemplate]*'
excludes: '[program]*,[expressionParser]*,[jsonparser]*,[while]*,[indentedWhile]*,[SimpleExpressionParser]*,[GenericLexerWithCallbacks]*,[indented]*,[postProcessedLexerParser]*,[XML]*,[SimpleTemplate]*,[GeneratedXML]*,[ExplicitTokens]*,[postProcessedLexerParser]*,[GenericLexerWithCallbacks]*'

- name: coveralls
uses: coverallsapp/[email protected]
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ coverage.json
ruleset1.ruleset
opencov.bat
BenchmarkDotNet.Artifacts

*/*.nupkg
*/*.snupkg
src/sly/nupkg/*
14 changes: 14 additions & 0 deletions sly.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XML", "src/samples/XML/XML.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleTemplate", "src/samples/SimpleTemplate/SimpleTemplate.csproj", "{BC5020CA-6BFC-4895-9A1E-99B4A0AEDB11}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GeneratedXML", "src\samples\GeneratedXML\GeneratedXML.csproj", "{7FEF0D32-FFC7-4886-A4B7-71314C25627E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExplicitTokens", "src\samples\ExplicitTokens\ExplicitTokens.csproj", "{94B9B654-82CB-4969-8DCA-250916E53724}"
EndProject
Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
Expand Down Expand Up @@ -120,6 +124,14 @@ Global
{BC5020CA-6BFC-4895-9A1E-99B4A0AEDB11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC5020CA-6BFC-4895-9A1E-99B4A0AEDB11}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC5020CA-6BFC-4895-9A1E-99B4A0AEDB11}.Release|Any CPU.Build.0 = Release|Any CPU
{7FEF0D32-FFC7-4886-A4B7-71314C25627E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7FEF0D32-FFC7-4886-A4B7-71314C25627E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7FEF0D32-FFC7-4886-A4B7-71314C25627E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7FEF0D32-FFC7-4886-A4B7-71314C25627E}.Release|Any CPU.Build.0 = Release|Any CPU
{94B9B654-82CB-4969-8DCA-250916E53724}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94B9B654-82CB-4969-8DCA-250916E53724}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94B9B654-82CB-4969-8DCA-250916E53724}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94B9B654-82CB-4969-8DCA-250916E53724}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -136,6 +148,8 @@ Global
{8F703C3C-0D10-4F43-AC2E-14843D59E460} = {36ED7F1A-2E81-4A71-81FE-A357E5840A33}
{81E72CFA-A6D6-4DB4-B3B5-E167064E7858} = {36ED7F1A-2E81-4A71-81FE-A357E5840A33}
{BC5020CA-6BFC-4895-9A1E-99B4A0AEDB11} = {36ED7F1A-2E81-4A71-81FE-A357E5840A33}
{7FEF0D32-FFC7-4886-A4B7-71314C25627E} = {36ED7F1A-2E81-4A71-81FE-A357E5840A33}
{94B9B654-82CB-4969-8DCA-250916E53724} = {36ED7F1A-2E81-4A71-81FE-A357E5840A33}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {43254130-CF3E-480E-952F-E50CA5D2E417}
Expand Down
27 changes: 27 additions & 0 deletions src/CslyGenerator.Tests/CslyGenerator.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>

<RootNamespace>CslyGenerator.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit" Version="1.1.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\sly\sly.csproj" />
</ItemGroup>


</Project>
255 changes: 255 additions & 0 deletions src/CslyGenerator.Tests/SourceGeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
using System.IO;
using System.Linq;
using sly.sourceGenerator;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Xunit;

namespace CslyGenerator.Tests;

public class SourceGeneratorTests
{
private const string parserClassTest = $@"
using aot.lexer;
using sly.lexer;
using sly.parser.generator;

namespace TestNamespace;

public enum AotTestLexer
{{
[Double]
DOUBLE,
[AlphaId]
IDENTIFIER,
[Sugar(""+"")]
PLUS,
[Sugar(""++"")]
INCREMENT,
[Sugar(""-"")]
MINUS,
[Sugar(""*"")]
TIMES,
[Sugar(""/"")]
DIVIDE,
[Sugar(""("")]
LPAREN,
[Sugar("")"")]
RPAREN,
[Sugar(""!"")]
FACTORIAL,



[Push(""carré"")]
[Sugar(""²"")]
SQUARE,
[Mode(""carré"")]
[Lexeme(""$-$"")]
REGEX,

[Lexeme(GenericToken.KeyWord,""hello"")]
HELLO,
[Lexeme(GenericToken.String)]
STR,
[Lexeme(GenericToken.Int)]
I,
[MultiLineComment(""<!--"",""-->"",channel:Channels.Main)]
[Mode]
COMMENT,
}}

[ParserRoot(""root"")]
[UseMemoization]
[UseBroadentokenWindow]
[AutoCloseIndentationsAttribute]
public class AotTestParser
{{
[Production(""root : SimpleExpressionParser_expressions"")]
public double Root(double value) => value;

[Operation((int) AotTestLexer.PLUS, Affix.InFix, Associativity.Right, 10)]
[Operation(""MINUS"", Affix.InFix, Associativity.Left, 10)]
public double BinaryTermExpression(double left, Token<AotTestLexer> operation, double right)
{{
double result = 0;
switch (operation.TokenID)
{{
case AotTestLexer.PLUS:
{{
result = left + right;
break;
}}
case AotTestLexer.MINUS:
{{
result = left - right;
break;
}}
}}

return result;
}}


[Operation((int) AotTestLexer.TIMES, Affix.InFix, Associativity.Right, 50)]
[Operation(""DIVIDE"", Affix.InFix, Associativity.Left, 50)]
[NodeName(""multiplication_or_division"")]
public double BinaryFactorExpression(double left, Token<AotTestLexer> operation, double right)
{{
double result = 0;
switch (operation.TokenID)
{{
case AotTestLexer.TIMES:
{{
result = left * right;
break;
}}
case AotTestLexer.DIVIDE:
{{
result = left / right;
break;
}}
}}

return result;
}}


[Prefix((int) AotTestLexer.MINUS, Associativity.Right, 100)]
public double PreFixExpression(Token<AotTestLexer> operation, double value)
{{
return -value;
}}

[Postfix((int) AotTestLexer.FACTORIAL, Associativity.Right, 100)]
public double PostFixExpression(double value, Token<AotTestLexer> operation)
{{
if (operation.TokenID == AotTestLexer.SQUARE)
{{
return value * value;
}}
if(operation.TokenID == AotTestLexer.FACTORIAL || operation.Value == ""!"")
{{
var factorial = 1;
for (var i = 1; i <= value; i++) factorial *= i;
return factorial;
}}
return value;
}}

[Operand]
[Production(""operand : primary_value"")]
[NodeName(""double"")]
public double OperandValue(double value)
{{
return value;
}}


[Production(""primary_value : DOUBLE"")]
[NodeName(""double"")]
public double OperandDouble(Token<AotTestLexer> value)
{{
return value.DoubleValue;
}}

[Production(""primary_value : INT"")]
[NodeName(""integer"")]
public double OperandInt(Token<AotTestLexer> value)
{{
return value.DoubleValue;
}}

[Production(""primary_value : LPAREN SimpleExpressionParser_expressions RPAREN"")]
[NodeName(""group"")]
public double OperandGroup(Token<AotTestLexer> lparen, double value, Token<AotTestLexer> rparen)
{{
return value;
}}
}}

[ParserGenerator(typeof(AotTestLexer), typeof(AotTestParser), typeof(double))]
public partial class TestGenerator
{{

}}

public enum ExtendedLexer
{{
[Extension]
EXT,

[Sugar(""-"")]
DASH,

[AlphaNumId]
ID

}}

public class ExtendedLexerParser {{ }}

[ParserGenerator(typeof(ExtendedLexer),typeof(ExtendedLexerParser),typeof(string))]
public partial class ExtendedLexerGenerator : AbstractParserGenerator<ExtendedLexer>
{{
public override Action<ExtendedLexer, LexemeAttribute, GenericLexer<ExtendedLexer>> UseTokenExtensions()
{{
var e = (ExtendedLexer token, LexemeAttribute lexem, GenericLexer<ExtendedLexer> lexer) =>
{{
if (token == ExtendedLexer.EXT)
{{
NodeCallback<GenericToken> callback = (FSMMatch<GenericToken> match) =>
{{
match.Properties[GenericLexer<ExtendedLexer>.DerivedToken] = ExtendedLexer.EXT;
return match;
}};

var fsmBuilder = lexer.FSMBuilder;


fsmBuilder.GoTo(GenericLexer<ExtendedLexer>.start)
.Transition('$')
.Transition('_')
.Transition('$')
.End(GenericToken.Extension) // mark as ending node
.CallBack(callback); // set the ending callback
}}
}};
return e;
}}
}}



";

[Fact]
public void ParserGeneratorTest()
{
// Create an instance of the source generator.
var generator = new CslyParserGenerator();

// Source generators should be tested using 'GeneratorDriver'.
var driver = CSharpGeneratorDriver.Create(new[] { generator });

// To run generators, we can use an empty compilation.
var compilation = CSharpCompilation.Create(nameof(ParserGeneratorTest),
new[] { CSharpSyntaxTree.ParseText(parserClassTest) },
new[]
{
// To support 'System.Attribute' inheritance, add reference to 'System.Private.CoreLib'.
MetadataReference.CreateFromFile(typeof(object).Assembly.Location)
});

// Run generators. Don't forget to use the new compilation rather than the previous one.
var runResult = driver.RunGenerators(compilation).GetRunResult();

var generatedFiles = runResult.GeneratedTrees.Select(x => new FileInfo(x.FilePath).Name).ToArray();

Assert.Equivalent(new[]
{
"TestGenerator.g.cs",
"ExtendedLexerGenerator.g.cs"
}, generatedFiles);
}
}
20 changes: 20 additions & 0 deletions src/CslyGenerator.Tests/Utils/TestAdditionalFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;

namespace CslyGenerator.Tests.Utils;

public class TestAdditionalFile : AdditionalText
{
private readonly SourceText _text;

public TestAdditionalFile(string path, string text)
{
Path = path;
_text = SourceText.From(text);
}

public override SourceText GetText(CancellationToken cancellationToken = new()) => _text;

public override string Path { get; }
}
2 changes: 1 addition & 1 deletion src/benchCurrent/GenericLexerBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private class Config : ManualConfig
{
public Config()
{
var baseJob = Job.MediumRun.With(CsProjCoreToolchain.NetCoreApp70);
var baseJob = Job.MediumRun.WithToolchain(CsProjCoreToolchain.NetCoreApp70);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/benchCurrent/JsonParserBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private class Config : ManualConfig
{
public Config()
{
var baseJob = Job.MediumRun.With(CsProjCoreToolchain.NetCoreApp70);
var baseJob = Job.MediumRun.WithToolchain(CsProjCoreToolchain.NetCoreApp70);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/benchCurrent/SimpleExpressionBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private class Config : ManualConfig
{
public Config()
{
var baseJob = Job.MediumRun.With(CsProjCoreToolchain.NetCoreApp70);
var baseJob = Job.MediumRun.WithToolchain(CsProjCoreToolchain.NetCoreApp70);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/benchCurrent/WhileBench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private class Config : ManualConfig
{
public Config()
{
var baseJob = Job.MediumRun.With(CsProjCoreToolchain.NetCoreApp70);
var baseJob = Job.MediumRun.WithToolchain(CsProjCoreToolchain.NetCoreApp70);
}
}

Expand Down
Loading
Loading