diff --git a/.gitignore b/.gitignore index 12428f8..6189d11 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.vs/* bin/* obj/* **/obj/* diff --git a/CliTests/CliTests-debug.csproj b/CliTests/CliTests-debug.csproj index 8bd750b..1ee9999 100644 --- a/CliTests/CliTests-debug.csproj +++ b/CliTests/CliTests-debug.csproj @@ -71,6 +71,10 @@ + + + Always + diff --git a/CliTests/CliTests.csproj b/CliTests/CliTests.csproj index 23e7b78..7121b87 100644 --- a/CliTests/CliTests.csproj +++ b/CliTests/CliTests.csproj @@ -32,7 +32,7 @@ - + diff --git a/Generated/Generated.csproj b/Generated/Generated.csproj index 872247d..b3c6aef 100644 --- a/Generated/Generated.csproj +++ b/Generated/Generated.csproj @@ -13,7 +13,7 @@ - + diff --git a/Tester/Program.cs b/Tester/Program.cs index 94142a1..f60b35f 100644 --- a/Tester/Program.cs +++ b/Tester/Program.cs @@ -29,10 +29,12 @@ public static List 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(); } diff --git a/Tester/Tester.csproj b/Tester/Tester.csproj index a6a08bd..39151aa 100644 --- a/Tester/Tester.csproj +++ b/Tester/Tester.csproj @@ -23,7 +23,7 @@ - + diff --git a/csly-cli-api/CslyProcessor.cs b/csly-cli-api/CslyProcessor.cs index 81dc81a..ae6dd28 100644 --- a/csly-cli-api/CslyProcessor.cs +++ b/csly-cli-api/CslyProcessor.cs @@ -247,7 +247,7 @@ public CliResult GenerateParser(string grammar, string nameSpac - + "; diff --git a/csly-cli-api/csly-cli-api.csproj b/csly-cli-api/csly-cli-api.csproj index 945a945..867870d 100644 --- a/csly-cli-api/csly-cli-api.csproj +++ b/csly-cli-api/csly-cli-api.csproj @@ -19,7 +19,7 @@ - + diff --git a/csly-cli-builder/csly-cli-builder.csproj b/csly-cli-builder/csly-cli-builder.csproj index c867c7f..45b2d0c 100644 --- a/csly-cli-builder/csly-cli-builder.csproj +++ b/csly-cli-builder/csly-cli-builder.csproj @@ -14,7 +14,7 @@ - + diff --git a/csly-cli-decompiler/csly-cli-decompiler.csproj b/csly-cli-decompiler/csly-cli-decompiler.csproj index abf6ebb..a7dc76c 100644 --- a/csly-cli-decompiler/csly-cli-decompiler.csproj +++ b/csly-cli-decompiler/csly-cli-decompiler.csproj @@ -10,7 +10,7 @@ - + diff --git a/csly-cli-extractor/LexerSpecificationExtractor.cs b/csly-cli-extractor/LexerSpecificationExtractor.cs index 28ae8ea..3a00943 100644 --- a/csly-cli-extractor/LexerSpecificationExtractor.cs +++ b/csly-cli-extractor/LexerSpecificationExtractor.cs @@ -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; @@ -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; @@ -52,7 +53,7 @@ private string Lexeme(string name, GenericToken type, params string[] args) { string attr = "AlphaId"; if (args.Length == 1) { - if (Enum.TryParse(args[0], out var idType)) + if (Enum.TryParse(args[0].Replace($"{nameof(IdentifierType)}.",""), out var idType)) { switch (idType) @@ -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(";"); @@ -101,7 +102,7 @@ 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(";"); @@ -109,13 +110,13 @@ private string Lexeme(string name, GenericToken type, params string[] args) } 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: { @@ -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})]"; } @@ -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})]"; } @@ -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); @@ -331,9 +343,13 @@ public string ExtractFromSource(string lexerSource) } else { - string[] pstrings = new string[] { }; + List pstrings = new List { }; if (attr?.ArgumentList?.Arguments != null && attr.ArgumentList.Arguments.Any()) { + if (attr.Name.ToString() == "Lexeme") + { + ; + } Predicate filter = e => { if (e.NameColon != null && e.NameColon.Name.Identifier.Text == "channel") @@ -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); } } diff --git a/csly-cli-extractor/csly-cli-extractor.csproj b/csly-cli-extractor/csly-cli-extractor.csproj index ef0bd50..03702d1 100644 --- a/csly-cli-extractor/csly-cli-extractor.csproj +++ b/csly-cli-extractor/csly-cli-extractor.csproj @@ -12,7 +12,7 @@ - + diff --git a/csly-cli-model/csly-cli-model.csproj b/csly-cli-model/csly-cli-model.csproj index a4d29c9..0ffb22c 100644 --- a/csly-cli-model/csly-cli-model.csproj +++ b/csly-cli-model/csly-cli-model.csproj @@ -9,7 +9,7 @@ - + diff --git a/csly-cli-parser/csly-cli-parser.csproj b/csly-cli-parser/csly-cli-parser.csproj index e6aa607..4b4521c 100644 --- a/csly-cli-parser/csly-cli-parser.csproj +++ b/csly-cli-parser/csly-cli-parser.csproj @@ -8,7 +8,7 @@ - + diff --git a/csly-cli/csly-cli.csproj b/csly-cli/csly-cli.csproj index e476391..dc981ed 100644 --- a/csly-cli/csly-cli.csproj +++ b/csly-cli/csly-cli.csproj @@ -28,7 +28,7 @@ - +