uu-cco-hut-parsing (empty) → 0.1.0.0
raw patch · 5 files changed
+117/−0 lines, 5 filesdep +basedep +uu-ccodep +uulibsetup-changed
Dependencies added: base, uu-cco, uulib
Files
- AUTHORS +2/−0
- LICENSE +1/−0
- Setup.lhs +4/−0
- src/CCO/Parsing/UU.hs +82/−0
- uu-cco-hut-parsing.cabal +28/−0
+ AUTHORS view
@@ -0,0 +1,2 @@+Stefan Holdermans <stefan@holdermans.nl> (Original author)+Atze Dijkstra <atze@uu.nl> (Maintainer)
+ LICENSE view
@@ -0,0 +1,1 @@+Copyright (c) 2008-2014 Utrecht University. All rights reserved.
+ Setup.lhs view
@@ -0,0 +1,4 @@+#! /usr/bin/env runhaskell++> import Distribution.Simple+> main = defaultMain
+ src/CCO/Parsing/UU.hs view
@@ -0,0 +1,82 @@+-------------------------------------------------------------------------------+-- |+-- Module : CCO.Parsing.UU+-- Copyright : (c) 2008 Utrecht University+-- License : All rights reserved+--+-- Maintainer : stefan@cs.uu.nl+-- Stability : provisional+-- Portability : portable+--+-- Utility for executing 'Parser's from the Haskell Utrecht Tools Library+-- within the 'Feedback' monad.+--+-- This module can be regarded a satellite to the utility library accompanying+-- the course on Compiler Construction (INFOMCCO) at Utrecht University.+--+-------------------------------------------------------------------------------++module CCO.Parsing.UU (+ -- * Executing parsers within the Feedback monad+ parseFeedback -- :: (Eq s, Show s, Symbol s) =>+ -- Parser s a -> [s] -> Feedback a+) where++import CCO.Feedback (Feedback, errorMessage)+import CCO.Printing (Doc, text, wrapped, (>|<), above)+import UU.Parsing++-------------------------------------------------------------------------------+-- Executing parsers within the Feedback monad+-------------------------------------------------------------------------------++-- | Executes a 'Parser' within the 'Feedback' monad.+parseFeedback :: (Eq s, Show s, Symbol s) => Parser s a -> [s] -> Feedback a+parseFeedback parser input = do Pair x final <- evalSteps (parse parser input)+ final `seq` return x+ where+ evalSteps :: (Eq s, Show s) => Steps a s (Maybe s) -> Feedback a+ evalSteps (OkVal f rest) = do x <- evalSteps rest+ return (f x)+ evalSteps (Ok rest) = evalSteps rest+ evalSteps (Cost _ rest) = evalSteps rest+ evalSteps (StRepair _ msg rest) = do errorMessage (ppMessage msg)+ evalSteps rest+ evalSteps (Best _ rest _) = evalSteps rest+ evalSteps (NoMoreSteps x) = return x++-- | Pretty prints a 'Message' produced by a 'Parser'.+ppMessage :: (Eq s, Show s) => Message s (Maybe s) -> Doc+ppMessage (Msg exp pos action)+ = above [ppHeader, ppUnexpected, ppExpected]+ where+ ppHeader = wrapped "Parse error."+ ppUnexpected = text "*** Unexpected : " >|< wrapped (describePosition pos)+ ppExpected = text "*** Expected : " >|< wrapped (describeExpecting exp) ++-- | Describes a symbol or the end of input.+describePosition :: Show s => Maybe s -> String+describePosition Nothing = "end of input"+describePosition (Just s) = show s++-- | Describes an expected symbol.+describeExpecting :: (Eq s, Show s) => Expecting s -> String++describeExpecting (ESym EmptyR) = "end of input"+describeExpecting (ESym (Range l r)) | l == r = show l+ | otherwise = show l ++ " .. " ++ show r++describeExpecting (EStr s) = s++describeExpecting (EOr []) = "end of input"+describeExpecting (EOr [e]) = describeExpecting e+describeExpecting (EOr [e, e']) = describeExpecting e ++ " or " +++ describeExpecting e'+describeExpecting (EOr [e, e', e'']) = describeExpecting e ++ ", " +++ describeExpecting e' ++ ", or " +++ describeExpecting e''+describeExpecting (EOr (e : es)) = describeExpecting e ++ ", " +++ describeExpecting (EOr es)++describeExpecting (ESeq []) = "end of input"+describeExpecting (ESeq (e : _)) = describeExpecting e
+ uu-cco-hut-parsing.cabal view
@@ -0,0 +1,28 @@+name: uu-cco-hut-parsing+version: 0.1.0.0+synopsis: Utilities for compiler construction+description: A small utility library accompanying the course on+ Compiler Construction (INFOMCCO) at Utrecht Univerity.+license: BSD3+license-file: LICENSE+category: Compilers/Interpreters+copyright: (c) 2008-2014 Utrecht University+author: Stefan Holdermans <stefan@holdermans.nl>+maintainer: Atze Dijkstra <atze@uu.nl>+stability: provisional+homepage: https://github.com/UU-ComputerScience/uu-cco+build-type: Simple+cabal-version: >= 1.6+extra-source-files: AUTHORS++source-repository head+ type: git+ location: git://github.com/UU-ComputerScience/uu-cco.git++library+ build-depends: base >= 4 && < 5, uulib >= 0.9.15, uu-cco >= 0.1.0.0+ exposed-modules: CCO.Parsing.UU+ other-modules: + extensions: Rank2Types+ hs-source-dirs: src+