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

« back to all changes in this revision

Viewing changes to src/full/Agda/Syntax/Parser/Monad.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:
28
28
    )
29
29
    where
30
30
 
 
31
import Control.Exception
31
32
import Data.Char
32
33
import Data.Typeable
33
34
 
35
36
import Control.Monad.Error
36
37
import Control.Applicative
37
38
 
38
 
import qualified Agda.Utils.IO as UTF8
39
 
 
40
39
import Agda.Syntax.Position
41
40
 
 
41
import Agda.Utils.FileName
 
42
import qualified Agda.Utils.IO.UTF8 as UTF8
42
43
import Agda.Utils.Monad
43
44
 
44
45
{--------------------------------------------------------------------------
95
96
                    }
96
97
    deriving (Typeable)
97
98
 
 
99
instance Exception ParseError
 
100
 
98
101
-- | The result of parsing something.
99
102
data ParseResult a  = ParseOk ParseState a
100
103
                    | ParseFailed ParseError
173
176
-- | Constructs the initial state of the parser. The string argument
174
177
--   is the input string, the file path is only there because it's part
175
178
--   of a position.
176
 
initState :: FilePath -> ParseFlags -> String -> [LexState] -> ParseState
 
179
initState :: Maybe AbsolutePath -> ParseFlags -> String -> [LexState]
 
180
          -> ParseState
177
181
initState file = initStatePos (startPos file)
178
182
 
179
183
-- | The default flags.
184
188
--   more specialised functions that supply the 'ParseFlags' and the
185
189
--   'LexState'.
186
190
parse :: ParseFlags -> [LexState] -> Parser a -> String -> ParseResult a
187
 
parse flags st p input = unP p (initState "" flags input st)
 
191
parse flags st p input = unP p (initState Nothing flags input st)
188
192
 
189
193
-- | The even more general way of parsing a string.
190
194
parsePosString :: Position -> ParseFlags -> [LexState] -> Parser a -> String ->
194
198
-- | The most general way of parsing a file. The "Agda.Syntax.Parser" will define
195
199
--   more specialised functions that supply the 'ParseFlags' and the
196
200
--   'LexState'.
197
 
parseFile :: ParseFlags -> [LexState] -> Parser a -> FilePath -> IO (ParseResult a)
 
201
--
 
202
--   Note that Agda source files always use the UTF-8 character
 
203
--   encoding.
 
204
parseFile :: ParseFlags -> [LexState] -> Parser a -> AbsolutePath
 
205
          -> IO (ParseResult a)
198
206
parseFile flags st p file =
199
 
    do  input <- liftIO $ UTF8.readTextFile file
200
 
        return $ unP p (initState file flags input st)
 
207
    do  input <- liftIO $ UTF8.readTextFile $ filePath file
 
208
        return $ unP p (initState (Just file) flags input st)
201
209
 
202
210
{--------------------------------------------------------------------------
203
211
    Manipulating the state