Skip to content

How to get the original (source) floating-point literal? #551

Closed
@bellon-tiobe

Description

@bellon-tiobe

Hi,

I am writing an automatic check for a coding standard rule about writing digits on either side of the dot in floating-point literals, but I discovered that I cannot really check it, because the missing zero was added at some earlier time.

julia> import JuliaSyntax as JS

julia> JS.parsestmt(JS.SyntaxNode, ".5")
SyntaxNode:
0.5                                      :: Float

All my attempts to get the original input have failed. See these attempt I took with the help of Infiltrator:

infil> JS.sourcetext(node)
"0.5"

infil> string(node)
"0.5"

infil> JS.untokenize(node)
ERROR: MethodError: no method matching untokenize(::JuliaSyntax.SyntaxNode)
The function `untokenize` exists, but no method is defined for this combination of argument types.
  ...

infil> JS.untokenize(node.raw)
ERROR: MethodError: no method matching untokenize(::JuliaSyntax.GreenNode{JuliaSyntax.SyntaxHead})
The function `untokenize` exists, but no method is defined for this combination of argument types.
   ...

infil> JS.untokenize(JS.head(node.raw))
ERROR: TypeError: in typeassert, expected String, got a value of type Nothing
   ...

infil> JS.untokenize(JS.head(node))
ERROR: TypeError: in typeassert, expected String, got a value of type Nothing
   ...

Is it possible to get the original literal .5? How?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions