~ubuntu-branches/ubuntu/raring/agda/raring-proposed

« back to all changes in this revision

Viewing changes to src/full/Agda/Syntax/Concrete/Name.hs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-01-05 23:43:20 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100105234320-6ksc0sdsfhtweknu
Tags: 2.2.6-1
* New upstream release 2.2.6, for headlines please see:
  http://wiki.portal.chalmers.se/agda/pmwiki.php?n=Main.Version-2-2-6
* debian/control
  + Bump standards-version to 3.8.3, no changes
  + Fix Vcs-Git to point to correct URL
  + Update build-depends for new upstream release
  + Undo arch/indep split per current pkg-haskell practice
  + Add Homepage field
* debian/copyright: Fix encoding to UTF-8 (thanks Lintian) 
* debian/README.source: Remove, no repacking so not necessary any more 
* debian/50agda.el:
  + Only load file if it exists, prevents a non-intrusive emacs warning
    where 50agda.el is left on system when package is removed. 
    (Closes: #559197). 
  + Do not load file on XEmacs — agda-mode is not compatible with XEmacs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
-}
6
6
module Agda.Syntax.Concrete.Name where
7
7
 
 
8
import Control.Applicative
 
9
 
 
10
import Data.List
8
11
import Data.Maybe
9
12
import Data.Generics (Typeable, Data)
10
13
 
 
14
import System.FilePath
 
15
 
 
16
import Test.QuickCheck
 
17
 
11
18
import Agda.Syntax.Common
12
19
import Agda.Syntax.Position
13
20
import Agda.Utils.FileName
14
 
import Agda.Utils.TestHelpers
 
21
import Agda.Utils.Pretty
15
22
 
16
23
#include "../../undefined.h"
17
24
import Agda.Utils.Impossible
115
122
           | QName Name
116
123
  deriving (Typeable, Data, Eq, Ord)
117
124
 
 
125
-- | Top-level module names.
 
126
--
 
127
-- Invariant: The list must not be empty.
 
128
 
 
129
newtype TopLevelModuleName
 
130
  = TopLevelModuleName { moduleNameParts :: [String] }
 
131
  deriving (Show, Eq, Ord, Typeable, Data)
 
132
 
 
133
-- | Turns a qualified name into a 'TopLevelModuleName'. The qualified
 
134
-- name is assumed to represent a top-level module name.
 
135
 
 
136
toTopLevelModuleName :: QName -> TopLevelModuleName
 
137
toTopLevelModuleName = TopLevelModuleName . map show . qnameParts
 
138
 
 
139
-- | Turns a top-level module name into a file name with the given
 
140
-- suffix.
 
141
 
 
142
moduleNameToFileName :: TopLevelModuleName -> String -> FilePath
 
143
moduleNameToFileName (TopLevelModuleName []) ext = __IMPOSSIBLE__
 
144
moduleNameToFileName (TopLevelModuleName ms) ext =
 
145
  joinPath (init ms) </> last ms <.> ext
 
146
 
 
147
-- | Finds the current project's \"root\" directory, given a project
 
148
-- file and the corresponding top-level module name.
 
149
--
 
150
-- Example: If the module \"A.B.C\" is located in the file
 
151
-- \"/foo/A/B/C.agda\", then the root is \"/foo/\".
 
152
--
 
153
-- Precondition: The module name must be well-formed.
 
154
 
 
155
projectRoot :: AbsolutePath -> TopLevelModuleName -> AbsolutePath
 
156
projectRoot file (TopLevelModuleName m) =
 
157
  mkAbsolute $
 
158
  foldr (.) id (replicate (length m - 1) takeDirectory) $
 
159
  takeDirectory $
 
160
  filePath file
 
161
 
118
162
isHole :: NamePart -> Bool
119
163
isHole Hole = True
120
164
isHole _    = False
125
169
isInfix   x =      isHole (head xs)  &&      isHole (last xs)  where xs = nameParts x
126
170
isNonfix  x = not (isHole (head xs)) && not (isHole (last xs)) where xs = nameParts x
127
171
 
128
 
type Suffix = String
129
 
 
130
 
 
131
 
moduleNameToFileName :: QName -> Suffix -> FilePath
132
 
moduleNameToFileName (QName  x) ext = show x ++ ext
133
 
moduleNameToFileName (Qual m x) ext = show m ++ [slash] ++ moduleNameToFileName x ext
134
 
 
135
172
instance Show Name where
136
173
    show (Name _ xs)  = concatMap show xs
137
174
    show (NoName _ _) = "_"
145
181
    show (Qual m x) = show m ++ "." ++ show x
146
182
    show (QName x)  = show x
147
183
 
 
184
instance Pretty TopLevelModuleName where
 
185
  pretty (TopLevelModuleName ms) = text $ intercalate "." ms
 
186
 
 
187
instance Arbitrary TopLevelModuleName where
 
188
  arbitrary = TopLevelModuleName <$> listOf1 (listOf1 $ elements "AB")
 
189
 
 
190
instance CoArbitrary TopLevelModuleName where
 
191
  coarbitrary (TopLevelModuleName m) = coarbitrary m
 
192
 
148
193
instance HasRange Name where
149
194
    getRange (Name r ps)  = r
150
195
    getRange (NoName r _) = r
164
209
instance KillRange Name where
165
210
  killRange (Name r ps)  = Name (killRange r) ps
166
211
  killRange (NoName r i) = NoName (killRange r) i
167