boxed2pp-table.str 3.35 KB
Newer Older
1
2
3
4
/*
 * boxed2pp-table.str: this file is a part of BoxedSdf from the Transformers
 *                     project.
 * Copyright (C) 2003, 2004  EPITA Research and Development Laboratory.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
20
21
 */
/**
22
23
24
25
 * This module transforms a BoxedSdf AST into a PP-Table one.
 *
 * Author: Valentin David <valentin@lrde.epita.fr>
 */
26
module boxed2pp-table
27
imports BoxedSdf2 prodcons sdf-2-pp-lib version
28

29
30
strategies

31
32
33
34
        short-description(p) = !["boxed2pp-table generates a pp-table AST ",
	                         "from a BoxedSdf AST.\n\n",
                                 "Usage: ", <p>(), " [options]"]

35
	at-pp(s) = oncetd(BoxedAttr(pplist(s)))
36

37
38
39
	/**
	 * PP-Entry equality.
	 */
40
	ppeq = ?(PP-Entry(Path1(cons), _), PP-Entry(Path1(cons), _))
41
	ppeq = ?(PP-Entry(Path(cons, p), _), PP-Entry(Path(cons, p), _))
42
43

rules
44

45
46
47
	/**
	 * Replace generated PP-Entries by written ones (attributes).
	 */
48
	ReplaceOnePP : (x, []) -> x
49

50
51
	ReplaceOnePP : (x, [y|ys]) -> y
	where	<ppeq> (x, y)
52

53
54
55
	ReplaceOnePP : (x, [y|ys]) -> x'
	where	<not(ppeq)> (x, y)
		; <ReplaceOnePP> (x, ys) => x'
56

57
	ReplacePP : ([],_) -> []
58

59
60
	ReplacePP : ([x|xs], l) -> [x'|xs']
	where	<ReplaceOnePP> (x, l) => x'
61
62
		; <ReplacePP> (xs, l) => xs'

63
	ToPP : p@prod(_,_,_) -> pplist
64
65
66
67
68
69
70
	where   (<prod(id,id,at-cons(un-double-quote; ?cs))> p
		 ; prod(id,id,at-pp(?pl))
		 ; !pl
		 ; map(\ e -> (cs,e) \; ToPPEntry)
		 <+ ![]) => my-pplist
		; <prod(id,id,at-cons(un-double-quote))> p
		; generate-pp-entries
71
		; topdown(try(selector(int-to-string,id)))
72
73
74
		; ?l
		; !(l, my-pplist)
		; ReplacePP => pplist
75

76
77
78
	/**
	 * Convert PP attributes to PP-Entries
	 */
79
80
81
82
83
	ToPPEntry : (cons, Pathed(None, b))
			-> PP-Entry(Path1(cons),b)
	ToPPEntry : (cons, Pathed(Some(Path2(s)), b))
			-> PP-Entry(Path(cons, s), b)

84
85
86
	/**
	 * Explore and transform the AST.
	 */
87
	extexp : Exports(context-free-syntax(l)) -> l'
88
89
90
91
92
93
94
95
96
	where	<map(ToPP <+ ![])> l
		; concat
		; keep(?PP-Entry(_,_)) => l'

	extexp : Exports(conc-grammars(a, b)) -> l
	where	<map(extsyn <+ ![])> [a, b]
		; concat
		; keep(?PP-Entry(_,_)) => l

97
98
99
100
101
        extsyn : conc-grammars(a, b) -> l
        where   <map(extsyn <+ ![])> [a, b]
                ; concat
                ; keep(?PP-Entry(_,_)) => l

102
	extsyn : context-free-syntax(l) -> l'
103
104
105
106
	where	<map(ToPP <+ ![])> l
		; concat
		; keep(?PP-Entry(_,_)) => l'

107
	extmod : Module(_,_,l) -> l'
108
109
110
111
	where	<map(extsyn <+ extexp <+ ![])> l
		; concat
		; keep(?PP-Entry(_,_)) => l'

112
	extdef : Definition(l) -> l'
113
114
115
116
117
	where	<map(extmod)> l
		; concat => l'

strategies

118
119
120
	/**
	 * Keep list element which match s.
	 */
121
122
	keep(s) = rec x([] <+ [s|x] <+ (\ [_|xs] -> xs \; x))

123
124
125
	/**
	 * Main Strategy.
	 */
126
	boxed2pp-table = iowrap(\ _#([x]) -> x \
127
128
				; (extdef + extmod)
				; \ x -> PP-Table(x) \)