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

RFC: --patchast to patch all modules via AST transformations #75

Open
timotheecour opened this issue Mar 27, 2020 · 0 comments
Open

RFC: --patchast to patch all modules via AST transformations #75

timotheecour opened this issue Mar 27, 2020 · 0 comments

Comments

@timotheecour
Copy link
Owner

timotheecour commented Mar 27, 2020

more general and flexible than these:

  • --import
    not good coz not flexible: all or nothing, can't apply to just a set of files etc

  • --include
    ditto, not flexible

  • --trmacros term rewriting macros
    not good coz too magical yet not flexible enough; reminds of perl: cryptic

  • --expandMacro:MACRO
    ditto, not flexible

use cases

  • can be used as a basis for nimfix v2
    the AST can be rendered alongside nimpretty to re-generate files after a user custom fix; user can always use git revert if he doesn't like the change

  • can be used for simple or arbitrarily complex refactorings

  • can be used to unhide a symbol wo touching the sources; would keep working even if the file changes unlike with patchFile in nimscript via patchFile("stdlib", "asyncdispatch", "patches/replacement")

usage

nim c --patchast:pathto/module main

# module pathto/module
macro patchModule*(a: NimNode) =
  result = a
  doAssert a.kind == nnkModuleFile
  let mod = a[0]
  if mod.name.s != "ospaths": return
  ...

note

  • we could make instead take as input the un-parsed file, ie the filename, and parse ourselves? eg via staticRead
    maybe more flexible in some situations eg when parser introduces a fwd incompatible change and we need to patch a module to support it;
  • maybe related to polyfills?
  • can that be achieved via patchFile? in any case its useful to have std utilies to deal with patching files and file asts

potential use cases

would be interesting to see if it could be used for these:

links

@timotheecour timotheecour changed the title RFC: --patchast to patch all modules via AST xformations RFC: --patchast to patch all modules via AST transformations Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant