Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Install-Package Simpleflow
using Simpleflow;

// Simpleflow Script
var flowScript =
var script =
@"
# Declare and initialize variables
let text = ""Hello, World! 🌄""
let today = $GetCurrentDateTime ( timezone: ""Eastern Standard Time"" )
let text = 'Hello, World! 🌄'
let today = $GetCurrentDateTime ( timezone: 'Eastern Standard Time' )

# Write rules
rule when arg.UniversalId == 2 and (arg.New or arg.Verified) then
Expand All @@ -39,7 +39,7 @@ var flowScript =
";

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

// Access result
Console.WriteLine(result.Messages[0]);
Expand Down
42 changes: 38 additions & 4 deletions src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using Simpleflow.Exceptions;
using Antlr4.Runtime.Tree;

namespace Simpleflow.CodeGenerator
{
Expand Down Expand Up @@ -39,17 +39,20 @@ private Expression GetBoolExpression(string value)
return Expression.Constant(Convert.ToBoolean(value), typeof(bool));
}

private string GetUnquotedText(string @string)
private string GetUnquotedEscapeText(string @string)
{
return @string.Substring(1, @string.Length - 2); // Trim first and last quotes
var text = @string.Substring(1, @string.Length - 2); // Trim first and last quotes
text = text.Replace("\\\"", "\"");
text = text.Replace("\\'", "'");
return text;
}

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

private SmartJsonObjectParameterExpression GetSmartVariable(string name)
private SmartJsonObjectExpression GetSmartVariable(string name)
{
return SmartJsonVariables.SingleOrDefault(s => string.Equals(s.Name, name, StringComparison.OrdinalIgnoreCase));
}
Expand All @@ -64,5 +67,36 @@ private Expression ToStringExpression(Expression obj)
{
return Expression.Call(obj, "ToString", typeArguments: null, arguments: null);
}

private Expression HandleNonBooleanExpression(Expression testExpression)
{
if (testExpression.Type != typeof(bool))
{
return Expression.NotEqual(testExpression, Expression.Default(testExpression.Type));
}
return testExpression;
}

private Expression TransferAnnotationToDescendent(IParseTree parserTree)
{
var child = parserTree.GetChild(0);

// transfer current tree node to child
var targetType = TargetTypeParserContextAnnotation.Get(parserTree);

if (targetType != null)
{
TargetTypeParserContextAnnotation.Put(child, targetType);
}

var exp = Visit(child);

if (targetType != null)
{
TargetTypeParserContextAnnotation.RemoveFrom(child);
}

return exp;
}
}
}
49 changes: 0 additions & 49 deletions src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.SmartVar.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ partial class SimpleflowCodeVisitor<TArg>
{
public override Expression VisitArrayLiteral([NotNull] SimpleflowParser.ArrayLiteralContext context)
{
var arrayValue = context.arrayValue();
var ilArrayValue = new List<Expression>(arrayValue.Length);
SimpleflowParser.ExpressionContext[] arrayValues = context.expression();
var ilArrayValue = new List<Expression>(arrayValues.Length);
Type ilArrayType = null;

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

return Expression.New(constructorInfo, Expression.NewArrayInit(ilArrayType, ilArrayValue));
}

public override Expression VisitArrayValue([NotNull] SimpleflowParser.ArrayValueContext context)
{
return Visit(context.GetChild(0));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Simpleflow.Exceptions;
using Simpleflow.Parser;

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

var messageToken = context.messageText();
return HandleMessageText(messageToken, nameof(FlowOutput.Messages));
var expression = Visit(context.expression());
return EmitMessageText(expression, nameof(FlowOutput.Messages));
}

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

var messageToken = context.messageText();
return HandleMessageText(messageToken, nameof(FlowOutput.Errors));
var expression = Visit(context.expression());
return EmitMessageText(expression, nameof(FlowOutput.Errors));
}

public override Expression VisitOutputStmt(SimpleflowParser.OutputStmtContext context)
Expand All @@ -58,14 +57,13 @@ public override Expression VisitOutputStmt(SimpleflowParser.OutputStmtContext co
return callExpr;
}

private Expression HandleMessageText(SimpleflowParser.MessageTextContext messageToken, string outputProperty)
private Expression EmitMessageText(Expression messageExpression, string outputProperty)
{
var identifier = Visit(messageToken.GetChild(0));
messageExpression = messageExpression.NodeType != ExpressionType.Call && messageExpression.Type == typeof(string)
? messageExpression
: ToStringExpression(messageExpression);

identifier = identifier.NodeType != ExpressionType.Call && identifier.Type == typeof(string) ?
identifier : ToStringExpression(identifier);

return CallListAddMethod(identifier, outputProperty);
return CallListAddMethod(messageExpression, outputProperty);
}

private Expression CallListAddMethod(Expression message, string outputProperty)
Expand Down
Loading