cfv
Copyright(c) Harley Eades 2026
Maintainerharley.eades@gmail.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Configuration.Cfv.Parser

Description

This module consists of the CFV parser API.

Synopsis

Documentation

parseCfvFile :: FilePath -> IO (Either CfvError [Binding]) Source #

Read, parse and evaluate a .cfv file using defaultShellConfig. Returns the variables in source order; a variable declared more than once appears more than once (so lookup finds the first declaration). Commands run one at a time in file order, and the first failure aborts the whole operation.

Never throws for extension, read, decode, parse or command problems; they are all returned as CfvError. (To throw instead: either E.throwIO pure =<< parseCfvFile p.)

parseCfvFileWith :: ShellConfig -> FilePath -> IO (Either CfvError [Binding]) Source #

Like parseCfvFile with an explicit shell configuration.

data CfvError Source #

Everything that can go wrong when processing a CFV file.

Constructors

InvalidExtension FilePath

The file name does not end in .cfv (checked before anything is read).

FileReadError FilePath IOException

The file could not be opened or read.

FileDecodeError FilePath UnicodeException

The file's contents are not valid UTF-8.

FileSyntaxError SyntaxError

The contents do not parse.

FileCommandError CommandError Text VarAttr Position

A backtick command could not be run, or failed. (Only produced by functions that run commands.)

Instances

Instances details
Exception CfvError Source # 
Instance details

Defined in Configuration.Cfv.Parser

Show CfvError Source # 
Instance details

Defined in Configuration.Cfv.Parser

Eq CfvError Source # 
Instance details

Defined in Configuration.Cfv.Parser

data SyntaxError Source #

A problem with the text itself, with a location.

Constructors

SyntaxError 

Fields

data ErrorKind Source #

The specific kind of syntax error.

Constructors

UnexpectedInput (Maybe Item) [Item]

Found this (if known), but expected one of these.

ReservedWord Text

A Haskell keyword (or a lone _) was used as a variable name. Position: start of the word.

InvalidEscape (Maybe Char)

A backslash followed by a character that is not a known escape. Position: the backslash. Nothing (character withheld) inside the value of a Secret declaration.

UnterminatedString Char

A string literal with no closing quote (carries the quote character). Position: the opening quote.

UnterminatedCommand

A backtick command with no closing backtick. Position: the opening backtick.

OtherFailure Text

Anything else; should not occur with the current grammar.

Instances

Instances details
Show ErrorKind Source # 
Instance details

Defined in Configuration.Cfv.Parser

Eq ErrorKind Source # 
Instance details

Defined in Configuration.Cfv.Parser

data Item Source #

Something the parser found or expected.

Constructors

Literal Text

Specific text, such as ";".

Description Text

A named construct, such as "variable name".

EndOfFile 

Instances

Instances details
Show Item Source # 
Instance details

Defined in Configuration.Cfv.Parser

Methods

showsPrec :: Int -> Item -> ShowS #

show :: Item -> String #

showList :: [Item] -> ShowS #

Eq Item Source # 
Instance details

Defined in Configuration.Cfv.Parser

Methods

(==) :: Item -> Item -> Bool #

(/=) :: Item -> Item -> Bool #

Ord Item Source # 
Instance details

Defined in Configuration.Cfv.Parser

Methods

compare :: Item -> Item -> Ordering #

(<) :: Item -> Item -> Bool #

(<=) :: Item -> Item -> Bool #

(>) :: Item -> Item -> Bool #

(>=) :: Item -> Item -> Bool #

max :: Item -> Item -> Item #

min :: Item -> Item -> Item #

data Position Source #

A location in the source. Line and column are 1-based; the offset is the 0-based character offset from the start of the input.

Constructors

Position 

Instances

Instances details
Show Position Source # 
Instance details

Defined in Configuration.Cfv.Parser

Eq Position Source # 
Instance details

Defined in Configuration.Cfv.Parser

parseEvalCfv :: [Char] -> Text -> IO (Either CfvError [Binding]) Source #

Like parseCfvFile, but doesn't read from a file. Useful for testing.

parseEvalCfvWith :: ShellConfig -> [Char] -> Text -> IO (Either CfvError [Binding]) Source #

Like parseEvalCfv but with an explicit shell configuration.

renderCfvError :: CfvError -> Text Source #

Converts a error into a Text that is appropriate for logging.