Skip to content

Commit 4b8fc3f

Browse files
committed
fix: handle context accesses following calls
Signed-off-by: William Woodruff <[email protected]>
1 parent e6b1699 commit 4b8fc3f

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

Diff for: src/expr/expr.pest

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ primary_expr = {
4646
| string
4747
| boolean
4848
| null
49-
| index
5049
| function_call
50+
| index
5151
| context
5252
| "(" ~ primary_expr ~ ")"
5353
}
@@ -72,12 +72,12 @@ boolean = { "true" | "false" }
7272
null = { "null" }
7373

7474
/// Context references (e.g., github.event.issue.number)
75-
context = ${ identifier ~ ("." ~ (identifier | star))* }
75+
context = ${ identifier ~ (("." ~ (identifier | star)) | index)* }
7676
star = { "*" }
7777
identifier = @{ (ASCII_ALPHA | "_" | "-") ~ (ASCII_ALPHANUMERIC | "_" | "-")* }
7878

7979
/// Function calls
80-
function_call = { identifier ~ "(" ~ (or_expr ~ ("," ~ or_expr)*)? ~ ")" }
80+
function_call = { identifier ~ "(" ~ (or_expr ~ ("," ~ or_expr)*)? ~ ")" ~ (index | ("." ~ context))? }
8181

8282
/// Index operations
83-
index = { (context | function_call | ("(" ~ primary_expr ~ ")")) ~ ("[" ~ (or_expr | star) ~ "]")+ }
83+
index = { ("[" ~ (or_expr | star) ~ "]")+ }

Diff for: src/expr/mod.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ mod tests {
365365
"(true == false) == true",
366366
"(true == (false || true && (true || false))) == true",
367367
"(github.actor != 'github-actions[bot]' && github.actor) == 'BrewTestBot'",
368+
"fromJson(steps.runs.outputs.data).workflow_runs[0].id",
368369
];
369370

370371
for case in cases {
@@ -413,17 +414,19 @@ mod tests {
413414
("foo.bar.baz", Expr::Context("foo.bar.baz".into())),
414415
(
415416
"foo.bar.baz[1][2]",
416-
Expr::Index {
417-
parent: Expr::Context("foo.bar.baz".into()).into(),
418-
indices: vec![Expr::Number(1.0), Expr::Number(2.0)],
419-
},
417+
Expr::Context("foo.bar.baz[1][2]".into()),
418+
// Expr::Index {
419+
// parent: Expr::Context("foo.bar.baz".into()).into(),
420+
// indices: vec![Expr::Number(1.0), Expr::Number(2.0)],
421+
// },
420422
),
421423
(
422424
"foo.bar.baz[*]",
423-
Expr::Index {
424-
parent: Expr::Context("foo.bar.baz".into()).into(),
425-
indices: vec![Expr::Star],
426-
},
425+
Expr::Context("foo.bar.baz[*]".into()),
426+
// Expr::Index {
427+
// parent: Expr::Context("foo.bar.baz".into()).into(),
428+
// indices: vec![Expr::Star],
429+
// },
427430
),
428431
(
429432
"vegetables.*.ediblePortions",
@@ -473,7 +476,18 @@ mod tests {
473476
op: BinOp::Or, rhs: Expr::Boolean(false).into()
474477
}.into()
475478
}
476-
)
479+
),
480+
(
481+
// BUG: AST is incorrect here
482+
"fromJson(steps.runs.outputs.data).workflow_runs[0].id",
483+
Expr::Call {
484+
func: "fromJson".into(),
485+
args: vec![
486+
Expr::Context("steps.runs.outputs.data".into()).into(),
487+
Expr::Context("workflow_runs[0].id".into()).into(),
488+
]
489+
}
490+
),
477491
];
478492

479493
for (case, expr) in cases {

0 commit comments

Comments
 (0)