Skip to content

Commit b96ff23

Browse files
jurgenvinjuDavyLandman
authored andcommitted
added default keyword parameters to ICollector to help write correct and safe scope and stack pushes and pops. shorthands for manual enter/leave, push/pop pairs
1 parent 6aa79dd commit b96ff23

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/analysis/typepal/ICollector.rsc

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,51 @@ data Collector
7777
void (value l, value r, FailMessage fm) requireEqual,
7878
void (value l, value r, FailMessage fm) requireComparable,
7979
void (value l, value r, FailMessage fm) requireSubType,
80-
void (value l, value r, FailMessage fm) requireUnify
80+
void (value l, value r, FailMessage fm) requireUnify,
81+
82+
/* blocked short-hands for scope stack and info stack management (default kwparams) */
83+
84+
/* enter/leave */ void (Tree id, void () block) scope = (Tree id, void() block) {
85+
enterScope(id);
86+
try
87+
block();
88+
catch 22: ;
89+
finally
90+
leaveScope(id);
91+
},
92+
/* lub ent/leave */ void (Tree id, void () block) lubScope = (Tree id, void() block) {
93+
enterLubScope(id);
94+
try
95+
block();
96+
catch 22: ;
97+
finally
98+
leaveScope(id);
99+
},
100+
/* comp lub */ void (list[Tree] ids, void () block) compositeLubScope = (list[Tree] ids, void () block) {
101+
enterCompositeLubScope(ids);
102+
try
103+
block();
104+
catch 22: ;
105+
finally
106+
leaveCompositeScope(ids);
107+
},
108+
/* comp ent/leave*/ void (list[Tree] ids, void () block) compositeScope = (list[Tree] ids, void () block) {
109+
enterCompositeScope(ids);
110+
try
111+
block();
112+
catch 22: ;
113+
finally
114+
leaveCompositeScope(ids);
115+
116+
},
117+
/* push/pop info*/ void (str key, value val, void () block) nestInfo = (str key, value val, void () block) {
118+
push(key, val);
119+
try {
120+
block();
121+
}
122+
catch 22: ;
123+
finally {
124+
pop(key);
125+
}
126+
}
81127
);

0 commit comments

Comments
 (0)