language-rust-0.1.0.0: Parsing and pretty printing of Rust code

Copyright(c) Alec Theriault 2017-2018
LicenseBSD-style
Maintaineralec.theriault@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Language.Rust.Data.InputStream

Contents

Description

These are the only functions that need to be implemented in order to use the parser. Whether this wraps ByteString or String depends on whether the useByteStrings option is on or not (it is by default). Using ByteString means better handling of weird characters (takeByte for plain String fails badly if you try to take a byte that doesn't fall on a character boundary), but it means incurring a dependency on the utf8-string package.

Synopsis

InputStream type

countLines :: InputStream -> Int Source #

Returns the number of text lines in the given InputStream

>>> countLines ""
0
>>> countLines "foo"
1
>>> countLines "foo\n\nbar"
3
>>> countLines "foo\n\nbar\n"
3

inputStreamEmpty :: InputStream -> Bool Source #

Return True if the given input stream is empty.

>>> inputStreamEmpty ""
True
>>> inputStreamEmpty "foo"
False

Introduction forms

readInputStream :: FilePath -> IO InputStream Source #

Read an encoded file into an InputStream

Elimination forms

takeByte :: InputStream -> (Word8, InputStream) Source #

Read the first byte from an InputStream and return that byte with what remains of the InputStream. Behaviour is undefined when inputStreamEmpty returns True.

>>> takeByte "foo bar"
(102, "oo bar")
>>> takeByte "Ĥăƨĸëļļ"
(196, "\ETX\168\&8\235<<")

takeChar :: InputStream -> (Char, InputStream) Source #

Read the first character from an InputStream and return that Char with what remains of the InputStream. Behaviour is undefined when inputStreamEmpty returns True.

>>> takeChar "foo bar"
('f', "oo bar")
>>> takeChar "Ĥăƨĸëļļ"
('Ĥ', "ăƨĸëļļ")

peekChars :: Int -> InputStream -> String Source #

Returns the first n characters of the given input stream, without removing them.

>>> peekChars 5 "foo bar"
"foo ba"
>>> peekChars 5 "foo"
"foo"
>>> peekChars 3 "Ĥăƨĸëļļ"
"Ĥăƨ"