haskell-suite/haskell-src-exts

Strange AST Produced with certain extensions and Numeric literals

merc1031 opened this issue · 0 comments

There are a few issues with extended numeric literals i have seen when poking around floskell Which uses HSE
Ill try to capture these below

HexFloatLiterals produce a series of InifixApp and QVarOp, which ends up being ambiguous
They both produce the following (cleaned up for visibility)
Both f 0xF . FFp12 and f 0xF.FFp12 (with -XHexFloatLiterals, ghci and ghc turn this one into a Float)
produce

InfixApp
  ( App
      ( Var
          ( UnQual
              ( Ident
                 "f"
              )
          )
      )
      ( Lit
          ( Int
              15 "0xF"
          )
      )
  )
  ( QVarOp
      ( UnQual
          ( Symbol
              "."
          )
      )
  )
  ( Con
      ( UnQual
          ( Ident
             "FFp12"
          )
      )
  )

NumericUnderscores produce 2 different issues.
The first, simpler issue:
It splits the int on the first _ and produces an App
3_000
produces

( App
    ( Lit
        ( Int
            3 "3"
        )
    )
    ( Var
        ( UnQual
            ( Ident
                "_000"
            )
        )
    )
)

The second more broken issue is combined with exponent syntax:
It splits the int on the first _ and produces an App followed by a QVarOp +
6.022_140_857e+23
produces

InfixApp
    ( App
        ( Lit
            ( Frac
                ( 3011 % 500 ) "6.022"
            )
        )
        ( Var
            ( UnQual
                ( Ident
                    "_140_857e"
                )
            )
        )
    )
    ( QVarOp
        ( UnQual
            ( Symbol
                "+"
            )
        )
    )
    ( Lit
        ( Int
            23 "23"
        )
    )
)