Skip to content

Keep track of original constant notation in untyped tree #11504

Open
@nojaf

Description

@nojaf

Is your feature request related to a problem? Please describe.

When the user types a constant in a custom format, this information is lost in the untyped tree.
Example

let a = 1.

This exact notation 1. is parsed correctly and ends up being SynExpr.Const (SynConst.Double 1.0)).

Describe the solution you'd like
I'd like to see the original format the user typed in the untyped tree.
Something like

[<NoEquality; NoComparison; RequireQualifiedAccess>]
type SynConst =
    // ...

    | Double of notation:string * value:double

Describe alternatives you've considered
This information can be retrieved from the F# tokens.

Additional context
At first glance, this seems quite doable.
We can extend the F# token for the constant:
pars.fsy

%token <string * double> IEEE64
| IEEE64
    { let notation, value = $1
      SynConst.Double (notation, value) } 

lex.fsl

 | ieee64
     { let v = lexeme lexbuf
       IEEE64 (v, try float(lexeme lexbuf) with _ -> fail args lexbuf (FSComp.SR.lexInvalidFloat()) 0.0) }

There are multiple constants where I see this gain (chars for example).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions