~ubuntu-branches/ubuntu/trusty/happy/trusty-proposed

« back to all changes in this revision

Viewing changes to happy/src/Info.lhs

  • Committer: Bazaar Package Importer
  • Author(s): Ian Lynagh (wibble)
  • Date: 2006-10-26 22:52:14 UTC
  • mfrom: (1.2.2 upstream) (3.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20061026225214-6jmf0n3ykkc9elyw
Tags: 1.16~rc2-1
* New upstream (release candidate) version.
* Removed happy/ prefixes from various paths in debian/rules and
  debian/docs.
* doc/configure generated by autoconf is in the Debian diff.
* Build using cabal:
  * Various debian/rules changes.
  * Create debian/get_version.hs for extracting the version from the cabal
    file.
  * Requires ghc6 >= 6.4.2.
  * No longer tries to detect platform. Closes: #340325, #332979.
  * Removed autotool-dev build-dep.
* Add 'XSLTPROC_OPTS = --nonet' to doc/config.mk.in.
* Remove src/Parser.ly and src/AttrGrammarParser.ly before cleaning so
  the generated files don't get cleaned.
* Set Standards-Version to 3.7.2 (no changes needed).
* Removed PS and DVI stanzas from debian/doc-base as we don't build
  the documentation those ways.
* Removed content-free postinst and prerm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
-----------------------------------------------------------------------------
2
 
$Id$
3
 
 
4
 
Generating info files.
5
 
 
6
 
(c) 1993-2001 Andy Gill, Simon Marlow
7
 
-----------------------------------------------------------------------------
8
 
 
9
 
> module Info (genInfoFile) where
10
 
 
11
 
> import Version                ( version )
12
 
> import LALR                   ( Lr0Item )
13
 
> import GenUtils               ( str, interleave, interleave', ljustify )
14
 
> import Set
15
 
> import Grammar
16
 
 
17
 
> import Array
18
 
> import List (nub)
19
 
 
20
 
Produce a file of parser information, useful for debugging the parser.
21
 
 
22
 
> genInfoFile
23
 
>       :: [Set Lr0Item]
24
 
>       -> Grammar
25
 
>       -> ActionTable
26
 
>       -> GotoTable
27
 
>       -> [(Int,String)]
28
 
>       -> Array Int (Int,Int)
29
 
>       -> String
30
 
>       -> [Int]                        -- unused rules
31
 
>       -> [String]                     -- unused terminals
32
 
>       -> String
33
 
 
34
 
> genInfoFile items 
35
 
>       (Grammar { productions = prods
36
 
>                , lookupProdNo = lookupProd
37
 
>                , lookupProdsOfName = lookupProdNos
38
 
>                , non_terminals = nonterms
39
 
>                , terminals = terms
40
 
>                , token_names = env
41
 
>                , eof_term = eof
42
 
>                , first_term = fst_term
43
 
>                })
44
 
>        action goto tokens conflictArray filename unused_rules unused_terminals
45
 
>       = (showHeader
46
 
>       . showConflicts
47
 
>       . showUnused
48
 
>       . showProductions 
49
 
>       . showTerminals 
50
 
>       . showNonTerminals 
51
 
>       . showStates
52
 
>       . showStats
53
 
>       ) ""
54
 
>   where
55
 
 
56
 
>   showHeader 
57
 
>       = banner ("Info file generated by Happy Version " ++ 
58
 
>                 version ++ " from " ++ filename)
59
 
 
60
 
>   showConflicts
61
 
>       = str "\n"
62
 
>       . foldr (.) id (map showConflictsState (assocs conflictArray))
63
 
>       . str "\n"
64
 
 
65
 
>   showConflictsState (state, (0,0)) = id
66
 
>   showConflictsState (state, (sr,rr))
67
 
>       = str "state "
68
 
>       . shows state
69
 
>       . str " contains "
70
 
>       . interleave' " and " (
71
 
>               (if sr /= 0 
72
 
>                       then [ shows sr . str " shift/reduce conflicts" ]
73
 
>                       else []) ++
74
 
>                if rr /= 0
75
 
>                       then [ shows rr . str " reduce/reduce conflicts" ]
76
 
>                       else [])
77
 
>       . str ".\n"
78
 
 
79
 
>   showUnused =
80
 
>         (case unused_rules of
81
 
>           [] -> id
82
 
>           _  ->   interleave "\n" (
83
 
>                       map (\r ->   str "rule " 
84
 
>                                  . shows r 
85
 
>                                  . str " is unused")
86
 
>                               unused_rules)
87
 
>                 . str "\n")
88
 
>       . (case unused_terminals of
89
 
>           [] -> id
90
 
>           _  ->   interleave "\n" (
91
 
>                       map (\t ->   str "terminal " 
92
 
>                                  . str t 
93
 
>                                  . str " is unused")
94
 
>                               unused_terminals)
95
 
>                 . str "\n")
96
 
 
97
 
>   showProductions = 
98
 
>         banner "Grammar"
99
 
>       . interleave "\n" (zipWith showProduction prods [ 0 :: Int .. ])
100
 
>       . str "\n"
101
 
  
102
 
>   showProduction (nt, toks, sem, prec) i
103
 
>       = ljuststr 50 (
104
 
>         str "\t"
105
 
>       . showName nt
106
 
>       . str " -> "
107
 
>       . interleave " " (map showName toks))
108
 
>       . str "  (" . shows i . str ")"
109
 
 
110
 
>   showStates =
111
 
>         banner "States"
112
 
>       . interleave "\n" (zipWith showState 
113
 
>               (map setToList items) [ 0 :: Int .. ])
114
 
 
115
 
>   showState state n
116
 
>       = str "State ". shows n
117
 
>       . str "\n\n"
118
 
>       . interleave "\n" (map showItem [ (r,d) | (r,d) <- state, d /= 0 ])
119
 
>       . str "\n"
120
 
>       . foldr (.) id (map showAction (assocs (action ! n)))
121
 
>       . str "\n"
122
 
>       . foldr (.) id (map showGoto (assocs (goto ! n)))
123
 
 
124
 
>   showItem (rule,dot)
125
 
>       = ljuststr 50 (
126
 
>                 str "\t"
127
 
>               . showName nt
128
 
>               . str " -> "
129
 
>               . interleave " " (map showName beforeDot)
130
 
>               . str ". "
131
 
>               . interleave " " (map showName afterDot))
132
 
>       . str "   (rule " . shows rule . str ")"
133
 
>       where
134
 
>               (nt, toks, sem, prec) = lookupProd rule
135
 
>               (beforeDot, afterDot) = splitAt dot toks
136
 
 
137
 
>   showAction (t, LR'Fail)
138
 
>       = id
139
 
>   showAction (t, act)
140
 
>       = str "\t"
141
 
>       . showJName 15 t
142
 
>       . showAction' act
143
 
>       . str "\n"
144
 
 
145
 
>   showAction' LR'MustFail
146
 
>       = str "fail"
147
 
>   showAction' (LR'Shift n _)
148
 
>       = str "shift, and enter state "
149
 
>       . shows n
150
 
>   showAction' LR'Accept
151
 
>       = str "accept"
152
 
>   showAction' (LR'Reduce n _)
153
 
