Pairify – how to match balanced string pairs

I’m now actively working on a VSCode extension. I started it as a theme but then decided to add some more features. Like for example a tin line on the left side of the editor marking the current function scope. In order to do that I had to analyze the current file’s code and find the lines that are included in that scope. The obvious approach will be to translate the code to AST and then traverse the tree finding the information that I need. This however will require the usage of a language server which now I don’t want to deal with. So I decided to explore a brute force approach. Looping over the string characters and finding balanced matches. I quickly wrapped it into a library. I called it Pairify. It consumes text and returns an array of pairs. This blog post will show you how it works.


This content originally appeared on Krasimir Tsonev - blog and was authored by Krasimir Tsonev - blog

I'm now actively working on a VSCode extension. I started it as a theme but then decided to add some more features. Like for example a tin line on the left side of the editor marking the current function scope. In order to do that I had to analyze the current file's code and find the lines that are included in that scope. The obvious approach will be to translate the code to AST and then traverse the tree finding the information that I need. This however will require the usage of a language server which now I don't want to deal with. So I decided to explore a brute force approach. Looping over the string characters and finding balanced matches. I quickly wrapped it into a library. I called it Pairify. It consumes text and returns an array of pairs. This blog post will show you how it works.


This content originally appeared on Krasimir Tsonev - blog and was authored by Krasimir Tsonev - blog


Print Share Comment Cite Upload Translate Updates
APA

Krasimir Tsonev - blog | Sciencx (2021-02-07T21:52:55+00:00) Pairify – how to match balanced string pairs. Retrieved from https://www.scien.cx/2021/02/07/pairify-how-to-match-balanced-string-pairs/

MLA
" » Pairify – how to match balanced string pairs." Krasimir Tsonev - blog | Sciencx - Sunday February 7, 2021, https://www.scien.cx/2021/02/07/pairify-how-to-match-balanced-string-pairs/
HARVARD
Krasimir Tsonev - blog | Sciencx Sunday February 7, 2021 » Pairify – how to match balanced string pairs., viewed ,<https://www.scien.cx/2021/02/07/pairify-how-to-match-balanced-string-pairs/>
VANCOUVER
Krasimir Tsonev - blog | Sciencx - » Pairify – how to match balanced string pairs. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/07/pairify-how-to-match-balanced-string-pairs/
CHICAGO
" » Pairify – how to match balanced string pairs." Krasimir Tsonev - blog | Sciencx - Accessed . https://www.scien.cx/2021/02/07/pairify-how-to-match-balanced-string-pairs/
IEEE
" » Pairify – how to match balanced string pairs." Krasimir Tsonev - blog | Sciencx [Online]. Available: https://www.scien.cx/2021/02/07/pairify-how-to-match-balanced-string-pairs/. [Accessed: ]
rf:citation
» Pairify – how to match balanced string pairs | Krasimir Tsonev - blog | Sciencx | https://www.scien.cx/2021/02/07/pairify-how-to-match-balanced-string-pairs/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.