Skip to content

Commit f79c553

Browse files
authored
Merge pull request #26 from navtech-io/develop
Fix - able to write expression without space between operand and oper…
2 parents fcdc942 + 0b1b282 commit f79c553

24 files changed

+766
-484
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ using Simpleflow;
2626
var script =
2727
@"
2828
# Declare and initialize variables
29-
let text = 'Hello, World! 🌄'
30-
let today = $GetCurrentDateTime ( timezone: 'Eastern Standard Time' )
29+
let today = $GetCurrentDate()
3130
3231
# Write rules
33-
rule when arg.UniversalId == 2 and (arg.New or arg.Verified) then
34-
message text
32+
rule when arg.UniversalId == 2
33+
and (arg.New or arg.Verified) then
34+
message 'Hello, World! 🌄'
3535
end rule
3636
3737
# Output

build/Build.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,16 @@ class Build : NukeBuild
121121
.SetTitle("Simpleflow")
122122
.SetAuthors("navtech.io")
123123
.SetCopyright("navtech.io")
124-
.SetPackageProjectUrl("https://github.com/navtech-io/Simpleflow")
124+
.SetPackageProjectUrl("https://navtech-io.github.io/Simpleflow/")
125+
.SetRepositoryUrl("https://github.com/navtech-io/Simpleflow")
125126
.AddProperty("PackageLicenseExpression", "Apache-2.0")
126127
.AddProperty("PackageIcon", @"PackageIcon.png")
127128
.SetPackageRequireLicenseAcceptance(true)
128129
.SetIncludeSymbols(true)
129-
.SetDescription("A .NET library and a runtime engine to execute dynamic rules and workflows with intuitive and simple Simpleflow scripting language.")
130-
.SetPackageTags("Simpleflow.NET Workflow RuleEngine DynamicValidations DynamicExpressionEvaluator")
130+
.SetDescription("A .NET library and a runtime engine to execute dynamic rules and workflows with intuitive and simple declarative Simpleflow scripting language.")
131+
.SetPackageTags("Simpleflow.NET Workflow Rule-Engine Dynamic-Validations Dynamic-Expression-Evaluator")
131132
.SetNoDependencies(true)
132-
.SetOutputDirectory(ArtifactsDirectory / "nuget"));
133+
.SetOutputDirectory(ArtifactsDirectory / "nuget")); ;
133134
});
134135

