Skip to content

Commit

Permalink
Merge pull request #91 from fink-lang/ast-traverse-member-kv
Browse files Browse the repository at this point in the history
AST traverse member kv
  • Loading branch information
kollhof authored Dec 2, 2020
2 parents 973f720 + d525414 commit 956500c
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 162 deletions.
190 changes: 40 additions & 150 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/ast/analyze.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ is_binding_ident = fn expr, ctx:
false


has_kv_parent = fn expr, ctx:
parent = get_parent expr, ctx
match parent:
{type: 'rec:kv', left: expr}:
true
{type: 'member'}:
has_kv_parent parent, ctx
else:
false



is_referencing = fn expr, ctx:
match expr:
Expand All @@ -128,6 +139,7 @@ is_referencing = fn expr, ctx:
{type: 'rec:kv', left: expr, right: false}: true
{type: 'rec:kv', left: expr}: false
{type: 'member', right: expr}: false
{type: 'member', left: expr}: not has_kv_parent parent, ctx
{type: 'jsx:attr', name: expr, value: ? != false}: false
else: true

Expand Down
6 changes: 3 additions & 3 deletions src/ast/analyze.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ source = '
ni + undef

{ni, na: {nu}} = {foo}
{(ni): nini=nu} = {foo: bar, (ni): nu}
{(ni): nini=nu, foo.bar: spam} = {foo: bar, (ni): nu, foo.bar.spam: 134}

match bar foo:
nu:
Expand All @@ -80,8 +80,8 @@ source = '
try:
foo

[ni] = [1234, "spam"]
na = [...ni]
[ni, ..., nu] = [1234, "spam"]
na = [...ni, false, true]
fn foo: {foo}

map await ham:
Expand Down
11 changes: 8 additions & 3 deletions src/ast/analyze.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ Array [
"ident:ni@7:1-7:3",
"ident:nu@7:10-7:12",
"ident:nini@8:7-8:11",
"ident:spam@8:25-8:29",
"ident:ni@12:4-12:6",
"ident:Spam@18:0-18:4",
"ident:children@18:11-18:19",
"ident:ni@27:1-27:3",
"ident:nu@27:10-27:12",
"ident:na@28:0-28:2",
"ident:foo@29:3-29:6",
"ident:ham@31:10-31:13",
Expand All @@ -23,6 +25,7 @@ Array [
exports[`analyze gets duplicate bindings 1`] = `
Array [
"ident:ni@27:1-27:3 module@1:0-33:0",
"ident:nu@27:10-27:12 module@1:0-33:0",
]
`;

Expand All @@ -33,7 +36,7 @@ Array [
"ident:foo@10:10-10:13 -> ident:foo@1:0-1:3",
"ident:foo@12:9-12:12 -> ident:foo@1:0-1:3",
"ident:foo@25:2-25:5 -> ident:foo@1:0-1:3",
"ident:bar@8:24-8:27 -> ident:bar@3:0-3:3",
"ident:bar@8:39-8:42 -> ident:bar@3:0-3:3",
"ident:bar@10:6-10:9 -> ident:bar@3:0-3:3",
"ident:spam@4:7-4:11 -> ident:spam@3:9-3:13",
"ident:ham@4:20-4:23 -> ident:ham@3:19-3:22",
Expand All @@ -42,10 +45,10 @@ Array [
"ident:div@16:1-16:4 -> unbound",
"ident:ham@21:24-21:27 -> unbound",
"ident:ni@8:2-8:4 -> ident:ni@7:1-7:3",
"ident:ni@8:30-8:32 -> ident:ni@7:1-7:3",
"ident:ni@8:45-8:47 -> ident:ni@7:1-7:3",
"ident:ni@21:6-21:8 -> ident:ni@7:1-7:3",
"ident:nu@8:12-8:14 -> ident:nu@7:10-7:12",
"ident:nu@8:35-8:37 -> ident:nu@7:10-7:12",
"ident:nu@8:50-8:52 -> ident:nu@7:10-7:12",
"ident:nu@11:2-11:4 -> ident:nu@7:10-7:12",
"ident:nu@21:15-21:17 -> ident:nu@7:10-7:12",
"ident:ni@13:8-13:10 -> ident:ni@12:4-12:6",
Expand All @@ -67,10 +70,12 @@ Array [
"ident:ni@7:1-7:3 module@1:0-33:0",
"ident:nu@7:10-7:12 module@1:0-33:0",
"ident:nini@8:7-8:11 module@1:0-33:0",
"ident:spam@8:25-8:29 module@1:0-33:0",
"ident:ni@12:4-12:6 match:expr@11:2-13:11",
"ident:Spam@18:0-18:4 module@1:0-33:0",
"ident:children@18:11-18:19 block:fn@18:7-19:17",
"ident:ni@27:1-27:3 module@1:0-33:0",
"ident:nu@27:10-27:12 module@1:0-33:0",
"ident:na@28:0-28:2 module@1:0-33:0",
"ident:foo@29:3-29:6 block:fn@29:0-29:13",
"ident:ham@31:10-31:13 block:map@31:0-33:0",
Expand Down
5 changes: 4 additions & 1 deletion src/ast/traverse.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ get_child_exprs = fn expr:
{type: 'rec:kv', right: false}:
[expr.left]

{type: 'spread', right: false}:
[]

{left: {}, right: {}}:
[expr.left, expr.right]

# spread
# spread, await
{right: {}}:
[expr.right]

Expand Down
Loading

0 comments on commit 956500c

Please sign in to comment.