Skip to content

Use alternative parser based on type annotation #28

@theophile-scrive

Description

@theophile-scrive

Hi @brandonchinn178 it's me again. :)

I am trying to distinguish user input based on type annotation, for what would be either a text literal or a reference. I plan on using type annotations to label strings, and parse those as separate data types.
However using (naïvely I must confess) the (<|>) operator does not seem to give the expected results.

Here is a an excerpt from the reproducer, that you can run with cabal run Repro.hs:

myNodeDecoder :: DecodeArrow NodeList () (Either Var Text)
myNodeDecoder =
  KDL.nodeWith "node" $
    (Right <$> KDL.argWith' ["text"] KDL.text)
      <|> (Left <$> KDL.argWith' ["var"] (Var <$> KDL.text))

Should I drop to a lower parsing level to make the distinction?

Repro.hs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions