BGforgeNet / VScode-BGforge-MLS

BGforge MultiLanguage server
https://forums.bgforge.net/viewforum.php?f=35
Other
16 stars 5 forks source link

Weird behavior when using "" or ~~ #13

Closed 4Luke4 closed 5 years ago

4Luke4 commented 5 years ago

Let's consider the following example:

LAF DELETE_SCRIPT_BLOCK
STR_VAR
    script = ~GTSUM00~
    match = EVAL "RESPONSE #100[%WNL%%LNL%%MNL%]*END"
END

All the code that follows this line match = EVAL "RESPONSE #100[%WNL%%LNL%%MNL%]*END" is highlighted in yellow (as if a string delimiter is missing).

Why!?

Missing string delimiter ?
burner1024 commented 5 years ago

Quite clear when you look at it, LAF finds END and stops there, everything after that is separated, and the quotes open a new string. I'm not sure how to fix this, though. Need a clear indication that LAF invocation is over.

4Luke4 commented 5 years ago

I'm not sure how to fix this, though. Need a clear indication that LAF invocation is over.

Guess END should not qualify as the end of a function invocation if it's included in a string (i.e., if it's between two "" or ~~......)

burner1024 commented 5 years ago

Guess END should not qualify as the end of a function invocation if it's included in a string (i.e., if it's between two "" or ~~......)

Yeah, only that needs to be in regex terms.

burner1024 commented 5 years ago

Here's a try... works on the site but not in VScode for some reason. And I don't like how it's 428 steps, anyway.

4Luke4 commented 5 years ago

@burner1024

We must find a solution in any case because this issue is quite annoying IMHO...

burner1024 commented 5 years ago

I'm open to suggestions.

burner1024 commented 5 years ago

Probably can color it individually instead of trying to parse the entire invocation. It'll likely bite back at some time, but I don't really see a better option.

4Luke4 commented 5 years ago

Probably can color it individually instead of trying to parse the entire invocation. It'll likely bite back at some time, but I don't really see a better option.

Could you provide a screenshot? What do you mean by "It'll likely bite back at some time"?

burner1024 commented 5 years ago

It means that it'll likely break again in some other edge cases, and that won't be easily fixable. The core problem is that weidu treats all whitespace the same, while tmlanguage syntax doesn't (specifically, newlines).

4Luke4 commented 5 years ago

@burner1024

What about opening a feature request then?

burner1024 commented 5 years ago

About what?

4Luke4 commented 5 years ago

About what?

About treating newlines differently from the other whitespace characters (space, TAB and so forth...)

burner1024 commented 5 years ago

That's impossible, it'll break half the mods.

burner1024 commented 5 years ago

And just about the same can be accomplished by modders themselves.

burner1024 commented 5 years ago

I pushed a fix for this. Can you test if nothing else is broken?

4Luke4 commented 5 years ago

I pushed a fix for this. Can you test if nothing else is broken?

There's no available update for the extension.....

burner1024 commented 5 years ago

Yes, it's not released yet. To use current master, you just clone the repo and press F5 in VScode to run it.

4Luke4 commented 5 years ago

Yes, it's not released yet. To use current master, you just clone the repo and press F5 in VScode to run it.

What should I put under "Select Environment" after pressing F5?

burner1024 commented 5 years ago

Huh? Doesn't show that for me. "Launch client", I think.

4Luke4 commented 5 years ago

Huh? Doesn't show that for me. "Launch client", I think.

OK, I'm done.

Unfortunately, now issues occur when the name of a function is a %variable% (have a look at the attached screenshot)

LPF %variable%

To tell the truth, %variables% are not correctly identified regardless of your latest fix

%variables% incorrectly identified

LPF and RET should be highlighted in red.....

burner1024 commented 5 years ago

Function name as a variable?! What kind of witchery is this??

Please drop the snippets as text, so I could test.

4Luke4 commented 5 years ago

Function name as a variable?! What kind of witchery is this??

As you probably know, WeiDU's built-in functions (REPLACE_BCS_BLOCK, search & replace, etc...) are not very reliable when it comes to editing existing scripts.

As a result, DavidW wrote down a series of BCS-editing functions in order to solve that issue. You can find them here.

burner1024 commented 5 years ago

It was a rethorical question. Anyway, I still need the snippets.

4Luke4 commented 5 years ago

It was a rethorical question. Anyway, I still need the snippets.

What do you mean by "snippets"?

