Skip to content

Bug in the workflow of parsers #1491

Closed
Closed

Description

@adithyaov

Consider the following parser:

data LineContent
    = LineContentText String
    | LineContentIdentifier String
    deriving (Show)

lineParser :: MonadCatch m => Parser m Char Line
lineParser = Parser.many content Fold.toList

    where

    identifierSimple =
        Parser.some (alphaNumP `alt_` charP '\'' `alt_` charP '_') Fold.toList
    identifierInBraces = charP '{' *> identifierSimple <* charP '}'
    identifier =
        fmap LineContentIdentifier
            $ charP '$' *> (identifierInBraces `alt_` identifierSimple)
    escapedDollar = fmap (LineContentText . (: [])) $ charP '$' *> charP '$'
    -- "Parser.count" is undefined. The current implementation eats the
    -- malformed '$' instead of erroring out. This should be fixed if 'count' is
    -- used.
    -- escapedDollar =
    --     fmap LineContentText
    --         $ charP '$' *> Parser.count 1 (charP '$') Fold.toList
    anySingle = Parser.satisfy (const True)
    end =
        void (Parser.lookAhead escapedDollar)
            `alt_` void (Parser.lookAhead identifier)
            `alt_` Parser.eof
    contentText = LineContentText <$> Parser.manyTill anySingle end Fold.toList
    content = escapedDollar `alt_` identifier `alt_` contentText

With alt_ = (<|>), the ParserK alternative, the last identifier is not parsed
properly. The rest of the input returned by parse_ is also improper because of
the incorrect parsing.

With alt_ = alt, the ParserD alternative, few identifiers are reversed.

Activity

  1. added
    type:bug
    on Feb 21, 2022
  2. added this to the 0.9.0 milestone on Mar 4, 2022
  3. adithyaov commented on Sep 15, 2022

    @adithyaov
    MemberAuthor

    Bug in the interconversion of parsers,

    import qualified Streamly.Internal.Data.Parser as Parser
    import qualified Streamly.Internal.Data.Parser.ParserD as D
    import qualified Streamly.Internal.Data.Fold as Fold
    import qualified Streamly.Internal.Data.Stream as Stream
    
    main1 =
        Stream.parse
            (Parser.takeWhile (== '1') Fold.drain
                 *> Parser.takeWhile (== ' ') Fold.drain)
            $ Stream.fromList "1"
    

    The above does not produce expected result.

    EDIT: This was solved.

  4. adithyaov commented on Sep 16, 2022

    @adithyaov
    MemberAuthor

    See #1838

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type:bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions