boxedsdf-merge.str 1.29 KB
Newer Older
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
module sdf-boxed-merge
imports lib BoxedSdf2 xtc-lib stratego-xt-xtc-tools
signature
  constructors
    Pptable : String -> Option

rules

	readtxtpp : infile -> tree
	where	xtc-temp-files(<xtc-transform(!"sglr",
			!["-2", "-p", <xtc-find> "pp-table.tbl"])> FILE(infile)
	        ; xtc-implode-asfix
		; read-from => tree)

strategies

	pptable-option =
		ArgOption("-p" + "--pptable"
	        , where(<set-config> ("-p",<id>)); !Pptable(<id>)
		, !"-p f|--pptable f Read pptable input from f"
		)

	my-iowrap(s) =
		iowrap(
		  (
		   (option-defined(?Pptable(pp)), id)
		   ; (id, \ i -> (i,<readtxtpp> pp) \)
		     <+ !"bad -p option, try --help."; debug; giving-up)
		   ; (id, s)
		  , pptable-option)

	boxedsdf-merge = my-iowrap(
		?(i, p)
		; !i
		; tag(!p)
	       )

strategies

	at-cons(s) = oncetd(cons(s))

	tagprod(l) = ?p
		; prod(id,id,at-cons(un-double-quote; ?cons))
		; l
		; collect(?PP-Entry(Path1(cons), _)
			<+ ?PP-Entry(Path(cons, _), _))
		; map(\ PP-Entry(Path1(_), x) -> Pathed(None, x) \
		  <+ \ PP-Entry(Path(_, p), x) -> Pathed(Some(Path2(p)), x) \)
		; ?pps
		; !p
		; (prod(id,id, attrs(\ x -> [BoxedAttr(pplist(pps))|x] \))
		  <+ prod(id,id, !attrs(BoxedAttr(pplist(pps)))))

	tag(l) = alltd(
			priorities(id);
			context-free-priorities(id)
			<+
			prod(id,id,id);
			tagprod(l)
		)