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

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


module Char where

import IsUpper
import IsDigit
import IsOctDigit
import IsHexDigit
import AsciiTab

lexLitChar		:: ReadS String
lexLitChar ('\\':s)	=  map (prefix '\\') (lexEsc s)
	where
	prefix c (t,s) = (c:t, s)

	lexEsc (c:s)	 | c `elem` "abfnrtv\\\"'" = [([c],s)]
  	lexEsc ('^':c:s) | c >= '@' && c <= '_'    = [(['^',c],s)]

	-- Numeric escapes
	lexEsc ('o':s)               = [prefix 'o' (span isOctDigit s)]
	lexEsc ('x':s)               = [prefix 'x' (span isHexDigit s)]
        lexEsc s@(d:_)   | isDigit d = [span isDigit s]

	-- Very crude approximation to \XYZ.  
--	lexEsc s@(c:_)   | isUpper c = [span isCharName s]
--				where isCharName c   = isUpper c || isDigit c
	-- Much better approximation to \XYZ.  
	lexEsc s@(c:_)	 | isUpper c
			=  case [(mne,s') | mne <- "DEL": map snd asciiTab
					  , ([],s') <- [match mne s]	  ]
			   of (pr:_) -> [pr]
			      []     -> []
	lexEsc _	=  []

	match :: (Eq a) => [a] -> [a] -> ([a],[a])
	match (x:xs) (y:ys) | x == y  =  match xs ys
	match xs     ys		      =  (xs,ys)


lexLitChar (c:s)	=  [([c],s)]
lexLitChar ""		= []

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].