I've already sent you a link to the functions in question.....

burner1024 commented 5 years ago

The code that you're having problems with, as text.

4Luke4 commented 5 years ago

The code that you're having problems with, as text.

OK, here you go (do you have problems with copy & paste?)

Spoiler warning ``` DEFINE_ACTION_FUNCTION internal_script_block_master INT_VAR insert_above=0 only_once=0 recompile=1 replace=0 STR_VAR script="" patch="" patch_original="" match_function="" match="" match1="" match2="" match3="" match4="" match5="" internal_type="" internal_insert_data="" swap_out="" swap_out1="" swap_out2="" swap_out3="" swap_out4="" swap_out5="" swap_in="" swap_in1="" swap_in2="" swap_in3="" swap_in4="" swap_in5="" original_swap_out="" original_swap_out1="" original_swap_out2="" original_swap_out3="" original_swap_out4="" original_swap_out5="" original_swap_in="" original_swap_in1="" original_swap_in2="" original_swap_in3="" original_swap_in4="" original_swap_in5="" BEGIN COPY_EXISTING "%script%.bcs" "override" SET found_match=0 SPRINT new_script "" SET start=INDEX_BUFFER("CR") WHILE start>0 BEGIN SET end=INDEX_BUFFER ("RS%LNL%CR%LNL%") SET length=(end - start) + 6 READ_ASCII start data (length) DELETE_BYTES start length INNER_PATCH_SAVE data "SC%LNL%%data%SC%LNL%" BEGIN DECOMPILE_BCS_TO_BAF SET proceed=0 PATCH_IF (!found_match || !only_once) BEGIN PATCH_IF "%match_function%" STRING_COMPARE "" BEGIN READ_ASCII 0x0 data_temp (BUFFER_LENGTH) // we do this to avoid side-effects INNER_PATCH "%data_temp%" BEGIN LPF "%match_function%" RET v_func=value END END END ELSE BEGIN SET v_func=1 END PATCH_IF ( INDEX_BUFFER ("%match%")>=0 AND INDEX_BUFFER ("%match1%")>=0 AND INDEX_BUFFER ("%match2%")>=0 AND INDEX_BUFFER ("%match3%")>=0 AND INDEX_BUFFER ("%match4%")>=0 AND INDEX_BUFFER ("%match5%")>=0 AND v_func=1 ) BEGIN SET proceed=1 END END PATCH_IF proceed BEGIN SET found_match=1 PATCH_MATCH "%type%" WITH alter BEGIN PATCH_IF "%patch%" STRING_COMPARE "" BEGIN LPF "%patch%" END END PATCH_IF "%swap_out%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%swap_out%" "%swap_in%" END PATCH_IF "%swap_out1%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%swap_out1%" "%swap_in1%" END PATCH_IF "%swap_out2%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%swap_out2%" "%swap_in2%" END PATCH_IF "%swap_out3%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%swap_out3%" "%swap_in3%" END PATCH_IF "%swap_out4%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%swap_out4%" "%swap_in4%" END PATCH_IF "%swap_out5%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%swap_out5%" "%swap_in5%" END END clone BEGIN READ_ASCII 0x0 data2 (BUFFER_LENGTH) INNER_PATCH_SAVE data2 "%data2%" BEGIN PATCH_IF "%patch%" STRING_COMPARE "" BEGIN LPF "%patch%" END END PATCH_IF "%swap_out%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%swap_out%" "%swap_in%" END PATCH_IF "%swap_out1%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%swap_out1%" "%swap_in1%" END PATCH_IF "%swap_out2%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%swap_out2%" "%swap_in2%" END PATCH_IF "%swap_out3%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%swap_out3%" "%swap_in3%" END PATCH_IF "%swap_out4%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%swap_out4%" "%swap_in4%" END PATCH_IF "%swap_out5%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%swap_out5%" "%swap_in5%" END END PATCH_IF "%patch_original%" STRING_COMPARE "" BEGIN LPF "%patch_original%" END END PATCH_IF "%original_swap_out%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%original_swap_out%" "%original_swap_in%" END PATCH_IF "%original_swap_out1%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%original_swap_out1%" "%original_swap_in1%" END PATCH_IF "%original_swap_out2%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%original_swap_out2%" "%original_swap_in2%" END PATCH_IF "%original_swap_out3%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%original_swap_out3%" "%original_swap_in3%" END PATCH_IF "%original_swap_out4%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%original_swap_out4%" "%original_swap_in4%" END PATCH_IF "%original_swap_out5%" STRING_COMPARE "" BEGIN REPLACE_TEXTUALLY "%original_swap_out5%" "%original_swap_in5%" END PATCH_IF insert_above BEGIN SET insert_point=0 END ELSE BEGIN SET insert_point=BUFFER_LENGTH END INSERT_BYTES insert_point (STRING_LENGTH "%data2%") WRITE_ASCIIE insert_point "%data2%" END delete BEGIN DELETE_BYTES 0x0 BUFFER_LENGTH END insert BEGIN PATCH_IF replace BEGIN DELETE_BYTES 0x0 BUFFER_LENGTH END PATCH_IF insert_above BEGIN SET insert_point=0 END ELSE BEGIN SET insert_point=BUFFER_LENGTH END INSERT_BYTES insert_point (STRING_LENGTH "%internal_insert_data%") WRITE_ASCIIE insert_point "%internal_insert_data%" END DEFAULT PATCH_FAIL "internal error in ALTER_SCRIPT suite" END END END SPRINT new_script "%new_script%%data%" SET start=INDEX_BUFFER("CR") END DELETE_BYTES 0x0 BUFFER_LENGTH INNER_PATCH_SAVE new_script "%new_script%" BEGIN PATCH_IF recompile BEGIN COMPILE_BAF_TO_BCS END SET new_length=BUFFER_LENGTH END INSERT_BYTES 0x0 new_length WRITE_ASCIIE 0x0 "%new_script%" BUT_ONLY END ```
burner1024 commented 5 years ago

