boxedsdf-update.str 3.54 KB
Newer Older
1
2
3
4
/*
 * boxedsdf-update.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
26
27
28
29
30
31
32
 * Sdf update checker
 *
 * When rewriting a grammar, sometimes, some pp informations are forgotten.
 * It compares the old grammar with the new one and delete (and prevent with
 * verbose level more than 1) all the pp entries that are not updated.
 * When a pp entry is deleted, the default one will be generated by
 * boxed2pp-table tool.
 *
 * Author: Valentin David <valentin@lrde.epita.fr>
 */
module boxedsdf-update
33
imports BoxedSdf2 xtc-lib version
34
35
36
37
38
39
40
41
42
43
44
45
46
47

signature
  constructors
	Old : String -> Option

rules

	readgrammar : infile -> tree
	where	xtc-temp-files(<xtc-transform(!"sglri", !["-p", <get-syntax>])>
			FILE(infile)
		; read-from => tree)

strategies

48
49
50
51
        short-description(p) = !["boxedsdf-update helps to check ",
	                         "modifications on a grammar.\n\n",
                                 "Usage: ", <p>(), " [options]"]

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
	get-syntax = (<get-config> "-s" <+ !"BoxedSdf2")
		; if-verbose2(debug(!"Using grammar: "))
		; !(<id>, ".tbl")
		; conc-strings
		; (<find-in-path> (<id>, <get-config> "-I") <+ xtc-find)
		; if-verbose6(debug(!"Using grammar table: "))

        /**
         * -d/--old grammar
         * to specify the old grammar
         */
        old-option =
                ArgOption("-d" + "--old"
                , where(<set-config> ("-d",<id>)); !Old(<id>)
                , !"-d n|--old n     Generated module will import n"
                )

	/**
	 * -s/--syntax syntax
	 * to specify the syntax of the old grammar
	 */
	syntax-option =
		ArgOption("-s" + "--syntax"
		  , where(<set-config> ("-s", <id>))
		  , !"-s g|--syntax g  Use g syntax for old grammar, default BoxedSdf2"
		)

	at-cons(s) = oncetd(cons(s))
	at-pp(s) = oncetd(BoxedAttr(pplist(s)))

	eq-prod = ?(prod(a, b, _), prod(a, b, _))

	eq-pp = (prod(id,id,at-pp(?pp)), prod(id,id, at-pp(?pp)))

	reset-old-pp = alltd(lexical-syntax(id)
		  <+ context-free-priorities(id)
		  <+ lexical-priorities(id)
		  <+ priorities(id)
		  <+ { c, p :
		       prod(id,id,at-cons(?c))
		       ; ?p
		       ; <not(eq-prod)> (<id>, <GetOldProd> c)
		       ; eq-pp
		       ; where(<if-verbose1(debug(!"Production has changed, but not the pp. Reseting it: "))> c)
		       ; <prod(id,id,attrs(filter(not(BoxedAttr(id))))
				     ; try(attrs([])
				       ; !no-attrs))> p
		     })

	boxedsdf-update = iowrap(
		  (option-defined(?Old(grammar))
		  ; where (
		    <readgrammar> grammar
		    ; alltd(lexical-syntax(id)
			<+ context-free-priorities(id)
			<+ lexical-priorities(id)
			<+ priorities(id)
			<+ { c, p:
			     prod(id,id,at-cons(?c))
			     ; ?p
			     ; rules(GetOldProd : c -> p)
			   })
		    ), id)
		  ; (id, reset-old-pp)
                , old-option + syntax-option)