>       = str "reduce using rule "
154
 
>       . shows n
155
 
>   showAction' (LR'Multiple as a)
156
 
>       = showAction' a
157
 
>       . str "\n"
158
 
>       . interleave "\n" 
159
 
>               (map (\a -> str "\t\t\t(" . showAction' a . str ")") 
160
 
>                (nub (filter (/= a) as)))
161
 
 
162
 
>   showGoto (nt, NoGoto)
163
 
>       = id
164
 
>   showGoto (nt, Goto n)
165
 
>       = str "\t"
166
 
>       . showJName 15 nt
167
 
>       . str "goto state "
168
 
>       . shows n
169
 
>       . str "\n"
170
 
 
171
 
>   showTerminals
172
 
>       = banner "Terminals"
173
 
>       . interleave "\n" (map showTerminal tokens)
174
 
>       . str "\n"
175
 
 
176
 
>   showTerminal (t,s)
177
 
>       = str "\t"
178
 
>       . showJName 15 t
179
 
>       . str "{ " . str s . str " }"
180
 
 
181
 
>   showNonTerminals
182
 
>       = banner "Non-terminals"
183
 
>       . interleave "\n" (map showNonTerminal nonterms)
184
 
>       . str "\n"
185
 
 
186
 
>   showNonTerminal nt
187
 
>       = str "\t"
188
 
>       . showJName 15 nt
189
 
>       . (if (length nt_rules == 1)
190
 
>               then str " rule  "
191
 
>               else str " rules ")
192
 
>       . foldr1 (\a b -> a . str ", " . b) nt_rules
193
 
>       where nt_rules = map shows (lookupProdNos nt)
194
 
 
195
 
>   showStats 
196
 
>       = banner "Grammar Totals"
197
 
>       . str   "Number of rules: " . shows (length prods)
198
 
>       . str "\nNumber of terminals: " . shows (length tokens)
199
 
>       . str "\nNumber of non-terminals: " . shows (length nonterms)
200
 
>       . str "\nNumber of states: " . shows (length items)
201
 
>       . str "\n"
202
 
 
203
 
>   nameOf n    = env ! n
204
 
>   showName    = str . nameOf
205
 
>   showJName j = str . ljustify j . nameOf
206
 
 
207
 
> ljuststr n s = str (ljustify n (s ""))
208
 
 
209
 
> banner s 
210
 
>       = str "-----------------------------------------------------------------------------\n"
211
 
>       . str s
212
 
>       . str "\n-----------------------------------------------------------------------------\n"
213