You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--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:
The text was updated successfully, but these errors were encountered:
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
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 macrosnot 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
innimscript
viapatchFile("stdlib", "asyncdispatch", "patches/replacement")
usage
nim c --patchast:pathto/module main
note
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;
patchFile
? in any case its useful to have std utilies to deal with patching files and file astspotential use cases
would be interesting to see if it could be used for these:
import foo {.all.}
nim-lang/Nim#11865import foo {.privateImport.}
exec("nim c")
honor `-d:nimExe:path nimscript: makeexec("nim c")
honor-d:nimExe:path
nim-lang/RFCs#273links
The text was updated successfully, but these errors were encountered: