Skip to content

Commit

Permalink
Apply PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
thealmarty committed Jun 8, 2021
1 parent 0848d20 commit adcf32c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
18 changes: 10 additions & 8 deletions plutus-core/plutus-core/src/PlutusCore/ParserCommon.hs
Expand Up @@ -120,11 +120,7 @@ isIdentifierChar c = isAlphaNum c || c == '_' || c == '\''
reservedWord ::
-- | The word to match
T.Text -> Parser SourcePos
reservedWord w = lexeme $ try $ do
p <- getSourcePos
void $ string w
notFollowedBy (satisfy isIdentifierChar)
return p
reservedWord w = lexeme $ try $ getSourcePos <* symbol w

builtinFunction :: (Bounded fun, Enum fun, Pretty fun) => Parser fun
builtinFunction = lexeme $ choice $ map parseBuiltin [minBound .. maxBound]
Expand Down Expand Up @@ -160,11 +156,10 @@ enforce p = do
-- parse a built-in type or a constant. This is neither efficient (because of @manyTill anySingle@),
-- nor future-proof (what if some future built-in type has parens in its syntax?). A good way of
-- resolving this would be to turn 'PLC.parse' into a proper parser rather than just a function
-- from @Text@, but PLC's parser also uses 'PLC.parse' and it's currently not @megaparsec@-based,
-- and so mixing two distinct parsing machines doesn't sound too exciting.
--
-- from @Text@ - this will happen as SCP-2251 gets done.
-- Note that this also fails on @(con string \"yes (no)\")@ as well as @con unit ()@, so it really
-- should be fixed somehow.
-- (For @con unit ()@, @kwxm suggested replacing it with @unitval@ or @one@ or *)
closedChunk :: Parser T.Text
closedChunk = T.pack <$> manyTill anySingle end where
end = enforce whitespace <|> void (lookAhead $ char ')')
Expand All @@ -181,6 +176,13 @@ builtinTypeTag = do

-- | Parse a constant by parsing a type tag first and using the type-specific parser of constants.
-- Uses 'PLC.parse' under the hood for both types and constants.
-- @kwxm: this'll have problems with some built-in constants like strings and characters.
-- The existing parser has special cases involving complicated regular expressions
-- to deal with those (see Lexer.x), but things got more complicated recently when
-- @effectfully added built-in lists and pairs that can have other constants
-- nested inside them...We're probably still going to need special parsers
-- for things like quoted strings that can contain escape sequences.
-- @thealmarty will hopefully deal with these in SCP-2251.
constant
:: forall uni.
( PLC.Parsable (PLC.SomeTypeIn (PLC.Kinded uni))
Expand Down
Expand Up @@ -95,10 +95,14 @@ term
:: ( PLC.Parsable (PLC.Some uni), PLC.Closed uni, uni `PLC.Everywhere` PLC.Parsable
, Bounded fun, Enum fun, Pretty fun, PLC.Parsable (PLC.SomeTypeIn (PLC.Kinded uni)))
=> Parser (UPLC.Term PLC.Name uni fun SourcePos)
term = conTerm <|> builtinTerm <|> varTerm
<|> lamTerm self <|> appTerm self
<|> delayTerm self <|> forceTerm self
<|> errorTerm
term = conTerm
<|> builtinTerm
<|> varTerm
<|> lamTerm self
<|> appTerm self
<|> delayTerm self
<|> forceTerm self
<|> errorTerm
where self = term

-- | Parser for UPLC programs.
Expand Down

0 comments on commit adcf32c

Please sign in to comment.