Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/prelude/PreludeText/_ReadField.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module Prelude where

import Char (isLower)
import TReadS

_readField :: (Read a) => String -> String -> (String -> [(a->b,String)]) -> ReadS b

_readField prefix name fun
    | (let h = head name in
       isLower h || h=='_') =				-- ordinary fieldname
        \ r ->  [(c a,s) | (c,r) <- fun r,
		           (tok,r) <- lex r,
                           tok == prefix,
		           (tok,r) <- lex r,
                           tok == name,
		           (tok,r) <- lex r,
                           tok == "=",
		           (a,s) <- readsPrec 0 r]
    | otherwise =					-- symbol fieldname
        \ r ->  [(c a,s) | (c,r) <- fun r,
		           (tok,r) <- lex r,
                           tok == prefix,
		           (tok,r) <- lex r,
                           tok == "(",
		           (tok,r) <- lex r,
                           tok == init (tail name),	-- trim parens off
		           (tok,r) <- lex r,
                           tok == ")",
		           (tok,r) <- lex r,
                           tok == "=",
		           (a,s) <- readsPrec 0 r]

_readFinal postfix reader =
        \ r ->  [(c,s) | (c,r) <- reader r,
                         (tok,s) <- lex r,
                         tok == postfix ]


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.