Skip to content

Commit

Permalink
Merge pull request #41 from b3b00/fix/indented-while-and-related
Browse files Browse the repository at this point in the history
Fix/indented while and related
  • Loading branch information
b3b00 authored Nov 8, 2024
2 parents 3b53c44 + 7984192 commit c401f05
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vs/*
bin/*
obj/*
**/obj/*
Expand Down
4 changes: 4 additions & 0 deletions CliTests/CliTests-debug.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
<EmbeddedResource Include="data\simpleexpr\simpleexpressionparser.csharp" />
<EmbeddedResource Include="data\simpleexpr\simpleexpressiontoken.csharp" />
<EmbeddedResource Include="data\whileGrammar.txt" />
<None Remove="data\indentedWhile.txt" />
<EmbeddedResource Include="data\indentedWhile.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion CliTests/CliTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<ItemGroup>
<!-- <ProjectReference Include="..\..\csly\src\sly\sly.csproj" />-->
<PackageReference Include="sly" Version="3.4.5" />
<PackageReference Include="sly" Version="3.4.6" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Generated/Generated.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="sly" Version="3.4.5" />
<PackageReference Include="sly" Version="3.4.6" />
<!-- <ProjectReference Include="..\..\csly\src\sly\sly.csproj" />-->
</ItemGroup>

Expand Down
6 changes: 4 additions & 2 deletions Tester/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public static List<string> GetLines(this string content)
public static void Main(string[] args)
{
//Compile("C:\\Users\\olduh\\dev\\BlazorCslyViz\\BlazorVizView\\samples\\grammar\\indented-while.txt");
// Extract(@"C:\Users\olduh\dev\csly\src\samples\IndentedWhile\parser\IndentedWhileParserGeneric.cs","C:\\Users\\olduh\\dev\\csly\\src\\samples\\IndentedWhile\\parser\\IndentedWhileTokenGeneric.cs", @"C:\Users\olduh\dev\BlazorCslyViz\BlazorVizView\samples\grammar\indented-while.txt");
Extract(@"C:\Users\olduh\dev\csly\src\samples\IndentedWhile\parser\IndentedWhileParserGeneric.cs",@"C:\Users\olduh\dev\csly\src\samples\IndentedWhile\parser\IndentedWhileTokenGeneric.cs", @"C:\tmp\indented-while.txt");
Parse(@"C:\tmp\indented-while.txt",@"c:/tmp/indented.txt");

// Parse(@"C:\Users\olduh\dev\BlazorCslyViz\BlazorVizView\samples\grammar\indented-while.txt", @"C:\Users\olduh\dev\BlazorCslyViz\BlazorVizView\samples\source\indented-while.txt");
// TestErrorMessages();
TestExpressionNodeNames();
// TestExpressionNodeNames();
}


Expand Down
2 changes: 1 addition & 1 deletion Tester/Tester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<ProjectReference Include="..\csly-cli-model\csly-cli-model.csproj" />
<ProjectReference Include="..\csly-cli-parser\csly-cli-parser.csproj" />
<PackageReference Include="NFluent" Version="3.0.4" />
<PackageReference Include="sly" Version="3.4.5" />
<PackageReference Include="sly" Version="3.4.6" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="System.ValueTuple" Version="4.5.0"/>
<PackageReference Include="System.Collections.Immutable" Version="8.0.0"/>
Expand Down
2 changes: 1 addition & 1 deletion csly-cli-api/CslyProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public CliResult<GeneratedSource> GenerateParser(string grammar, string nameSpac
</PropertyGroup>
<ItemGroup>
<PackageReference Include=""sly"" Version=""3.4.5"" />
<PackageReference Include=""sly"" Version=""3.4.6"" />
</ItemGroup>
</Project>";
Expand Down
2 changes: 1 addition & 1 deletion csly-cli-api/csly-cli-api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<ItemGroup>
<!-- <ProjectReference Include="..\..\csly\src\sly\sly.csproj" />-->
<PackageReference Include="sly" Version="3.4.5" />
<PackageReference Include="sly" Version="3.4.6" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion csly-cli-builder/csly-cli-builder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<!-- <ProjectReference Include="..\..\csly\src\sly\sly.csproj" />-->
<PackageReference Include="sly" Version="3.4.5" />
<PackageReference Include="sly" Version="3.4.6" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion csly-cli-decompiler/csly-cli-decompiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<!-- <ProjectReference Include="..\..\csly\src\sly\sly.csproj" />-->
<PackageReference Include="sly" Version="3.4.5" />
<PackageReference Include="sly" Version="3.4.6" />
</ItemGroup>

</Project>
73 changes: 56 additions & 17 deletions csly-cli-extractor/LexerSpecificationExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ private string Lexeme(string name, GenericToken type, params string[] args)
{
case GenericToken.Date:
{
return $"[Date] {name} : {args[0]} '{args[1]}';";

return $"[Date] {name} : {args[0].Replace($"{nameof(DateFormat)}.","")} {args[1]};";
}
case GenericToken.Comment:
{
if (args.Length == 1)
{
return $"[SingleLineComment] {name} : \"{args[0].Replace("\"","\\\"")}\";";
return $"[SingleLineComment] {name} : {args[0]};";
}
else if (args.Length == 2)
{
return $"[MultiLineComment] {name} : \"{args[0].Replace("\"","\\\"")}\" \"{args[1].Replace("\"","\\\"")}\";";
return $"[MultiLineComment] {name} : {args[0]} {args[1]};";
}

break;
Expand All @@ -43,7 +44,7 @@ private string Lexeme(string name, GenericToken type, params string[] args)
}
else if (args.Length == 1)
{
return $"[Hexa] {name} : \"{args[0].Replace("\"","\\\"")}\";";
return $"[Hexa] {name} : {args[0]};";
}

break;
Expand All @@ -52,7 +53,7 @@ private string Lexeme(string name, GenericToken type, params string[] args)
{
string attr = "AlphaId";
if (args.Length == 1) {
if (Enum.TryParse<IdentifierType>(args[0], out var idType))
if (Enum.TryParse<IdentifierType>(args[0].Replace($"{nameof(IdentifierType)}.",""), out var idType))
{

switch (idType)
Expand Down Expand Up @@ -89,7 +90,7 @@ private string Lexeme(string name, GenericToken type, params string[] args)
b.Append("[Character] ").Append(name);
if (args.Length == 2)
{
b.Append($" : \"{args[0].Replace("\"","\\\"")}\" \"{args[1].Replace("\\","\\\\").Replace("\"","\\\"")}\"");
b.Append($" : {args[0]} {args[1]}");
}

b.Append(";");
Expand All @@ -101,21 +102,21 @@ private string Lexeme(string name, GenericToken type, params string[] args)
b.Append("[String] ").Append(name);
if (args.Length == 2)
{
b.Append($" : \"{args[0].Replace("\"","\\\"")}\" \"{args[1].Replace("\\","\\\\").Replace("\"","\\\"")}\"");
b.Append($" : {args[0]} {args[1]}");
}

b.Append(";");
return b.ToString();
}
case GenericToken.KeyWord:
{
string definitions = string.Join(" ", args.Select(x => "\"" + x.Replace("\"", "\\\"") + "\""));
string definitions = string.Join(" ", args);

return $"[KeyWord] {name} : {definitions};";
}
case GenericToken.SugarToken:
{
return $"[Sugar] {name} : \"{args[0].Replace("\"","\\\"")}\";";
return $"[Sugar] {name} : {args[0]};";
}
default:
{
Expand Down Expand Up @@ -192,14 +193,14 @@ private string Lexeme(string name, string type, params string[] args)
}
else if (type == "UpTo")
{
return $@"[UpTo] {name} : {string.Join(" ",args.Select(x => $@"""{x}"""))}; ";
return $@"[UpTo] {name} : {string.Join(" ",args)}; ";
}

if (type == "Mode")
{
if (args.Any())
{
var t = string.Join(", ",args.Select(x => $@"""{x}"""));
var t = string.Join(", ",args);
return $@"[Mode({t})]";
}

Expand All @@ -210,7 +211,7 @@ private string Lexeme(string name, string type, params string[] args)
{
if (args.Any())
{
var t = string.Join(", ",args.Select(x => $@"""{x}"""));
var t = string.Join(", ",args);
return $@"[Push({t})]";
}

Expand Down Expand Up @@ -304,10 +305,21 @@ public string ExtractFromSource(string lexerSource)
.Where(x => modeAttributes.Contains(x.Name.ToString()));
foreach (var attr in modes)
{
if (attr.Name.ToString() == "Push")
{
;
}
string[] pstrings = new string[] { };
if (attr?.ArgumentList?.Arguments != null && attr.ArgumentList.Arguments.Any())
{
pstrings = attr.ArgumentList.Arguments.Select(x => x.Expression.ExprToString()).ToArray();
pstrings = attr.ArgumentList.Arguments.Select(x =>
{
if (x.Expression.ExprToString() == nameof(ModeAttribute.DefaultLexerMode))
{
return $@"""{ModeAttribute.DefaultLexerMode}""";
}
return x.Expression.ToString();
}).ToArray();
}

var lexeme = Lexeme(member.Identifier.Text, attr.Name.ToString(), pstrings);
Expand All @@ -331,9 +343,13 @@ public string ExtractFromSource(string lexerSource)
}
else
{
string[] pstrings = new string[] { };
List<string> pstrings = new List<string> { };
if (attr?.ArgumentList?.Arguments != null && attr.ArgumentList.Arguments.Any())
{
if (attr.Name.ToString() == "Lexeme")
{
;
}
Predicate<AttributeArgumentSyntax> filter = e =>
{
if (e.NameColon != null && e.NameColon.Name.Identifier.Text == "channel")
Expand All @@ -349,11 +365,34 @@ public string ExtractFromSource(string lexerSource)
return true;
};

pstrings = attr.ArgumentList.Arguments.Where(x => filter(x)).Select(x => x.Expression.ExprToString())
.ToArray();
// pstrings = attr.ArgumentList.Arguments.Where(x => filter(x)).Select(x =>
// {
// if (attr.Name.ToString() == "Lexeme")
// {
//
// }
// return x.Expression.ToString();
// //return x.Expression.ExprToString();
// }).ToList();

for (int i = 0; i < attr.ArgumentList.Arguments.Count; i++)
{
var arg = attr.ArgumentList.Arguments[i];
if (filter(arg))
{
if (attr.Name.ToString() == "Lexeme" && i == 0)
{
pstrings.Add(arg.Expression.ExprToString());
}
else
{
pstrings.Add(arg.Expression.ToString());
}
}
}
}

var lexeme = Lexeme(member.Identifier.Text, attr.Name.ToString(), pstrings);
var lexeme = Lexeme(member.Identifier.Text, attr.Name.ToString(), pstrings.ToArray());
builder.AppendLine(lexeme);
}
}
Expand Down
2 changes: 1 addition & 1 deletion csly-cli-extractor/csly-cli-extractor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>
<ItemGroup>
<!-- <ProjectReference Include="..\..\csly\src\sly\sly.csproj" />-->
<PackageReference Include="sly" Version="3.4.5" />
<PackageReference Include="sly" Version="3.4.6" />
</ItemGroup>


Expand Down
2 changes: 1 addition & 1 deletion csly-cli-model/csly-cli-model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<!-- <ProjectReference Include="..\..\csly\src\sly\sly.csproj" />-->
<PackageReference Include="sly" Version="3.4.5" />
<PackageReference Include="sly" Version="3.4.6" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Collections.Immutable" Version="8.0.0"/>
Expand Down
2 changes: 1 addition & 1 deletion csly-cli-parser/csly-cli-parser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<!-- <ProjectReference Include="..\..\csly\src\sly\sly.csproj" />-->
<PackageReference Include="sly" Version="3.4.5" />
<PackageReference Include="sly" Version="3.4.6" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Collections.Immutable" Version="8.0.0"/>
Expand Down
2 changes: 1 addition & 1 deletion csly-cli/csly-cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<ItemGroup>
<!-- <ProjectReference Include="..\..\csly\src\sly\sly.csproj" />-->
<PackageReference Include="sly" Version="3.4.5" />
<PackageReference Include="sly" Version="3.4.6" />
</ItemGroup>


Expand Down

0 comments on commit c401f05

Please sign in to comment.