EliotVU / UnrealScript-Language-Service

Bringing a work-in-progress intelliSense to ye olde UnrealScript :)
MIT License
52 stars 11 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 5 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 5 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.

EliotVU commented 2 weeks ago

@tuokri Yes, or even just displace the workspace folders with macro code with the intermediate code; The only problem with this solution would be for modders that need to mod the stock scripts.

EliotVU commented 2 weeks ago

I have been working on and off on a new approach to tackle this issue in another branch, but nothing complete yet (ANTLR's approach really likes to interfere with most solutions)

EliotVU commented 1 week ago

I have worked through the road blocking issues I was having with the re-worked preprocessor, see commit 4aefe32d3e22b30adacf96d40475743304e61316

It can now preprocess:

However this is not yet production ready, there's still work to be done in regards to: