EliotVU / UnrealScript-Language-Service

Bringing a work-in-progress intelliSense to ye olde UnrealScript :)
MIT License
48 stars 9 forks source link

Preprocessor macros #10

Open EliotVU opened 5 years ago

EliotVU commented 5 years ago

The usage of macros can lead to severe parsing and indexing issues, like the following code:

return ( `TimeSince( LastRenderTime ) < 0.3 );

The usage of `TimeSince here will tell the lexer that this is a PP command, when this is occurred the input will be thrown out thus leaving the parser with:

return ( < 0.3 );

Which leads to even bigger issues down the road, so as the end block of a method not being terminated.

One workaround for this issue could be to safely parse binary operators that are missing an expression on the left or right, however due the nature of UnrealScript allowance of custom defined pre and post operators, "< 0.3" could in theory be a post operator! Thus it cannot be assumed to be an incomplete binary operator (albeit it would be totally unexpected for "<" symbol, that cannot be said of other symbols).

The proper solution would be not to skip any PP commands and instead fully parse and evaluate any macro prior to parsing the document, this is however not an easy task!

Xymanek commented 4 years ago

Status of marcos in 0.4.3:

Parsing still fails. Sometimes it causes just a small error: image

Sometimes a much bigger problem: image The "problems" window is full of (ANTLR Node Error) ;

EliotVU commented 4 years ago

Yeah, macros with params are not yet supported, neither are macro symbols being included yet from the global.uci or `include calls.

tuokri commented 1 year ago

I was thinking, would it be possible to use the output from make -intermediate to improve the plugin's macro parsing? Whenever a macro with params occurs, fetch the correct code from the intermediate output, instead of just throwing out the macro. Though I have no idea whether it's possible to keep the source code and intermediate output in sync to be able to programmatically track which parts of the intermediate output are preprocessed macros and which parts correspond to the unprocessed source directly.