Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Apr 24, 2024
1 parent ad2d6b6 commit 7c1e342
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
43 changes: 43 additions & 0 deletions Tests/ExtractionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,49 @@ public void TestManyLexemGrammarCompileThenDecompileThenTest_Grammar1()
;
}

[Fact]
public void TestDateCompileThenDecompileThenTest()
{
CultureInfo ci = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
var grammar = @"
genericLexer DateLexer;
[Date] DATE : YYYYMMDD '-';
parser DateParser;
-> root : DATE;
";

var builder = new ParserBuilder();
var model = builder.CompileModel(grammar, "DateParser");
Check.That(model).IsOkModel();
var errors = model.Error;

var p = builder.BuildParser(model);
Check.That(p.lexerType).IsNotNull();
Check.That(p.parserType).IsNotNull();

var decompiler = new Decompiler();
var decompiled = decompiler.Decompile(p.lexerType, p.parserType);
Check.That(decompiled).IsNotNull().And.IsNotEmpty();
builder.CompileModel(decompiled, "Many");

var parseResult = builder.Getz(decompiled, "2024-04-24", "MyParser1", new List<(string format, SyntaxTreeProcessor processor)>() {("JSON",ParserBuilder.SyntaxTreeToJson)}, rootRule:"expression");
Check.That(parseResult.IsError).IsFalse();
var r = parseResult.Value[0];
Check.That(r.format).IsEqualTo("JSON");
Check.That(r.content).IsNotNull().And.IsNotEmpty();
var json = r.content;
var o = JsonConvert.DeserializeObject<JObject>(json);
var if1 = o.SelectTokens("$..Token.Value");
var tokens = if1.ToList().Select(x => x.Value<string>()).ToList();
Check.That(tokens).ContainsExactly(new List<string>() { "2024-04-24" });
;
}


[Fact]
public void TestManyLexemGrammarGeneration()
Expand Down
2 changes: 1 addition & 1 deletion Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="SharpCoreFileSystem" Version="1.0.4" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NFluent" Version="3.0.0.277-beta" />
<PackageReference Include="NFluent" Version="3.0.4" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
7 changes: 3 additions & 4 deletions csly-cli-builder/Result.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@


using System.Diagnostics.CodeAnalysis;

namespace clsy.cli.builder;

public class Result<T> : Result<T, List<string>>
{
public Result() : base()
{
}

public Result(T value) : base(value)
{
Expand Down Expand Up @@ -34,13 +33,13 @@ public Result(List<string> error) : base (error)
return new Result<T>(error);
}

[ExcludeFromCodeCoverage]
public override string ToString()
{
if (IsError)
{
return "ERROR\n"+string.Join("\n", Error as List<string>);
}

return "OK";
}
}
Expand Down
2 changes: 2 additions & 0 deletions csly-cli-decompiler/Decompiler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text;

Expand All @@ -22,6 +23,7 @@ public string Decompile(Type lexerType, Type parserType)
return builder.ToString();
}

[ExcludeFromCodeCoverage]
public string Decompile(string lexerFqn, string parserFqn, string assemblyPath)
{
var assembly = Assembly.LoadFrom(assemblyPath);
Expand Down
6 changes: 3 additions & 3 deletions csly-cli-parser/ParserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ namespace csly.cli.parser;
public class ParserContext
{
private List<string> EnumNames = new List<string>();
public string ParserName { get; private set; }

public string _parserName;

public ParserContext(string parserName)
{
ParserName = parserName;
_parserName = parserName;
}

public void AddEnumName(string name)
Expand Down

0 comments on commit 7c1e342

Please sign in to comment.