-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathDisjunction.rsc
More file actions
64 lines (59 loc) · 1.83 KB
/
Disjunction.rsc
File metadata and controls
64 lines (59 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI}
@wiki{addH,horizontal,removeH,vertical}
module transform::library::Disjunction
//import lib::Rascalware;
import language::BGF;
import language::XScope;
import language::XOutcome;
import transform::library::Util;
XBGFResult runAddH(BGFProduction p1, BGFGrammar g)
{
p2 = unmark(p1);
p3 = demarkH(p1);
if (!inProds(p3,g.prods))
return <notFoundP(p3),g>;
return <ok(),grammar(g.roots, replaceP(g.prods,p3,p2))>;
}
XBGFResult runHorizontal(XBGFScope w, BGFGrammar g)
{
// For xbgf1.pro, the context must be strictly vertical. Here we are more relaxed.
<ps1,ps2,ps3> = splitPbyW(g.prods,w);
list[BGFExpression] es4 = [];
for (production(str l, str x, BGFExpression e) <- ps2)
if (choice(L) := e)
es4 += L;
elseif (l == "")
es4 += e;
else
es4 += selectable(l,e);
if (innt(str x) := w)
return <ok(),grammar(g.roots,ps1 + production("",x,choice(es4)) + ps3)>;
else
return <problemScope("Scope for horizontal must be a nonterminal",w),g>;
}
XBGFResult runRemoveH(BGFProduction p1, BGFGrammar g)
{
p2 = unmark(p1);
if (!inProds(p2, g.prods))
return <notFoundP(p2),g>;
return <ok(),grammar(g.roots, replaceP(g.prods,p2,demarkH(p1)))>;
}
XBGFResult runVertical(XBGFScope w, BGFGrammar g)
{
<ps1,ps2,ps3> = splitPbyW(g.prods, w);
ps4 = [];
for (production(str l, str x, BGFExpression e) <- ps2)
if (choice(L) := e)
for (se <- L)
if (selectable(str s, BGFExpression e2) := se)
if (/production(s,_,_) := g.prods)
return <problemStr("Outermost selector clashes with an existing label",s),g>;
elseif (/production(s,_,_) := ps4)
return <problemStr("Outermost selectors ambiguous",s),g>;
else
ps4 += production(s,x,e2);
else
ps4 += production("",x,se);
else ps4 += production(l,x,e);
return <ok(),grammar(g.roots, ps1 + ps4 + ps3)>;
}