libdparse icon indicating copy to clipboard operation
libdparse copied to clipboard

Parameter types

Open Dmunch04 opened this issue 4 years ago • 5 comments

Hi.

Are there any specific reason why it doesn't parse any parameter data types? And also, it would be neat to have functions that generated the signature as string for stuff like functions, variables, etc.

Dmunch04 avatar Jun 28 '20 23:06 Dmunch04

Can you provide a test case showing what you did, what you expected, and what you got ?

Geod24 avatar Jun 29 '20 00:06 Geod24

Well the thing is, I'm not sure what I should do? What is the recommended way to access types? Return types, parameter types, variable types, etc.

Dmunch04 avatar Jun 29 '20 15:06 Dmunch04

Like how would I get a Type's "pretty" value?

Dmunch04 avatar Jun 29 '20 21:06 Dmunch04

I'm not sure what you mean with a Type's "pretty" value.

If you are looking for something interpreting symbol types from source code you are instead looking for dsymbol instead of libdparse or you want to use dmd as a library. However dsymbol will lose some AST information or make it hard to access (such as how exactly you written a type in the definition)

libdparse will just give you the AST from some source code input to traverse over yourself, not anything more.

If you want to transform the AST back into code strings use dparse.formatter, example API usage: https://github.com/Pure-D/workspace-d/blob/9cf3d6424f2118a99f043cfd43eec20037190fa9/source/workspaced/dparseext.d#L19

WebFreak001 avatar Jun 30 '20 18:06 WebFreak001

I'm not sure what you mean with a Type's "pretty" value.

I mean the attribute from fx. dscanner on Type called pretty

Dmunch04 avatar Jun 30 '20 19:06 Dmunch04

dparse.formatter can be used to format whole things, e.g. you could unset the functionBody before calling it.

Alternatively you can access the .tokens slice on the FunctionDeclaration to get the raw tokens that make up the whole function declaration.

Parameters are parsed normally and can be visited.

Closing this issue since there doesn't seem to be anything to do on the libdparse side.

WebFreak001 avatar May 04 '23 02:05 WebFreak001