Skip to content

Commit

Permalink
Merge pull request #6 from dynasist/parser-refactor
Browse files Browse the repository at this point in the history
Parser refactor
  • Loading branch information
martonsagi authored Oct 31, 2019
2 parents 923d424 + 5620ec6 commit 6004a78
Show file tree
Hide file tree
Showing 38 changed files with 730 additions and 1,166 deletions.
20 changes: 6 additions & 14 deletions ALObjectParser.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,18 @@ class Program
static void Main(string[] args)
{
var path = args != null && args.Count() > 0 ? args[0] : @".\test_cu.al";
var parser = new ALTestCodeunitParser(path);
var codeunit = parser.Read();
var codeunit = ALParser.ReadSingle(path);

Console.WriteLine($"Object info: {codeunit.Type} {codeunit.Id} {codeunit.Name}");
Console.WriteLine($"Object path: {parser.Path}");
Console.WriteLine($"Object path: {path}");
Console.WriteLine("-----------------------------------------------------------");
foreach (var feature in codeunit.Features)
foreach (var method in codeunit.Methods)
{
Console.WriteLine($"Test Feature: {feature.Name} including {feature.Scenarios.Count()} scenario(s)");
Console.WriteLine($"Method: {method.Name} including {method.Parameters.Count()} pparameter(s)");
Console.WriteLine();
foreach (var scenario in feature.Scenarios)
foreach (var param in method.Parameters)
{
Console.WriteLine($" Test Scenario: #{scenario.ID} {scenario.Name}");

foreach (var element in scenario.Elements)
{
Console.WriteLine($" {element.Type}: {element.Value}");
}

Console.WriteLine();
Console.WriteLine($" Parameter: #{param.Name} {param.Type}");
}
Console.WriteLine("-----------------------------------------------------------");
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 0 additions & 15 deletions ALObjectParser.Library/Enums/ScenarioElementType.cs

This file was deleted.

52 changes: 1 addition & 51 deletions ALObjectParser.Library/Helpers/ALMethodHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static string Write(this ALMethod method)
parameterTxt = String.Join(';', method.Parameters.Select(s => $"{(s.IsVar ? "var " : "")}{s.Name}: {s.Type}"));
}

writer.WriteLine($"{(method.IsLocal ? "local " : "")}{method.MethodKind} {method.Name}({parameterTxt}){(!String.IsNullOrEmpty(method.ReturnType) ? ": " + method.ReturnType : "")}");
writer.WriteLine($"{(method.IsLocal ? "local " : "")}{method.MethodKind} {(method.Name.Contains(" ") ? $"\"{method.Name}\"": method.Name)}({parameterTxt}){(!String.IsNullOrEmpty(method.ReturnType) ? ": " + method.ReturnType : "")}");

if (String.IsNullOrEmpty(method.Content))
{
Expand All @@ -51,55 +51,5 @@ public static string Write(this ALMethod method)

return result;
}

public static string Write(this ITestFeature feature)
{
return $"// [FEATURE] {feature.Name}";
}

public static string Write(this ITestScenario scenario)
{
return $"// [SCENARIO #{scenario.ID:0000}] {scenario.Name}";
}

public static string Write(this ITestScenarioElement element)
{
return $"// [{element.Type}] {element.Value}";
}

public static string WriteMethod(this ITestScenarioElement element, ALParserConfig config = null)
{
var prefix = "";
switch (element.Type)
{
case ScenarioElementType.GIVEN:
prefix = config != null ? config.GivenFunctionPrefix : "Create";
break;
case
ScenarioElementType.WHEN:
prefix = config != null ? config.WhenFunctionPrefix : "Assign";
break;
case ScenarioElementType.THEN:
prefix = config != null ? config.ThenFunctionPrefix : "Verify";
break;
default:
break;
}

return $"{prefix}{element.Value.SanitizeName()}";
}

public static string SanitizeName(this string name)
{
var result =
String.Join("",
Regex
.Split(name, @"\W", RegexOptions.CultureInvariant)
.Where(s => !string.IsNullOrEmpty(s))
.Select(s => Regex.Replace(s, "^.", m => m.Value.ToUpperInvariant()))
);

return result;
}
}
}
20 changes: 0 additions & 20 deletions ALObjectParser.Library/Helpers/TestFeatureComparer.cs

This file was deleted.

20 changes: 0 additions & 20 deletions ALObjectParser.Library/Helpers/TestFeatureNameComparer.cs

This file was deleted.

20 changes: 0 additions & 20 deletions ALObjectParser.Library/Helpers/TestScenarioComparer.cs

This file was deleted.

