Skip to content

Commit

Permalink
merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Jan 26, 2022
2 parents 53c6a54 + 815db22 commit 7dcea54
Show file tree
Hide file tree
Showing 102 changed files with 13,222 additions and 708 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
pull_request:
branches:
- dev
permissions:
pull-requests: write
jobs:
build:
env:
Expand All @@ -31,12 +33,13 @@ jobs:
- name: Build with dotnet
run: dotnet build --configuration Release
- name: Test with dotnet
uses: b3b00/[email protected].0
uses: b3b00/[email protected].1
id: 'coverlet'
if: env.RUN_TESTS
with:
testProject: ${{env.TESTS_PROJECT}}
output: 'lcov.info'
threshold: 80
outputFormat: 'lcov'
excludes: '[program]*,[expressionParser]*,[jsonparser]*,[while]*,[indentedWhile]*,[SimpleExpressionParser]*,[GenericLexerWithCallbacks]*,[indented]*'
- name: coveralls
Expand All @@ -46,13 +49,17 @@ jobs:
github-token: ${{secrets.GITHUB_TOKEN }}
path-to-lcov: ${{steps.coverlet.outputs.coverageFile}}
- name: ReportGenerator
uses: danielpalme/[email protected].4
uses: danielpalme/[email protected].12
with:
reports: ${{steps.coverlet.outputs.coverageFile}}
targetdir: 'coveragereport'
reporttypes: 'HtmlInline;lcov'
reporttypes: 'HtmlInline;MarkdownSummary'
verbosity: 'Info' # The verbosity level of the log messages. Values: Verbose, Info, Warning, Error, Off
tag: '${{ github.run_number }}_${{ github.run_id }}'
# - name: Publish coverage summary
# uses: marocchino/sticky-pull-request-comment@v2
# with:
# path: coveragereport/Summary.md
- name: publish nuget
if: matrix.os == 'windows-latest' && env.PUBLISH_NUGET
id: publish_nuget
Expand Down Expand Up @@ -89,3 +96,8 @@ jobs:
with:
url: https://camo.githubusercontent.com/12c4fcb3b21fbb2a725fc61449fb1b91e972c4c8a2baaf5904936d8e334bdbe8/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f62336230302f63736c792f62616467652e7376673f6272616e63683d64657626736572766963653d676974687562
method: PURGE
- name: refresh nuget badge
uses: fjogeleit/http-request-action@master
with:
url: https://camo.githubusercontent.com/b0c8ccfcb3256380ae37c312e789e6282143295fa495361ea5c2dbe2169bff8c/68747470733a2f2f696d672e736869656c64732e696f2f6e756765742f762f736c792e737667
method: PURGE
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.localhistory/*
.VSCodeCounter
# User-specific files
*.suo
*.user
Expand Down
10 changes: 0 additions & 10 deletions Directory.Build.props

This file was deleted.

91 changes: 91 additions & 0 deletions Issue254/Bench.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.IO;
using System.Linq.Expressions;
using BenchmarkDotNet.Analysers;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Toolchains.CsProj;
using BravoLights.Ast;
using BravoLights.Common.Ast;
using sly.parser;
using sly.parser.generator;

namespace Issue254
{
public class Bench
{
[MemoryDiagnoser]

[Config(typeof(Config))]
public class JsonParserBench
{


private class Config : ManualConfig
{
public Config()
{
try
{
Console.WriteLine("configuring bench");
var baseJob = Job.MediumRun.WithToolchain(CsProjCoreToolchain.NetCoreApp50);
AddJob(baseJob.WithNuGet("sly", "2.7.0.5").WithId("2.7.0.5"));
AddJob(baseJob.WithNuGet("sly", "2.7.0.4").WithId("2.7.0.4"));
AddJob(baseJob.WithNuGet("sly", "2.7.0.1").WithId("2.7.0.1"));
}
catch (Exception e)
{
Console.WriteLine("in Config : ");
Console.WriteLine(e.Message);
}

}
}

private Parser<ExpressionToken, IAstNode> BenchedParser;



[GlobalSetup]
public void Setup()
{
Console.WriteLine(("SETUP"));

var parserInstance = new MSFSExpressionParser();
var builder = new ParserBuilder<ExpressionToken, IAstNode>();
var result = builder.BuildParser(parserInstance, ParserType.EBNF_LL_RECURSIVE_DESCENT, "MSFSExpressionParser_expressions");

Console.WriteLine("parser built.");
if (result.IsError)
{
Console.WriteLine("ERROR");
result.Errors.ForEach(e => Console.WriteLine(e.Message));
}
else
{
Console.WriteLine("parser ok");
BenchedParser = result.Result;
}

Console.WriteLine($"parser {BenchedParser}");
}

[Benchmark]
public void Test254()
{
if (BenchedParser == null)
{
Console.WriteLine("parser is null");
}
else
{
var ignored = BenchedParser.Parse("-(1+2 * 3)");
}
}



}
}
}
19 changes: 19 additions & 0 deletions Issue254/Issue254.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

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

<!-- <PackageReference Include="BenchmarkDotNet" Version="0.13.1" />-->
<!-- <PackageReference Include="sly" Version="2.7.0.5" />-->
</ItemGroup>

<ItemGroup>
<Compile Remove="Bench.cs" />
</ItemGroup>

</Project>
50 changes: 50 additions & 0 deletions Issue254/Issue254/BinaryExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

using System;
using System.Collections.Generic;

namespace BravoLights.Common.Ast
{
abstract class BinaryExpression<TOutput> : IAstNode
{
internal readonly IAstNode Lhs;
internal readonly IAstNode Rhs;

private object lastLhsValue;
private object lastRhsValue;
private object lastReportedValue;

protected BinaryExpression(IAstNode lhs, IAstNode rhs)
{
Lhs = lhs;
Rhs = rhs;
}

public string ErrorText => null;
public event EventHandler<ValueChangedEventArgs> ValueChanged;

public IEnumerable<IVariable> Variables
{
get
{
foreach (var variable in Lhs.Variables) {
yield return variable;
}
foreach (var variable in Rhs.Variables)
{
yield return variable;
}
}
}

protected abstract string OperatorText { get; }
protected abstract object ComputeValue(object lhsValue, object rhsValue);




public override string ToString()
{
return $"({Lhs} {OperatorText} {Rhs})";
}
}
}
154 changes: 154 additions & 0 deletions Issue254/Issue254/BinaryNumericExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
using System;
using sly.lexer;

namespace BravoLights.Common.Ast
{
enum NumericOperator
{
Plus,
Minus,
Times,
Divide,
BinaryAnd,
BinaryOr
}

/// <summary>
/// A binary expression such as 'X + Y' or 'X / Y', which produces a number from two other numbers and an operator.
/// </summary>
abstract class BinaryNumericExpression : BinaryExpression<double>
{
protected BinaryNumericExpression(IAstNode lhs, IAstNode rhs) : base(lhs, rhs)
{
}

protected abstract double ComputeNumericValue(double lhs, double rhs);

protected override object ComputeValue(object lhsValue, object rhsValue)
{
if (lhsValue is Exception)
{
return lhsValue;
}
if (rhsValue is Exception)
{
return rhsValue;
}
var lhs = Convert.ToDouble(lhsValue);
var rhs = Convert.ToDouble(rhsValue);
return ComputeNumericValue(lhs, rhs);
}

public static BinaryNumericExpression Create(IAstNode lhs, Token<ExpressionToken> op, IAstNode rhs)
{
return op.Value switch
{
"+" => new PlusExpression(lhs, rhs),
"-" => new MinusExpression(lhs, rhs),
"*" => new TimesExpression(lhs, rhs),
"/" => new DivideExpression(lhs, rhs),
"&" => new BitwiseAndExpression(lhs, rhs),
"|" => new BitwiseOrExpression(lhs, rhs),
_ => throw new Exception($"Unexpected operator: {op.Value}"),
};
}

public static BinaryNumericExpression Create(IAstNode lhs, Token<OldExpressionToken> op, IAstNode rhs)
{
return op.Value switch
{
"+" => new PlusExpression(lhs, rhs),
"-" => new MinusExpression(lhs, rhs),
"*" => new TimesExpression(lhs, rhs),
"/" => new DivideExpression(lhs, rhs),
"&" => new BitwiseAndExpression(lhs, rhs),
"|" => new BitwiseOrExpression(lhs, rhs),
_ => throw new Exception($"Unexpected operator: {op.Value}"),
};
}
}

class PlusExpression : BinaryNumericExpression
{
public PlusExpression(IAstNode lhs, IAstNode rhs) : base(lhs, rhs)
{
}

protected override string OperatorText => "+";

protected override double ComputeNumericValue(double lhs, double rhs)
{
return lhs + rhs;
}
}

class MinusExpression : BinaryNumericExpression
{
public MinusExpression(IAstNode lhs, IAstNode rhs) : base(lhs, rhs)
{
}

protected override string OperatorText => "-";

protected override double ComputeNumericValue(double lhs, double rhs)
{
return lhs - rhs;
}
}

class TimesExpression : BinaryNumericExpression
{
public TimesExpression(IAstNode lhs, IAstNode rhs) : base(lhs, rhs)
{
}

protected override string OperatorText => "*";

protected override double ComputeNumericValue(double lhs, double rhs)
{
return lhs * rhs;
}
}

class DivideExpression : BinaryNumericExpression
{
public DivideExpression(IAstNode lhs, IAstNode rhs) : base(lhs, rhs)
{
}

protected override string OperatorText => "/";

protected override double ComputeNumericValue(double lhs, double rhs)
{
return lhs / rhs;
}
}

class BitwiseOrExpression : BinaryNumericExpression
{
public BitwiseOrExpression(IAstNode lhs, IAstNode rhs) : base(lhs, rhs)
{
}

protected override string OperatorText => "|";

protected override double ComputeNumericValue(double lhs, double rhs)
{
return Convert.ToDouble(Convert.ToInt32(lhs) | Convert.ToInt32(rhs));
}
}

class BitwiseAndExpression : BinaryNumericExpression
{
public BitwiseAndExpression(IAstNode lhs, IAstNode rhs) : base(lhs, rhs)
{
}

protected override string OperatorText => "&";

protected override double ComputeNumericValue(double lhs, double rhs)
{
return Convert.ToDouble(Convert.ToInt32(lhs) & Convert.ToInt32(rhs));
}
}
}
Loading

0 comments on commit 7dcea54

Please sign in to comment.