dlang-community / libdparse

Library for lexing and parsing D source code
https://libdparse.dlang.io
Boost Software License 1.0
114 stars 56 forks source link

Parameter types #421

Closed Dmunch04 closed 1 year ago

Dmunch04 commented 4 years ago

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.

Geod24 commented 4 years ago

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

Dmunch04 commented 4 years ago

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 commented 4 years ago

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

WebFreak001 commented 4 years ago

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

Dmunch04 commented 4 years ago

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

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

WebFreak001 commented 1 year ago

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.