Skip to content

Commit

Permalink
type scope (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
vilterp authored Dec 15, 2024
1 parent a7fb313 commit 9bc9a9f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions languageWorkbench/languages/treeDL/example.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
type rawNode
type Node

rule {
raw_node = rawNode()
id = raw_node.id
Expand Down
21 changes: 19 additions & 2 deletions languageWorkbench/languages/treeDL/treeDL.dl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Var

scope.Var{scopeID: I, name: N, span: S, kind: K} :-
var.localVar{scopeID: I, name: N, span: S, kind: K}.
var.localVar{scopeID: I, name: N, span: S, kind: K} |
var.type{scopeID: I, name: N, span: S, kind: K}.
var.localVar{scopeID: Statement, name: N, span: S, kind: "var"} :-
ast.Statement{id: Statement} &
ast.Assign{id: Assign, parentID: Statement} &
Expand All @@ -21,16 +22,31 @@ var.bindAttr{id: Expr, name: N, span: span{from: Start, to: End}} :-
ast.Attr{id: Attr, parentID: Attrs, span: span{to: End}} &
ast.Ident{parentID: Attr, text: N, span: span{from: Start, to: End}}. # TODO: use 'key'

var.type{scopeID: I, name: N, span: S, kind: "type"} :-
var.getType{scopeID: I, name: N, span: S} |
var.bindType{scopeID: I, name: N, span: S}.
var.getType{scopeID: global{}, name: N, span: S} :-
ast.Get{id: Get} &
ast.Ident{parentID: Get, text: N, span: S}.
var.bindType{scopeID: global{}, name: N, span: S} :-
ast.Bind{id: Get} &
ast.Ident{parentID: Get, text: N, span: S}.

# Defn

scope.Defn{scopeID: I, span: S, name: N, kind: K, type: T} :-
defn.localVar{scopeID: I, span: S, name: N, kind: K, type: T}.
defn.localVar{scopeID: I, span: S, name: N, kind: K, type: T} |
defn.type{scopeID: I, span: S, name: N, kind: K, type: T}.

defn.localVar{scopeID: Statement, span: S, name: N, kind: "var", type: "any"} :-
ast.Statement{id: Statement} &
ast.Assign{id: Assign, parentID: Statement} &
ast.Ident{parentID: Assign, span: S, text: N}.

defn.type{scopeID: global{}, span: S, name: N, kind: "type", type: "any"} :-
ast.TypeDecl{id: Decl} &
ast.Ident{parentID: Decl, text: N, span: S}.

# Parent

scope.Parent{parentID: First, childID: Second} :-
Expand All @@ -48,3 +64,4 @@ hl.mapping{rule: "comment", type: "comment"}.
hl.mapping{rule: "addKW", type: "keyword"}.
hl.mapping{rule: "setKW", type: "keyword"}.
hl.mapping{rule: "ruleKW", type: "keyword"}.
hl.mapping{rule: "typeKW", type: "keyword"}.
5 changes: 4 additions & 1 deletion languageWorkbench/languages/treeDL/treeDL.grammar
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
main :- Rule.
Program :- repSep(Rule, ws).
Program :- repSep(Decl, ws).
Decl :- (Rule | TypeDecl).
TypeDecl :- [typeKW, ws, Ident].
Rule :- [ruleKW, ws, "{", ws, Sequence, ws, "}"].
Sequence :- repSep(Statement, ws).
Statement :- (Assign | Filter | Bind | Rule).
Expand All @@ -24,6 +26,7 @@ Bind :- [Ident, ".", addKW, Attrs].
Literal :- (StringLit | NumberLit | BoolLit).

# keywords
typeKW :- "type".
ruleKW :- "rule".
addKW :- "add".
setKW :- "set".
Expand Down

0 comments on commit 9bc9a9f

Please sign in to comment.