Skip to content

The right approach to use slang as a formatter #828

Answered by MikePopoloski
suzizecat asked this question in Q&A
Discussion options

You must be logged in to vote

You have the right idea. It's going to be clunky because the memory management is important, but once you have it figured out you can wrap it all up in some nice helper methods and make it look pretty for your actual rewriter logic so I wouldn't worry about it too much.

Some thoughts: if the string you're adding is an actual string literal (in this case " !=") then you don't need to allocate memory for it; string literals live in a fixed location in memory for the lifetime of the program so you can just pass a pointer to it without issue. You only need the alloc and copy for dynamically constructed strings.

Also you need to be careful about this line:

work->modifiers = TokenList(tok_list);

Replies: 3 comments 13 replies

Comment options

You must be logged in to vote
4 replies
@suzizecat
Comment options

@MikePopoloski
Comment options

@suzizecat
Comment options

@MikePopoloski
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
9 replies
@suzizecat
Comment options

@MikePopoloski
Comment options

@suzizecat
Comment options

@MikePopoloski
Comment options

Answer selected by suzizecat
@suzizecat
Comment options

@suzizecat
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants