-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
270 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>ConsoleApp2</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\csly-cli-api\csly-cli-api.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
|
||
|
||
|
||
using csly_cli_api; | ||
|
||
namespace csly_cli_api | ||
{ | ||
|
||
public class Program | ||
{ | ||
|
||
public static void Main(string[] args) | ||
{ | ||
var grammar = @" | ||
genericLexer MinimalLexer; | ||
[Date] DATE : YYYYMMDD '-'; | ||
parser MinimalParser; | ||
-> root : DATE ; | ||
"; | ||
|
||
string source = @" | ||
2024-05-07 | ||
"; | ||
|
||
|
||
var r = CslyProcessor.GetDot(grammar, source); | ||
if (r.IsOK) | ||
{ | ||
Console.WriteLine(r.Result); | ||
} | ||
|
||
else | ||
{ | ||
foreach (var error in r.Errors) | ||
{ | ||
Console.WriteLine(error); | ||
} | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace csly.cli.model.parser; | ||
|
||
public class LexerOptions : ICLIModel | ||
{ | ||
public bool IgnoreWS { get; set; } | ||
|
||
public bool IgnoreEOL { get; set; } | ||
|
||
public bool IgnoreKeyWordCase { get; set; } | ||
|
||
public bool IndentationAware { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using sly.parser.generator; | ||
|
||
namespace csly.cli.model.parser; | ||
|
||
public class ParserOptimization : ICLIModel | ||
{ | ||
public bool UseMemoization { get; set; } | ||
public bool BroadenTokenWindow { get; set; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using clsy.cli.builder.parser; | ||
|
||
namespace csly_cli_api; | ||
|
||
|
||
|
||
public class CliResult | ||
{ | ||
private bool _isOk; | ||
|
||
public bool IsOK => _isOk; | ||
|
||
private string _result; | ||
|
||
public string Result => _result; | ||
|
||
private List<string> _errors; | ||
|
||
public List<string> Errors => _errors; | ||
|
||
public CliResult(List<string> errors) | ||
{ | ||
_isOk = false; | ||
_errors = errors; | ||
} | ||
|
||
public CliResult(string result) | ||
{ | ||
_isOk = true; | ||
_result = result; | ||
} | ||
} | ||
|
||
public class CslyProcessor | ||
{ | ||
public static CliResult GetDot(string grammar, string source) | ||
{ | ||
var builder = new ParserBuilder(); | ||
var model = builder.CompileModel(grammar, "MinimalParser"); | ||
if (model.IsOk) | ||
{ | ||
var r = builder.Getz(grammar, source, "TestParser", | ||
new List<(string format, SyntaxTreeProcessor processor)>() | ||
{ ("DOT", (SyntaxTreeProcessor)ParserBuilder.SyntaxTreeToDotGraph) }); | ||
if (r.IsError) | ||
{ | ||
return new CliResult(r.Error.Select(x => $"parse error : {x}").ToList()); | ||
} | ||
else | ||
{ | ||
return new CliResult(r.Value[0].content); | ||
} | ||
} | ||
else | ||
{ | ||
return new CliResult(model.Error.Select(x => $"grammar error : {x}").ToList()); | ||
} | ||
} | ||
|
||
public static CliResult GetJson(string grammar, string source) | ||
{ | ||
var builder = new ParserBuilder(); | ||
var model = builder.CompileModel(grammar, "MinimalParser"); | ||
if (model.IsOk) | ||
{ | ||
var r = builder.Getz(grammar, source, "TestParser", | ||
new List<(string format, SyntaxTreeProcessor processor)>() | ||
{ ("JSON", (SyntaxTreeProcessor)ParserBuilder.SyntaxTreeToDotGraph) }); | ||
if (r.IsError) | ||
{ | ||
return new CliResult(r.Error.Select(x => $"parse error : {x}").ToList()); | ||
} | ||
else | ||
{ | ||
return new CliResult(r.Value[0].content); | ||
} | ||
} | ||
else | ||
{ | ||
return new CliResult(model.Error.Select(x => $"grammar error : {x}").ToList()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>csly_cli_api</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\csly-cli-builder\csly-cli-builder.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="sly" Version="3.1.4" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace csly.cli.model.parser; | ||
|
||
public class IndentClause : IClause | ||
{ | ||
public override string ToString() | ||
{ | ||
return "INDENT"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.