19 changes: 0 additions & 19 deletions ALObjectParser.Library/Helpers/TestScenarioElementComparer.cs

This file was deleted.

20 changes: 0 additions & 20 deletions ALObjectParser.Library/Helpers/TestScenarioIDComparer.cs

This file was deleted.

5 changes: 3 additions & 2 deletions ALObjectParser.Library/Interfaces/IALObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public interface IALObject
int Id { get; set; }
ALObjectType Type { get; set; }
string Name { get; set; }
List<ALMethod> Methods { get; set; }
List<ITestFeature> Features { get; set; }
ICollection<ALMethod> Methods { get; set; }
ICollection<ALProperty> Properties { get; set; }
ICollection<ALComment> Comments { get; set; }
}
}
13 changes: 0 additions & 13 deletions ALObjectParser.Library/Interfaces/ITestFeature.cs

This file was deleted.

14 changes: 0 additions & 14 deletions ALObjectParser.Library/Interfaces/ITestScenario.cs

This file was deleted.

12 changes: 0 additions & 12 deletions ALObjectParser.Library/Interfaces/ITestScenarioElement.cs

This file was deleted.

8 changes: 5 additions & 3 deletions ALObjectParser.Library/Models/ALObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ public class ALObject: IALObject
public ALObject()
{
Methods = new List<ALMethod>();
Properties = new List<ALProperty>();
Comments = new List<ALComment>();
}

public int Id { get; set; }
public ALObjectType Type { get; set; }
public string Name { get; set; }

public List<ALMethod> Methods { get; set; }
public List<ITestFeature> Features { get; set; }
public IEnumerable<ALProperty> Properties { get; set; }
public ICollection<ALMethod> Methods { get; set; }
public ICollection<ALProperty> Properties { get; set; }
public ICollection<ALComment> Comments { get; set; }
}
}
9 changes: 9 additions & 0 deletions ALObjectParser.Library/Models/ALObjectParts/ALComment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ALObjectParser.Library
{
public class ALComment
{
public string Content { get; set; }
public int StartPos { get; set; }
public int EndPos { get; set; }
}
}
4 changes: 3 additions & 1 deletion ALObjectParser.Library/Models/ALObjectParts/ALMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public ALMethod()
{
Parameters = new List<ALParameter>();
Attributes = new List<ALAttribute>();
Comments = new List<ALComment>();
}

public string Name { get; set; }
Expand All @@ -16,8 +17,9 @@ public ALMethod()
public bool IsLocal { get; set; }
public ICollection<ALParameter> Parameters { get; set; }
public string ReturnType { get; set; }
public ITestScenario Scenario { get; set; }
public string Content { get; set; }
public ALMethodBody MethodBody { get; set; }
public ICollection<ALAttribute> Attributes { get; set; }
public IEnumerable<ALComment> Comments { get; set; }
}
}
16 changes: 16 additions & 0 deletions ALObjectParser.Library/Models/ALObjectParts/ALMethodBody.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;

namespace ALObjectParser.Library
{
public class ALMethodBody
{
public ALMethodBody()
{
Comments = new List<ALComment>();
}

public IEnumerable<string> ContentLines { get; set; }
public string Content { get; set; }
public IEnumerable<ALComment> Comments { get; set; }
}
}
34 changes: 34 additions & 0 deletions ALObjectParser.Library/Models/ALObjectTypeMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ALObjectParser.Library
{
public class ALObjectTypeMap: Dictionary<ALObjectType, Type>
{
public ALObjectTypeMap()
{
Add(ALObjectType.table, typeof(ALTable));
Add(ALObjectType.tableextension, typeof(ALTableExtension));
Add(ALObjectType.page, typeof(ALPage));
Add(ALObjectType.pagecustomization, typeof(ALPageCustomization));
Add(ALObjectType.pageextension, typeof(ALPageExtension));
Add(ALObjectType.report, typeof(ALTable));
Add(ALObjectType.xmlport, typeof(ALTable));
Add(ALObjectType.query, typeof(ALTable));
Add(ALObjectType.codeunit, typeof(ALCodeunit));
Add(ALObjectType.controladdin, typeof(ALTable));
Add(ALObjectType.dotnet, typeof(ALTable));
Add(ALObjectType.@enum, typeof(ALTable));
Add(ALObjectType.profile, typeof(ALTable));
}

public static IALObject CreateInstance(ALObjectType type)
{
var items = new ALObjectTypeMap();
dynamic instance = Activator.CreateInstance(items[type]);

return instance;
}
}
}
Loading

0 comments on commit 6004a78

Please sign in to comment.