135136
Target Publish => _ => _

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.VisitExpression.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ namespace Simpleflow.CodeGenerator
1111
partial class SimpleflowCodeVisitor<TArg>
1212
{
1313

14+
public override Expression VisitUniaryPlusExpression([NotNull] SimpleflowParser.UniaryPlusExpressionContext context)
15+
{
16+
return Expression.UnaryPlus(Visit(context.expression()));
17+
}
18+
19+
public override Expression VisitUniaryMinusExpression([NotNull] SimpleflowParser.UniaryMinusExpressionContext context)
20+
{
21+
return Expression.Negate(Visit(context.expression()));
22+
}
23+
1424
public override Expression VisitMultiplicativeExpression([NotNull] SimpleflowParser.MultiplicativeExpressionContext context)
1525
{
1626
var symbolNode = (ITerminalNode)context.GetChild(1); // exp(0) operator(1) exp(2)

src/Simpleflow/CodeGenerator/SimpleflowCodeVisitor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public SimpleflowCodeVisitor(IFunctionRegister functionRegister, ParserEventPubl
4242
InputParam = Expression.Parameter(typeof(TArg));
4343
OutputParam = Expression.Parameter(typeof(FlowOutput));
4444
// use context parameter name in order to access in script
45-
ScriptHelperContextParam = Expression.Parameter(typeof(ScriptHelperContext));
45+
ScriptHelperContextParam = Expression.Parameter(typeof(RuntimeContext));
4646

4747
/* A label expression of the void type that is the target for Expression.Return(). */
4848
TargetLabelToExitFunction = Expression.Label();
@@ -67,8 +67,8 @@ public override Expression VisitProgram(SimpleflowParser.ProgramContext context)
6767
Expression body = Expression.Block(Variables, statementExpressions);
6868

6969
/* Create function with input and output parameters */
70-
Expression<Action<TArg, FlowOutput, ScriptHelperContext>> program =
71-
Expression.Lambda<Action<TArg /*input-context*/, FlowOutput, ScriptHelperContext>>(
70+
Expression<Action<TArg, FlowOutput, RuntimeContext>> program =
71+
Expression.Lambda<Action<TArg /*input-context*/, FlowOutput, RuntimeContext>>(
7272
body,
7373
new ParameterExpression[] { InputParam, OutputParam, ScriptHelperContextParam }
7474
);
@@ -234,7 +234,7 @@ private void ReplaceVirtualSmartVariablesWithReal(List<Expression> statementExpr
234234
private List<Expression> CreateDefaultVariablesAndAssign()
235235
{
236236
var argVar = Expression.Variable(typeof(TArg), "arg");
237-
var contextVar = Expression.Variable(typeof(ScriptHelperContext), "context");
237+
var contextVar = Expression.Variable(typeof(RuntimeContext), "context");
238238

239239
Variables.Add(argVar);
240240
Variables.Add(contextVar);

src/Simpleflow/CodeGenerator/SimpleflowCompiler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Simpleflow.CodeGenerator
1414
{
1515
internal class SimpleflowCompiler
1616
{
17-
internal static Action<TArg, FlowOutput, ScriptHelperContext> Compile<TArg>(string code,
17+
internal static Action<TArg, FlowOutput, RuntimeContext> Compile<TArg>(string code,
1818
IFunctionRegister activityRegister,
1919
ParserEventPublisher eventPublisher)
2020
{
@@ -31,7 +31,7 @@ internal static Action<TArg, FlowOutput, ScriptHelperContext> Compile<TArg>(stri
3131
var program = visitor.Visit(programContext);
3232

3333
// Compile
34-
var programExpression = (Expression<Action<TArg, FlowOutput, ScriptHelperContext>>)program;
34+
var programExpression = (Expression<Action<TArg, FlowOutput, RuntimeContext>>)program;
3535
return programExpression.CompileFast();
3636
}
3737

src/Simpleflow/FlowContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void EnableTrace()
3434

3535
public class FlowInternals
3636
{
37-
public Action<TArg, FlowOutput, ScriptHelperContext> CompiledScript { get; set; }
37+
public Action<TArg, FlowOutput, RuntimeContext> CompiledScript { get; set; }
3838
}
3939
}
4040
}

src/Simpleflow/Parser/Grammar/SimpleflowLexer.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Not: 'not';
6666
// Literals
6767
True: 'true';
6868
False: 'false';
69-
Number: ('+'|'-')?[0-9]+('.'[0-9]+)?;
69+
Number: [0-9]+('.'[0-9]+)?;
7070

7171
String: '"' ( '\\"' | ~["\r\n] )*? '"'
7272
| '\'' ( '\\\'' | ~['\r\n] )*? '\'' ;

src/Simpleflow/Parser/Grammar/SimpleflowParser.g4

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ exitStmt
6161
;
6262

6363
expression
64-
: expression (TimesOp | DivOp | ModuloOp) expression #MultiplicativeExpression
64+
: PlusOp expression #UniaryPlusExpression
65+
| MinusOp expression #UniaryMinusExpression
66+
| Not expression #NotExpression
67+
| expression (TimesOp | DivOp | ModuloOp) expression #MultiplicativeExpression
6568
| expression (PlusOp | MinusOp) expression #AdditiveExpression
6669
| expression ( GreaterThan
6770
| LessThan
@@ -71,7 +74,6 @@ expression
7174
| NotEqual
7275
) expression #RelationalExpression
7376
| expression (And | Or ) expression #LogicalExpression
74-
| Not expression #NotExpression
7577
| objectIdentifier #ObjectIdentiferExpression
7678
| simpleLiteral #SimpleLiteralExpression
7779
| arrayLiteral #ArrayLiteralExpression

0 commit comments

Comments
 (0)