I just need a minimal reproducible example: screenshot and text. That saves time and reduces amount of miscommunication errors.

Pushed an update, how about now? (please test) Captura de pantalla de 2019-09-14 19-35-45

4Luke4 commented 5 years ago

I just need a minimal reproducible example: screenshot and text. That saves time and reduces amount of miscommunication errors.

Got it.

So, now there are problems with variable identifiers when launching a function:

After your update – highlighted in white

Next update

v1.0.9 – highlighted in orange

v1 0 9
burner1024 commented 5 years ago

What about now?

4Luke4 commented 5 years ago

What about now?

Nope, sorry....

Broken – again
burner1024 commented 5 years ago

Screenshot and text, please.

4Luke4 commented 5 years ago

Screenshot and text, please.

Schermata 2019-09-16 alle 16 14 03
burner1024 commented 5 years ago

Text, please.

4Luke4 commented 5 years ago

Text, please.

LAF DELETE_SCRIPT_BLOCK
STR_VAR
    script = ~GTSUM00~
    match = EVAL "RESPONSE #100[%WNL%%LNL%%MNL%]*END"
END

ACTION_IF   !FILE_EXISTS_IN_GAME    ~GTGOBRSU.cre~  BEGIN
    CREATE  "CRE"   "GTGOBRSU"
        SAY NAME1   @1
        SAY NAME2   @1
        WRITE_LONG  0x0010  BIT1    // No corpse
        WRITE_SHORT 0x0024  30  // Current HP
        WRITE_SHORT 0x0026  30  // Maximum HP
        WRITE_LONG  0x0028  IDS_OF_SYMBOL   (~ANIMATE~ ~GOBLIN_BOW_ELITE~)
END
burner1024 commented 5 years ago

And now?

4Luke4 commented 5 years ago

And now?

Everything seems to be OK now but a minor issue: you may wanna use different colors for tra references (e.g. @3) and %variables% (or vars declaration)....

Different colors
burner1024 commented 5 years ago

There are only so many colors. If you have a specific suggestion, I'm listening. Theme editor linked in the topic will help you get an idea about what's possible.

burner1024 commented 5 years ago

If there are no suggestions, I guess I'm closing this.

4Luke4 commented 5 years ago

If there are no suggestions, I guess I'm closing this.

OK, feel free to close it, I'll think about that for the next update....

Before I forget, there's a minor issue with comments and DEFINE_PATCH_FUNCTION (or DEFINE_ACTION_FUNCTION)

Schermata 2019-09-19 alle 16 28 12
burner1024 commented 5 years ago

Fixed that as well. New release will be up shortly.

4Luke4 commented 5 years ago

Fixed that as well. New release will be up shortly.

Sorry, don't forget about numerical constants (have a look at the same screenshot: they should be highlighted in purple....)

burner1024 commented 5 years ago

damn, it's back to square one