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

feat: separate field + node to access strings content #103

Closed
wants to merge 2 commits into from

Conversation

ahlinc
Copy link
Contributor

@ahlinc ahlinc commented Sep 22, 2021

This PR is a proposal, but I'm not sure that it's worth to merge it.

Resolves #101

@verhovsky
Copy link
Collaborator

I appreciate it but it's more complicated than just removing the quotes, especially for ANSI-C quoted strings. You have to also remove stuff inside the string, like escaped quotes (replacing a backslash and a quote with just the quote) and newlines (which are removed). You can see how I ended up doing it here

https://github.com/NickCarneiro/curlconverter/blob/265a9372c6f9d361c820daba33e3b4b3906685bb/util.js#L557-L643

I especially spent a lot of time getting the ANSI-C quoted string parsing correct for this PR (which is ultimately probably not going anywhere...) yargs/yargs-parser#366

@ahlinc
Copy link
Contributor Author

ahlinc commented Sep 22, 2021

@verhovsky Got it, thanks for the link to the code. Such processing isn't possible in tree-sitter because tree-sitter doesn't store any resulting values in its nodes. It's AST nodes are just references to the concrete places in a source code. In sight of this the #101 issue I suppose can be closed.
P.S: It's possible to write some sort of string parsing on tree-sitter but only with possibility to skip some input parts and gather resulting value by concatenating in a buffer values from the nodes.

@ahlinc ahlinc closed this Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get the value of a string literal
2 participants