TIC-80
TIC-80 copied to clipboard
Improve outline function detection
As it stands, the outline uses a static string find to start looking for potential inclusions, e.g.:
https://github.com/nesbox/TIC-80/blob/681f18c0f477e7d7b5b4fea4e330c44028afd34c/src/api/lua.c#L1735-L1737
This is a bit too simple since, for example, it detects function foo()
but not function foo ()
or foo = function()
, which are still valid Lua.
There's similar cases for other supported languages (#1876).
I don't know if regex or the equivalent is a nightmare in C, or if it's out of scope of this project, but it'd help a lot to have some sort of pattern matching to know what to add to the outline, instead of manually checking each character. That'd also be a step towards including things other than functions for languages such as MoonScript or Squirrel, and generally could go a long way in making it much more useful.
First we'd need a cross-platform regex library that works on all supported platform... you'd have POSIX regex in Unix/Linux, but I don't think that helps us in windows and other simpler compile environs?
The basicest most bog standard google search gave gave me tiny-regex-c, which seems portable and featureful enough. But it warrants careful consideration, especially since the paper it came from is available, so it'd be possible to make a smaller version tailored to this issue's needs.
If the regex you have in mind won't change over the course of the program, you can implement them in c using a goto state machine.
https://rubber-duck-typing.com/posts/2017-04-26-goto-the-marvelous.html
maybe I will try to do it for the lua outline function later as an example
That's related to #2237