Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Parsers for PLC terms in DefaultUni.
Synopsis
- type PType = Type TyName DefaultUni SrcSpan
- varType :: Parser PType
- funType :: Parser PType
- allType :: Parser PType
- lamType :: Parser PType
- ifixType :: Parser PType
- builtinType :: Parser PType
- sopType :: Parser PType
- appType :: Parser PType
- kind :: Parser (Kind SrcSpan)
- pType :: Parser PType
- defaultUniApplication :: Parser (SomeTypeIn (Kinded DefaultUni))
- defaultUni :: Parser (SomeTypeIn (Kinded DefaultUni))
- tyName :: Parser TyName
- newtype ParserState = ParserState {
- identifiers :: Map Text Unique
- type Parser = ParsecT ParserError Text (StateT ParserState (ReaderT (Maybe Version) Quote))
- initial :: ParserState
- getVersion :: Parser (Maybe Version)
- withVersion :: Version -> Parser a -> Parser a
- whenVersion :: (Version -> Bool) -> Parser () -> Parser ()
- parse :: (AsParserErrorBundle e, MonadError e m, MonadQuote m) => Parser a -> String -> Text -> m a
- toErrorB :: Either (ParseErrorBundle Text ParserError) a -> Either ParserErrorBundle a
- parseGen :: (AsParserErrorBundle e, MonadError e m, MonadQuote m) => Parser a -> Text -> m a
- whitespace :: Parser ()
- leadingWhitespace :: Parser a -> Parser a
- trailingWhitespace :: Parser a -> Parser a
- withSpan' :: (SrcSpan -> Parser a) -> Parser a
- withSpan :: (SrcSpan -> Parser a) -> Parser a
- lexeme :: Parser a -> Parser a
- symbol :: Text -> Parser Text
- inParens :: Parser a -> Parser a
- inBrackets :: Parser a -> Parser a
- inBraces :: Parser a -> Parser a
- toSrcSpan :: SourcePos -> SourcePos -> SrcSpan
- version :: Parser Version
- name :: Parser Name
- cachedBuiltin :: Map Text DefaultFun
- builtinFunction :: Parser DefaultFun
- conInteger :: Parser Integer
- hexByte :: Parser Word8
- conBS :: Parser ByteString
- conText :: Parser Text
- conUnit :: Parser ()
- conBool :: Parser Bool
- conList :: DefaultUni (Esc a) -> Parser [a]
- conPair :: DefaultUni (Esc a) -> DefaultUni (Esc b) -> Parser (a, b)
- conDataNoParens :: Parser Data
- conData :: ExpectParens -> Parser Data
- con0xBS :: Parser ByteString
- conBLS12_381_G1_Element :: Parser Element
- conBLS12_381_G2_Element :: Parser Element
- constantOf :: ExpectParens -> DefaultUni (Esc a) -> Parser a
- constant :: Parser (Some (ValueOf DefaultUni))
- data ExpectParens
- program :: Parser (Program TyName Name DefaultUni DefaultFun SrcSpan)
- parseProgram :: (AsParserErrorBundle e, MonadError e m, MonadQuote m) => Text -> m (Program TyName Name DefaultUni DefaultFun SrcSpan)
- parseTerm :: (AsParserErrorBundle e, MonadError e m, MonadQuote m) => Text -> m (Term TyName Name DefaultUni DefaultFun SrcSpan)
- parseType :: (AsParserErrorBundle e, MonadError e m, MonadQuote m) => Text -> m (Type TyName DefaultUni SrcSpan)
- data SourcePos
- data ParserError
Documentation
type PType = Type TyName DefaultUni SrcSpan Source #
A PLC Type
to be parsed. ATM the parser only works
for types in the DefaultUni
with DefaultFun
.
defaultUniApplication :: Parser (SomeTypeIn (Kinded DefaultUni)) Source #
Parser for built-in type applications. The textual names here should match the ones in the PrettyBy instance for DefaultUni in PlutusCore.Default.Universe.
defaultUni :: Parser (SomeTypeIn (Kinded DefaultUni)) Source #
Parser for built-in types (the ones from DefaultUni
specifically).
Kinded
is needed for checking that a type function can be applied to its argument.
I.e. we do Plutus kind checking of builtin type applications during parsing, which is
unfortunate, but there's no way we could construct a DefaultUni
otherwise.
In case of kind error no sensible message is shown, only an overly general one:
>>>
:set -XTypeApplications
>>>
:set -XOverloadedStrings
>>>
import PlutusCore.Error
>>>
import PlutusCore.Quote
>>>
let runP = putStrLn . either display display . runQuoteT . parseGen @ParserErrorBundle defaultUni
>>>
runP "(list integer)"
(list integer)>>>
runP "(bool integer)"
test:1:14: | 1 | (bool integer) | ^ expecting "bool", "bytestring", "data", "integer", "list", "pair", "string", "unit", or '('
This is to be fixed.
One thing we could do to avoid doing kind checking during parsing is to parse into
data TextualUni a where TextualUni :: TextualUni (Esc (Tree Text))
i.e. parse into Tree Text
and do the kind checking afterwards, but given that we'll still need
to do the kind checking of builtins regardless (even for UPLC), we don't win much by deferring
doing it.
newtype ParserState Source #
Instances
Show ParserState Source # | |
Defined in PlutusCore.Parser.ParserCommon |
type Parser = ParsecT ParserError Text (StateT ParserState (ReaderT (Maybe Version) Quote)) Source #
getVersion :: Parser (Maybe Version) Source #
Get the version of the program being parsed, if we know it.
whenVersion :: (Version -> Bool) -> Parser () -> Parser () Source #
Run an action conditionally based on a predicate on the version. If we don't know the version then the predicate is assumed to be false, i.e. we act if we _know_ the predicate is satisfied.
parse :: (AsParserErrorBundle e, MonadError e m, MonadQuote m) => Parser a -> String -> Text -> m a Source #
toErrorB :: Either (ParseErrorBundle Text ParserError) a -> Either ParserErrorBundle a Source #
parseGen :: (AsParserErrorBundle e, MonadError e m, MonadQuote m) => Parser a -> Text -> m a Source #
Generic parser function in which the file path is just "test".
whitespace :: Parser () Source #
Space consumer.
leadingWhitespace :: Parser a -> Parser a Source #
trailingWhitespace :: Parser a -> Parser a Source #
withSpan' :: (SrcSpan -> Parser a) -> Parser a Source #
Returns a parser for a
by calling the supplied function on the starting
and ending positions of a
.
The supplied function should usually return a parser that does not consume trailing whitespaces. Otherwise, the end position will be the first character after the trailing whitespaces.
withSpan :: (SrcSpan -> Parser a) -> Parser a Source #
Like withSpan'
, but the result parser consumes whitespaces.
@withSpan = (<* whitespace) . withSpan'
inBrackets :: Parser a -> Parser a Source #
builtinFunction :: Parser DefaultFun Source #
Parser for builtin functions. Atm the parser can only parse DefaultFun
.
conInteger :: Parser Integer Source #
Parser for integer constants.
conBS :: Parser ByteString Source #
Parser for bytestring constants. They start with "#".
conText :: Parser Text Source #
Parser for string constants (wrapped in double quotes). Note that
Data.Text.pack "performs replacement on invalid scalar values", which means
that Unicode surrogate code points (corresponding to integers in the range
0xD800-0xDFFF) are converted to the Unicode replacement character U+FFFD
(decimal 65533). Thus `(con string "XxD800Z")` parses to a Text
object
whose second character is U+FFFD.
conPair :: DefaultUni (Esc a) -> DefaultUni (Esc b) -> Parser (a, b) Source #
Parser for pairs.
constantOf :: ExpectParens -> DefaultUni (Esc a) -> Parser a Source #
Parser for constants of the given type.
constant :: Parser (Some (ValueOf DefaultUni)) Source #
Parser of constants whose type is in DefaultUni
.
program :: Parser (Program TyName Name DefaultUni DefaultFun SrcSpan) Source #
Parser for PLC programs.
parseProgram :: (AsParserErrorBundle e, MonadError e m, MonadQuote m) => Text -> m (Program TyName Name DefaultUni DefaultFun SrcSpan) Source #
parseTerm :: (AsParserErrorBundle e, MonadError e m, MonadQuote m) => Text -> m (Term TyName Name DefaultUni DefaultFun SrcSpan) Source #
Parse a PLC term. The resulting program will have fresh names. The underlying monad must be capable of handling any parse errors.
parseType :: (AsParserErrorBundle e, MonadError e m, MonadQuote m) => Text -> m (Type TyName DefaultUni SrcSpan) Source #
Parse a PLC type. The resulting program will have fresh names. The underlying monad must be capable of handling any parse errors.
Instances
Data SourcePos | |
Defined in Text.Megaparsec.Pos gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SourcePos -> c SourcePos Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SourcePos Source # toConstr :: SourcePos -> Constr Source # dataTypeOf :: SourcePos -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c SourcePos) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SourcePos) Source # gmapT :: (forall b. Data b => b -> b) -> SourcePos -> SourcePos Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SourcePos -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SourcePos -> r Source # gmapQ :: (forall d. Data d => d -> u) -> SourcePos -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> SourcePos -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SourcePos -> m SourcePos Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SourcePos -> m SourcePos Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SourcePos -> m SourcePos Source # | |
Generic SourcePos | |
Read SourcePos | |
Show SourcePos | |
NFData SourcePos | |
Defined in Text.Megaparsec.Pos | |
Eq SourcePos | |
Ord SourcePos | |
Defined in Text.Megaparsec.Pos | |
Pretty SourcePos Source # | |
Defined in PlutusCore.Error | |
type Rep SourcePos | |
Defined in Text.Megaparsec.Pos type Rep SourcePos = D1 ('MetaData "SourcePos" "Text.Megaparsec.Pos" "megaparsec-9.6.1-2y4TSvMYdIdIGL4Xdwvkcx" 'False) (C1 ('MetaCons "SourcePos" 'PrefixI 'True) (S1 ('MetaSel ('Just "sourceName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FilePath) :*: (S1 ('MetaSel ('Just "sourceLine") 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Pos) :*: S1 ('MetaSel ('Just "sourceColumn") 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Pos)))) |
data ParserError Source #
An error encountered during parsing.
BuiltinTypeNotAStar !Text !SourcePos | |
UnknownBuiltinFunction !Text !SourcePos ![Text] | |
InvalidBuiltinConstant !Text !Text !SourcePos |