Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardcoded parse logic #11

Open
beef331 opened this issue Nov 19, 2022 · 2 comments
Open

Hardcoded parse logic #11

beef331 opened this issue Nov 19, 2022 · 2 comments
Labels
design API Design

Comments

@beef331
Copy link

beef331 commented Nov 19, 2022

Presently the logic to parse types is hardcoded https://github.com/juancarlospaco/cliche/blob/nim/src/cliche.nim#L122-L139 . Is there any specific reason this does not use a generic interface like the following?

proc parseCommand[T](input: openarray[char]): T

This would enable support for any user type, without any added support from you.

@juancarlospaco
Copy link
Owner

juancarlospaco commented Nov 19, 2022

The idea was to parse Primitives with decent performance for any targets,
not so much complex big types or any arbitrary unstructured data,
but without generating a wall of text in the expansion.

Also to keep the APIs simple in the usage, like if you have to pass too complex or nested data,
maybe just use something like --config=config.json or similar.

What would you put inside that proc ?
Just the same of the lines https://github.com/juancarlospaco/cliche/blob/nim/src/cliche.nim#L122-L139 ?

I am not complaining just wondering. PR are welcome too.

@beef331
Copy link
Author

beef331 commented Nov 19, 2022

It would not be a single proc it'd be one for each type so you'd have:

import std/parseutils

proc parseCommand(oa: openarray[char], T: typedesc[bool]): T =
  parseBool(oa) # 1.7.x only sorry :P 

proc parseCommand(oa: openarray[char], T: typedesc[int]): T = 
  parseint(oa) # 1.7.x only sorry :P 

This would allow support for user defined data types, and make it less tedious to add new first class types.

@juancarlospaco juancarlospaco added the design API Design label Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design API Design
Projects
None yet
Development

No branches or pull requests

2 participants