Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
Language.Fixpoint.Parse
Synopsis
- class Inputable a where
- type Parser = ParserV Symbol
- type ParserV v = StateT (PStateV v) (Parsec Void String)
- class (Fixpoint v, Ord v) => ParseableV v where
- reserved :: String -> ParserV v ()
- reservedOp :: String -> ParserV v ()
- reserved' :: Parser () -> String -> Parser ()
- reservedOp' :: Parser () -> String -> Parser ()
- locReserved :: String -> ParserV v (Located String)
- parens :: ParserV v a -> ParserV v a
- brackets :: ParserV v a -> ParserV v a
- angles :: ParserV v a -> ParserV v a
- braces :: ParserV v a -> ParserV v a
- semi :: ParserV v String
- comma :: ParserV v String
- colon :: ParserV v String
- dcolon :: ParserV v String
- dot :: ParserV v String
- pairP :: ParserV v a -> ParserV v z -> ParserV v b -> ParserV v (a, b)
- stringLiteral :: ParserV v String
- stringR :: ParserV v String
- locStringLiteral :: ParserV v (Located String)
- sym :: String -> ParserV v String
- lowerIdP :: ParserV v Symbol
- lowerIdR :: ParserV v Symbol
- upperIdP :: ParserV v Symbol
- upperIdR :: ParserV v Symbol
- symbolP :: ParserV v Symbol
- symbolR :: ParserV v Symbol
- locSymbolP :: ParserV v LocSymbol
- constantP :: ParserV v Constant
- natural :: ParserV v Integer
- naturalR :: ParserV v Integer
- locNatural :: ParserV v (Located Integer)
- bindP :: ParserV v Symbol
- sortP :: ParserV v Sort
- mkQual :: Symbol -> [QualParam] -> ExprV v -> SourcePos -> QualifierV v
- infixSymbolP :: Parser Symbol
- locInfixSymbolP :: ParserV v (Located Symbol)
- exprP :: ParseableV v => ParserV v (ExprV v)
- predP :: ParseableV v => ParserV v (ExprV v)
- funAppP :: ParseableV v => ParserV v (ExprV v)
- qualifierP :: ParseableV v => ParserV v Sort -> ParserV v (QualifierV v)
- refaP :: ParseableV v => ParserV v (ExprV v)
- refP :: Parser (Reft -> a) -> Parser a
- refDefP :: Symbol -> Parser Expr -> Parser (Reft -> a) -> Parser a
- refBindP :: Parser Symbol -> Parser Expr -> Parser (Reft -> a) -> Parser a
- defineP :: Parser Equation
- defineLocalP :: Parser (Int, [(Symbol, Expr)])
- matchP :: Parser Rewrite
- indentedBlock :: ParserV v a -> ParserV v [a]
- indentedLine :: ParserV v a -> ParserV v a
- indentedOrExplicitBlock :: ParserV v open -> ParserV v close -> ParserV v sep -> ParserV v a -> ParserV v [a]
- explicitBlock :: ParserV v open -> ParserV v close -> ParserV v sep -> ParserV v a -> ParserV v [a]
- explicitCommaBlock :: ParserV v a -> ParserV v [a]
- block :: ParserV v a -> ParserV v [a]
- spaces :: ParserV v ()
- setLayout :: ParserV v ()
- popLayout :: ParserV v ()
- condIdR :: ParserV v Char -> (Char -> Bool) -> (String -> Bool) -> String -> ParserV v Symbol
- lexeme' :: ParserV v () -> ParserV v a -> ParserV v a
- lexeme :: ParserV v a -> ParserV v a
- located :: ParserV v a -> ParserV v (Located a)
- locLexeme' :: ParserV v () -> ParserV v a -> ParserV v (Located a)
- locLexeme :: ParserV v a -> ParserV v (Located a)
- locLowerIdP :: ParserV v LocSymbol
- locUpperIdP :: ParserV v LocSymbol
- freshIntP :: ParserV v Integer
- doParse' :: Parser a -> SourceName -> String -> a
- parseTest' :: Show a => Parser a -> String -> IO ()
- parseFromFile :: Parser b -> SourceName -> IO b
- parseFromStdIn :: Parser a -> IO a
- remainderP :: Parser a -> Parser (a, String, SourcePos)
- isSmall :: Char -> Bool
- isNotReserved :: String -> Bool
- initPState :: ParseableV v => Maybe (Located String -> ExprV v) -> PStateV v
- type PState = PStateV Symbol
- data PStateV v = PState {}
- data LayoutStack
- data Fixity v
- data Assoc
- addOperatorP :: ParseableV v => Fixity v -> ParserV v ()
- addNumTyCon :: Symbol -> Parser ()
- expr0P :: ParseableV v => ParserV v (ExprV v)
- dataFieldP :: Parser DataField
- dataCtorP :: Parser DataCtor
- dataDeclP :: Parser DataDecl
- fTyConP :: ParserV v FTycon
- mkFTycon :: LocSymbol -> ParserV v FTycon
- intP :: ParserV v Int
- tvarP :: ParserV v Sort
- trueP :: ParserV v (ExprV v)
- falseP :: ParserV v (ExprV v)
- symconstP :: ParserV v SymConst
Top Level Class for Parseable Values
class Inputable a where Source #
Minimal complete definition
Nothing
Instances
Inputable Command Source # | |
Inputable Symbol Source # | |
Inputable Constant Source # | |
Inputable Expr Source # | |
Inputable (FInfo ()) Source # | |
Inputable (FInfoWithOpts ()) Source # | |
Defined in Language.Fixpoint.Parse | |
Inputable (FixResult Integer) Source # | |
Inputable [Command] Source # | |
Inputable (FixResult Integer, FixSolution) Source # | |
Top Level Class for Parseable Values
class (Fixpoint v, Ord v) => ParseableV v where Source #
A class to parse symbols
liquid-fixpoint parses Symbol and LiquidHaskell instantiates this to LocSymbol for more precise error messages. If liquid-fixpoint is adapted to parse names as LocSymbol as well, this class can be eliminated.
Some Important keyword and parsers
reserved :: String -> ParserV v () Source #
Parser that consumes the given reserved word.
The input token cannot be longer than the given name.
NOTE: we currently don't double-check that the reserved word is in the list of reserved words.
reservedOp :: String -> ParserV v () Source #
Parser that consumes the given reserved operator.
The input token cannot be longer than the given name.
NOTE: we currently don't double-check that the reserved operator is in the list of reserved operators.
parens :: ParserV v a -> ParserV v a Source #
Parser that consumes the given symbol.
The difference with reservedOp
is that the given symbol is seen
as a token of its own, so the next character that follows does not
matter.
symbol :: String -> Parser String symbol x = L.symbol spaces (string x)
brackets :: ParserV v a -> ParserV v a Source #
Parser that consumes the given symbol.
The difference with reservedOp
is that the given symbol is seen
as a token of its own, so the next character that follows does not
matter.
symbol :: String -> Parser String symbol x = L.symbol spaces (string x)
angles :: ParserV v a -> ParserV v a Source #
Parser that consumes the given symbol.
The difference with reservedOp
is that the given symbol is seen
as a token of its own, so the next character that follows does not
matter.
symbol :: String -> Parser String symbol x = L.symbol spaces (string x)
braces :: ParserV v a -> ParserV v a Source #
Parser that consumes the given symbol.
The difference with reservedOp
is that the given symbol is seen
as a token of its own, so the next character that follows does not
matter.
symbol :: String -> Parser String symbol x = L.symbol spaces (string x)
stringLiteral :: ParserV v String Source #
Parses a string literal as a lexeme. This is based on megaparsec's
charLiteral
parser, which claims to handle all the single-character
escapes defined by the Haskell grammar.
Parsing basic entities
lowerIdR :: ParserV v Symbol Source #
Raw parser for an identifier starting with a lowercase letter.
See Note [symChars].
upperIdR :: ParserV v Symbol Source #
Raw parser for an identifier starting with an uppercase letter.
See Note [symChars].
symbolP :: ParserV v Symbol Source #
Unconstrained identifier, lower- or uppercase.
Must not be a reserved word.
Lexeme version of symbolR
.
symbolR :: ParserV v Symbol Source #
Raw parser for an identifier starting with any letter.
See Note [symChars].
locSymbolP :: ParserV v LocSymbol Source #
constantP :: ParserV v Constant Source #
Parser for literal numeric constants: floats or integers without sign.
natural :: ParserV v Integer Source #
Consumes a natural number literal lexeme, which can be in decimal, octal and hexadecimal representation.
This does not parse negative integers. Unary minus is available as an operator in the expression language.
mkQual :: Symbol -> [QualParam] -> ExprV v -> SourcePos -> QualifierV v Source #
constructing qualifiers
infixSymbolP :: Parser Symbol Source #
Parses any of the known infix operators.
locInfixSymbolP :: ParserV v (Located Symbol) Source #
Located version of infixSymbolP
.
Parsing recursive entities
predP :: ParseableV v => ParserV v (ExprV v) Source #
Parses a predicate.
Unlike for expressions, there is a built-in operator list.
funAppP :: ParseableV v => ParserV v (ExprV v) Source #
Parser for function applications.
Andres, TODO: Why is this so complicated?
qualifierP :: ParseableV v => ParserV v Sort -> ParserV v (QualifierV v) Source #
Parsing Qualifiers --------------------------------------------------------
Qualifiers
refaP :: ParseableV v => ParserV v (ExprV v) Source #
BareTypes -----------------------------------------------------------------
Refa
refDefP :: Symbol -> Parser Expr -> Parser (Reft -> a) -> Parser a Source #
(Sorted) Refinements with default binder
refBindP :: Parser Symbol -> Parser Expr -> Parser (Reft -> a) -> Parser a Source #
(Sorted) Refinements with configurable sub-parsers
Layout
indentedBlock :: ParserV v a -> ParserV v [a] Source #
Parse a block delimited by layout. The block must be indented more than the surrounding blocks, otherwise we return an empty list.
Assumes that the parser for items does not accept the empty string.
indentedLine :: ParserV v a -> ParserV v a Source #
Parse a single line that may be continued via layout.
indentedOrExplicitBlock :: ParserV v open -> ParserV v close -> ParserV v sep -> ParserV v a -> ParserV v [a] Source #
Parse a block of items which can be delimited either via layout or via explicit delimiters as specified.
Assumes that the parser for items does not accept the empty string.
explicitBlock :: ParserV v open -> ParserV v close -> ParserV v sep -> ParserV v a -> ParserV v [a] Source #
Parse a block of items that are delimited via explicit delimiters. Layout is disabled/reset for the scope of this block.
explicitCommaBlock :: ParserV v a -> ParserV v [a] Source #
Parses a block with explicit braces and commas as separator. Used for record constructors in datatypes.
block :: ParserV v a -> ParserV v [a] Source #
Parses a block via layout or explicit braces and semicolons.
Assumes that the parser for items does not accept the empty string.
However, even in layouted mode, we are allowing semicolons to separate block contents. We also allow semicolons at the beginning, end, and multiple subsequent semicolons, so the resulting parser provides the illusion of allowing empty items.
spaces :: ParserV v () Source #
Consumes all whitespace, including LH comments.
Should not be used directly, but primarily via lexeme
.
The only "valid" use case for spaces is in top-level parsing function, to consume initial spaces.
Raw identifiers
condIdR :: ParserV v Char -> (Char -> Bool) -> (String -> Bool) -> String -> ParserV v Symbol Source #
Raw (non-whitespace) parser for an identifier adhering to certain conditions.
The arguments are as follows, in order:
- the parser for the initial character,
- a predicate indicating which subsequent characters are ok,
- a check for the entire identifier to be applied in the end,
- an error message to display if the final check fails.
Lexemes and lexemes with location
lexeme' :: ParserV v () -> ParserV v a -> ParserV v a Source #
Indentation-aware lexeme parser. Before parsing, establishes whether we are in a position permitted by the layout stack. After the token, consume whitespace and potentially change state.
located :: ParserV v a -> ParserV v (Located a) Source #
Make a parser location-aware.
This is at the cost of an imprecise span because we still consume spaces in the end first.
locLexeme' :: ParserV v () -> ParserV v a -> ParserV v (Located a) Source #
Indentation-aware located lexeme parser.
This is defined in such a way that it determines the actual source range covered by the identifier. I.e., it consumes additional whitespace in the end, but that is not part of the source range reported for the identifier.
locLowerIdP :: ParserV v LocSymbol Source #
locUpperIdP :: ParserV v LocSymbol Source #
Getting a Fresh Integer while parsing
Parsing Function
doParse' :: Parser a -> SourceName -> String -> a Source #
Entry point for parsing, for testing.
Take the top-level parser, the source file name, and the input as a string. Fails with an exception on a parse error.
parseFromFile :: Parser b -> SourceName -> IO b Source #
parseFromStdIn :: Parser a -> IO a Source #
remainderP :: Parser a -> Parser (a, String, SourcePos) Source #
Parse via the given parser, and obtain the rest of the input as well as the final source position.
Utilities
isSmall :: Char -> Bool Source #
Predicate version to check if the characer is a valid initial
character for lowerIdR
.
TODO: What is this needed for?
isNotReserved :: String -> Bool Source #
initPState :: ParseableV v => Maybe (Located String -> ExprV v) -> PStateV v Source #
Initial parser state.
The parser state.
We keep track of the fixities of infix operators.
We also keep track of whether empty list and singleton lists syntax is allowed (and how they are to be interpreted, if they are).
We also keep track of an integer counter that can be used to supply unique integers during the parsing process.
Finally, we keep track of the layout stack.
Constructors
PState | |
Fields
|
data LayoutStack Source #
The layout stack tracks columns at which layout blocks have started.
Constructors
Empty | no layout info |
Reset LayoutStack | in a block not using layout |
At Pos LayoutStack | in a block at the given column |
After Pos LayoutStack | past a block at the given column |
Instances
Show LayoutStack Source # | |
Defined in Language.Fixpoint.Parse Methods showsPrec :: Int -> LayoutStack -> ShowS # show :: LayoutStack -> String # showList :: [LayoutStack] -> ShowS # |
addOperatorP :: ParseableV v => Fixity v -> ParserV v () Source #
Add an operator to the parsing state.
addNumTyCon :: Symbol -> Parser () Source #
Add a new numeric FTyCon (symbol) to the parsing state.
For testing
expr0P :: ParseableV v => ParserV v (ExprV v) Source #
Parser for "atomic" expressions.
This parser is reused by Liquid Haskell.
dataFieldP :: Parser DataField Source #
Parsing Data Declarations -------------------------------------------------