joernio / joern

Open-source code analysis platform for C/C++/Java/Binary/Javascript/Python/Kotlin based on code property graphs. Discord https://discord.gg/vv4MH284Hc
https://joern.io/
Apache License 2.0
2k stars 269 forks source link

[ruby] HereDoc in Function Argument #4600

Open DavidBakerEffendi opened 4 months ago

DavidBakerEffendi commented 4 months ago

HereDoc in a function argument is interesting, as in this case, the heredoc only starts from the next line onwards, and is meant to be inserted in the argument index where the first heredoc token starts.

def foo(arg)
  bar(arg, <<-SOME_HEREDOC, arg + 1)
   inside here doc
  SOME_HEREDOC
end

Right now, the above causes a syntax issue which will fail parsing for that file.

xavierpinho commented 4 months ago

At one point I had something barely working using the following approach:

The thing is this isn't the whole story, though: they could be nested, interpolated, have methods directly applied to them, etc and it's all these use-cases that make this more time-consuming than it should otherwise be. I still reckon that the sanest way to go about this is to have a 2nd lexer pass though, hence why I'm sharing this somewhat positive experiment here.