Skip to content

Commit

Permalink
improve validation of MathAdd (#25)
Browse files Browse the repository at this point in the history
* fix: update the grammar for the math add intrinsic func args
* fix: support negative numbers as literal values
  • Loading branch information
massfords authored Dec 24, 2024
1 parent b76605a commit c4c1c6c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "asl-path-validator",
"version": "0.15.0",
"version": "0.16.0",
"description": "Validates the path expressions for the Amazon States Language",
"main": "./dist/index.js",
"scripts": {
Expand Down
32 changes: 32 additions & 0 deletions src/__tests__/validatePath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,38 @@ describe("unit tests for the parser", () => {
path: "States.MathAdd($.value1, $.step)",
valid_in: PayloadTemplatesOnly,
},
{
path: "States.MathAdd($.value1, -1)",
valid_in: PayloadTemplatesOnly,
},
{
path: "States.MathAdd($.value1, 1)",
valid_in: PayloadTemplatesOnly,
},
{
path: "States.MathAdd(1, -1)",
valid_in: PayloadTemplatesOnly,
},
{
path: "States.MathAdd(-1, -1)",
valid_in: PayloadTemplatesOnly,
},
{
path: "States.MathAdd(1, $.step)",
valid_in: PayloadTemplatesOnly,
},
{
path: "States.MathAdd(-1, $.step)",
valid_in: PayloadTemplatesOnly,
},
{
path: "States.MathAdd('-1', 'abc')",
valid_in: None,
},
{
path: "States.MathAdd(States.ArrayLength($$.Execution.Input.machines),-1)",
valid_in: PayloadTemplatesOnly,
},
{
path: "States.StringSplit($.inputString, $.splitter)",
valid_in: PayloadTemplatesOnly,
Expand Down
7 changes: 5 additions & 2 deletions src/aslPaths.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ intrinsic_function
/ func:"States.StringToJson" args:single_arg {return {func, args}}
/ func:"States.JsonToString" args:single_arg {return {func, args}}
/ func:"States.MathRandom" args:function_args {return {func, args}}
/ func:"States.MathAdd" args:function_args {return {func, args}}
/ func:"States.MathAdd" PAREN_LEFT _ arg1:jsonpath_ _ COMMA _ arg2:jsonpath_ _ PAREN_RIGHT {return {func, arg1, arg2}}
/ func:"States.MathAdd" PAREN_LEFT _ arg1:jsonpath_ _ COMMA _ arg2:(MINUS? NUMBER) _ PAREN_RIGHT {return {func, arg1, arg2}}
/ func:"States.MathAdd" PAREN_LEFT _ arg1:(MINUS? NUMBER) _ COMMA _ arg2:jsonpath_ _ PAREN_RIGHT {return {func, arg1, arg2}}
/ func:"States.MathAdd" PAREN_LEFT _ arg1:(MINUS? NUMBER) _ COMMA _ arg2:(MINUS? NUMBER) _ PAREN_RIGHT {return {func, arg1, arg2}}
/ func:"States.StringSplit" args:function_args {return {func, args}}
/ func:"States.UUID" args:no_args {return {func, args}}
/ func:"States.Format" args:function_args {return {func, args}}
Expand Down Expand Up @@ -119,7 +122,7 @@ comparison_op

value
= STRING
/ NUMBER
/ minus:MINUS? nbr:NUMBER { return (minus === '-' ? -1 : 1) * parseFloat(nbr)}
/ TRUE
/ FALSE
/ NULL
Expand Down

0 comments on commit c4c1c6c

Please sign in to comment.