Skip to content

Commit

Permalink
treedl: member access chain (#511)
Browse files Browse the repository at this point in the history
* add test for member access chain

* fix member access chain

* add to example

* bump version
  • Loading branch information
vilterp authored Dec 30, 2024
1 parent 00897d4 commit ece0b0a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/vscodeExtension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "lingo",
"displayName": "Lingo",
"publisher": "lingo",
"version": "0.2.11",
"version": "0.2.12",
"repository": {
"type": "git",
"url": "https://github.com/vilterp/datalog-ts"
Expand Down
1 change: 1 addition & 0 deletions languageWorkbench/languages/treeDL/example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ rule {
edge = Edge()
edge == id
node = Node.add(id=id)
x = node.next.next.id
}
8 changes: 8 additions & 0 deletions languageWorkbench/languages/treeDL/treeDL.dd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@ rule {
edge = Edge()
edge == id
node = Node.add(id=id)
x = node.next.next.id
}
scope.Usage{}?
----
application/datalog
scope.Usage{definitionScopeID: "Node", defnSpan: span{from: 173, to: 175}, kind: "attr", name: "id", usageScopeID: "Node", usageSpan: span{from: 201, to: 203}}.
scope.Usage{definitionScopeID: "Node", defnSpan: span{from: 41, to: 45}, kind: "attr", name: "next", usageScopeID: "Node", usageSpan: span{from: 191, to: 195}}.
scope.Usage{definitionScopeID: "Node", defnSpan: span{from: 41, to: 45}, kind: "attr", name: "next", usageScopeID: "Node", usageSpan: span{from: 196, to: 200}}.
scope.Usage{definitionScopeID: "Node", defnSpan: span{from: 67, to: 69}, kind: "attr", name: "id", usageScopeID: "Node", usageSpan: span{from: 201, to: 203}}.
scope.Usage{definitionScopeID: "rawNode", defnSpan: span{from: 17, to: 19}, kind: "attr", name: "id", usageScopeID: "rawNode", usageSpan: span{from: 123, to: 125}}.
scope.Usage{definitionScopeID: 135, defnSpan: span{from: 86, to: 94}, kind: "var", name: "raw_node", usageScopeID: 174, usageSpan: span{from: 114, to: 122}}.
scope.Usage{definitionScopeID: 174, defnSpan: span{from: 109, to: 111}, kind: "var", name: "id", usageScopeID: 231, usageSpan: span{from: 152, to: 154}}.
scope.Usage{definitionScopeID: 174, defnSpan: span{from: 109, to: 111}, kind: "var", name: "id", usageScopeID: 250, usageSpan: span{from: 176, to: 178}}.
scope.Usage{definitionScopeID: 206, defnSpan: span{from: 128, to: 132}, kind: "var", name: "edge", usageScopeID: 231, usageSpan: span{from: 144, to: 148}}.
scope.Usage{definitionScopeID: 250, defnSpan: span{from: 157, to: 161}, kind: "var", name: "node", usageScopeID: 285, usageSpan: span{from: 186, to: 190}}.
scope.Usage{definitionScopeID: global{}, defnSpan: span{from: 32, to: 36}, kind: "type", name: "Node", usageScopeID: global{}, usageSpan: span{from: 164, to: 168}}.
scope.Usage{definitionScopeID: global{}, defnSpan: span{from: 5, to: 12}, kind: "type", name: "rawNode", usageScopeID: global{}, usageSpan: span{from: 97, to: 104}}.

Expand All @@ -40,6 +46,7 @@ rule {
edge = Edge()
edge == id
node = Node.add(id=id)
x = node.next.next.id
}
tc.Type{}?
----
Expand All @@ -48,3 +55,4 @@ tc.Type{scope: 135, type: "rawNode", var: "raw_node"}.
tc.Type{scope: 174, type: "int", var: "id"}.
tc.Type{scope: 206, type: "Edge", var: "edge"}.
tc.Type{scope: 250, type: "Node", var: "node"}.
tc.Type{scope: 285, type: "int", var: "x"}.
7 changes: 5 additions & 2 deletions languageWorkbench/languages/treeDL/treeDL.dl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ tc.type.bind{scope: Statement, var: N, type: T} :-
ast.Bind{id: Bind, parentID: Expr} &
ast.Ident{parentID: Bind, text: T}.
tc.type.memberAccess{scope: Statement, var: N, type: T} :-
tc.type.memberAccess.step{scope: Statement, var: N, type: T, node: Ident} &
tc.type.memberAccess.node{scope: Statement, var: N, type: T, node: Ident} &
astInternal.lastChild{id: Ident}.
tc.type.memberAccess.base{scope: Statement, var: N, type: T, node: Ident} :-
util.AssignExpr{assign: Statement, var: N, expr: Expr} &
Expand All @@ -95,8 +95,11 @@ tc.type.memberAccess.base{scope: Statement, var: N, type: T, node: Ident} :-
ast.Ident{id: Ident, text: Var} &
astInternal.next{prev: ParentScope, next: Statement} &
scope.Item{scopeID: ParentScope, name: Var, type: T}.
tc.type.memberAccess.node{scope: Statement, var: N, type: T, node: Ident} :-
tc.type.memberAccess.base{scope: Statement, var: N, type: T, node: Ident} |
tc.type.memberAccess.step{scope: Statement, var: N, type: T, node: Ident}.
tc.type.memberAccess.step{scope: Statement, var: N, prevType: PrevT, type: T, node: Ident} :-
tc.type.memberAccess.base{scope: Statement, var: N, type: PrevT, node: Prev} &
tc.type.memberAccess.node{scope: Statement, var: N, type: PrevT, node: Prev} &
astInternal.next{prev: Prev, next: Ident} &
ast.Ident{id: Ident, text: Attr} &
tc.typeAttr{struct: PrevT, attr: Attr, type: T}.
Expand Down

0 comments on commit ece0b0a

Please sign in to comment.