Skip to content

Commit

Permalink
Merge pull request #695 from lucabol/master
Browse files Browse the repository at this point in the history
Add a source generator for a Maths language to the samples
  • Loading branch information
jmarolf authored Jan 14, 2021
2 parents f50de95 + dd1a3f3 commit 4b93c45
Show file tree
Hide file tree
Showing 5 changed files with 502 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ItemGroup>
<AdditionalFiles Include="People.csv" CsvLoadType="Startup" />
<AdditionalFiles Include="Cars.csv" CsvLoadType="OnDemand" CacheObjects="true" />
<AdditionalFiles Include="Geometry.math" />

<AdditionalFiles Include="MainSettings.xmlsettings" CopyToOutputDirectory="PreserveNewest" />
<None Include="MainSettings.xmlsettings" CopyToOutputDirectory="PreserveNewest" /> <!-- TODO: remove this when AdditionalFiles supports CopyToOutputDirectory -->
Expand Down
9 changes: 9 additions & 0 deletions samples/CSharp/SourceGenerators/GeneratedDemo/Geometry.math
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
AreaSquare(l) = pow(l, 2)
AreaRectangle(w, h) = w * h
AreaCircle(r) = pi * r * r
Quadratic(a, b, c) = {-b + sqrt(pow(b,2) - 4 * a * c)} / (2 * a)

GoldenRatio = 1.61803
GoldHarm(n) = GoldenRatio + 1 * ∑(i, 1, n, 1 / i)

D(x', x'', y', y'') = sqrt(pow([x'-x''],2) + pow([y'-y''], 2))
3 changes: 3 additions & 0 deletions samples/CSharp/SourceGenerators/GeneratedDemo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ static void Main(string[] args)

Console.WriteLine("\n\nRunning MustacheGenerator:\n");
UseMustacheGenerator.Run();

Console.WriteLine("\n\nRunning MathsGenerator:\n");
UseMathsGenerator.Run();
}
}
}
15 changes: 15 additions & 0 deletions samples/CSharp/SourceGenerators/GeneratedDemo/UseMathsGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using static System.Console;
using Maths;

namespace GeneratedDemo
{
public static class UseMathsGenerator
{
public static void Run()
{
WriteLine($"The area of a (10, 5) rectangle is: {Formulas.AreaRectangle(10, 5)}");
WriteLine($"The area of a (10) square is: {Formulas.AreaSquare(10)}");
WriteLine($"The GoldHarmon of 3 is: {Formulas.GoldHarm(3)}");
}
}
}
Loading

0 comments on commit 4b93c45

Please sign in to comment.