Skip to content

Commit fcdc942

Browse files
authored
Merge pull request #25 from navtech-io/develop
Develop
2 parents 0176947 + 57e5f1d commit fcdc942

38 files changed

+2532
-2840
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ Install-Package Simpleflow
2323
using Simpleflow;
2424

2525
// Simpleflow Script
26-
var flowScript =
26+
var script =
2727
@"
2828
# Declare and initialize variables
29-
let text = ""Hello, World! 🌄""
30-
let today = $GetCurrentDateTime ( timezone: ""Eastern Standard Time"" )
29+
let text = 'Hello, World! 🌄'
30+
let today = $GetCurrentDateTime ( timezone: 'Eastern Standard Time' )
3131
3232
# Write rules
3333
rule when arg.UniversalId == 2 and (arg.New or arg.Verified) then
@@ -39,7 +39,7 @@ var flowScript =
3939
";
4040

4141
// Execute Script
42-
FlowOutput result = SimpleflowEngine.Run(flowScript, new {UniversalId = 2, New=true, Verified=false} );
42+
FlowOutput result = SimpleflowEngine.Run(script, new {UniversalId = 2, New=true, Verified=false} );
4343

4444
// Access result
4545
Console.WriteLine(result.Messages[0]);

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.Helpers.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System;
55
using System.Linq;
66
using System.Linq.Expressions;
7-
using Simpleflow.Exceptions;
7+
using Antlr4.Runtime.Tree;
88

99
namespace Simpleflow.CodeGenerator
1010
{
@@ -39,17 +39,20 @@ private Expression GetBoolExpression(string value)
3939
return Expression.Constant(Convert.ToBoolean(value), typeof(bool));
4040
}
4141

42-
private string GetUnquotedText(string @string)
42+
private string GetUnquotedEscapeText(string @string)
4343
{
44-
return @string.Substring(1, @string.Length - 2); // Trim first and last quotes
44+
var text = @string.Substring(1, @string.Length - 2); // Trim first and last quotes
45+
text = text.Replace("\\\"", "\"");
46+
text = text.Replace("\\'", "'");
47+
return text;
4548
}
4649

4750
private ParameterExpression GetVariable(string name)
4851
{
4952
return Variables.SingleOrDefault(@var => string.Equals(@var.Name , name, StringComparison.OrdinalIgnoreCase));
5053
}
5154

52-
private SmartJsonObjectParameterExpression GetSmartVariable(string name)
55+
private SmartJsonObjectExpression GetSmartVariable(string name)
5356
{
5457
return SmartJsonVariables.SingleOrDefault(s => string.Equals(s.Name, name, StringComparison.OrdinalIgnoreCase));
5558
}
@@ -64,5 +67,36 @@ private Expression ToStringExpression(Expression obj)
6467
{
6568
return Expression.Call(obj, "ToString", typeArguments: null, arguments: null);
6669
}
70+
71+
private Expression HandleNonBooleanExpression(Expression testExpression)
72+
{
73+
if (testExpression.Type != typeof(bool))
74+
{
75+
return Expression.NotEqual(testExpression, Expression.Default(testExpression.Type));
76+
}
77+
return testExpression;
78+
}
79+
80+
private Expression TransferAnnotationToDescendent(IParseTree parserTree)
81+
{
82+
var child = parserTree.GetChild(0);
83+
84+
// transfer current tree node to child
85+
var targetType = TargetTypeParserContextAnnotation.Get(parserTree);
86+
87+
if (targetType != null)
88+
{
89+
TargetTypeParserContextAnnotation.Put(child, targetType);
90+
}
91+
92+
var exp = Visit(child);
93+
94+
if (targetType != null)
95+
{
96+
TargetTypeParserContextAnnotation.RemoveFrom(child);
97+
}
98+
99+
return exp;
100+
}
67101
}
68102
}

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.SmartVar.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitArithmeticExpression.cs

Lines changed: 0 additions & 106 deletions
This file was deleted.

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitArray.cs renamed to src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitArrayLiteral.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ partial class SimpleflowCodeVisitor<TArg>
1515
{
1616
public override Expression VisitArrayLiteral([NotNull] SimpleflowParser.ArrayLiteralContext context)
1717
{
18-
var arrayValue = context.arrayValue();
19-
var ilArrayValue = new List<Expression>(arrayValue.Length);
18+
SimpleflowParser.ExpressionContext[] arrayValues = context.expression();
19+
var ilArrayValue = new List<Expression>(arrayValues.Length);
2020
Type ilArrayType = null;
2121

2222
// process each value in array
23-
foreach (var value in arrayValue)
23+
foreach (var value in arrayValues)
2424
{
2525
var ilexp = value.Accept(this);
2626
if (ilexp != null)
@@ -53,10 +53,5 @@ public override Expression VisitArrayLiteral([NotNull] SimpleflowParser.ArrayLit
5353

5454
return Expression.New(constructorInfo, Expression.NewArrayInit(ilArrayType, ilArrayValue));
5555
}
56-
57-
public override Expression VisitArrayValue([NotNull] SimpleflowParser.ArrayValueContext context)
58-
{
59-
return Visit(context.GetChild(0));
60-
}
6156
}
6257
}

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitEmitters.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq.Expressions;
7-
using Simpleflow.Exceptions;
87
using Simpleflow.Parser;
98

109
namespace Simpleflow.CodeGenerator
@@ -17,8 +16,8 @@ public override Expression VisitMessageStmt(SimpleflowParser.MessageStmtContext
1716
if (context.exception != null)
1817
throw context.exception;
1918

20-
var messageToken = context.messageText();
21-
return HandleMessageText(messageToken, nameof(FlowOutput.Messages));
19+
var expression = Visit(context.expression());
20+
return EmitMessageText(expression, nameof(FlowOutput.Messages));
2221
}
2322

2423
public override Expression VisitExitStmt(SimpleflowParser.ExitStmtContext context)
@@ -31,8 +30,8 @@ public override Expression VisitErrorStmt(SimpleflowParser.ErrorStmtContext cont
3130
if (context.exception != null)
3231
throw context.exception;
3332

34-
var messageToken = context.messageText();
35-
return HandleMessageText(messageToken, nameof(FlowOutput.Errors));
33+
var expression = Visit(context.expression());
34+
return EmitMessageText(expression, nameof(FlowOutput.Errors));
3635
}
3736

3837
public override Expression VisitOutputStmt(SimpleflowParser.OutputStmtContext context)
@@ -58,14 +57,13 @@ public override Expression VisitOutputStmt(SimpleflowParser.OutputStmtContext co
5857
return callExpr;
5958
}
6059

61-
private Expression HandleMessageText(SimpleflowParser.MessageTextContext messageToken, string outputProperty)
60+
private Expression EmitMessageText(Expression messageExpression, string outputProperty)
6261
{
63-
var identifier = Visit(messageToken.GetChild(0));
62+
messageExpression = messageExpression.NodeType != ExpressionType.Call && messageExpression.Type == typeof(string)
63+
? messageExpression
64+
: ToStringExpression(messageExpression);
6465

65-
identifier = identifier.NodeType != ExpressionType.Call && identifier.Type == typeof(string) ?
66-
identifier : ToStringExpression(identifier);
67-
68-
return CallListAddMethod(identifier, outputProperty);
66+
return CallListAddMethod(messageExpression, outputProperty);
6967
}
7068

7169
private Expression CallListAddMethod(Expression message, string outputProperty)

0 commit comments

Comments
 (0)