Tnze / snbt-vscode

Support SNBT(Stringified Named Binary Tag) format of Minecraft.
7 stars 3 forks source link

[Feat Request] An option to make `\n` work as delimter #4

Open ZZZank opened 7 months ago

ZZZank commented 7 months ago

FTB Quests currently uses an unusual SNBT format, where \n, instead of ,, is used as delimiter. So the syntax-highlighter will interpret such file as:

image
Tnze commented 7 months ago

What is FTB Quests?

ZZZank commented 7 months ago

It's a mod for writing quests. https://www.curseforge.com/minecraft/mc-mods/ftb-quests-forge

I opened an issue suggesting them to switch to standard SNBT not long ago, but no reply yet.

Subilan commented 4 months ago

Would like to request the same. Configuring FTB Ranks & FTB Essentials now. They are still using \n as delimeter, so the syntax highlighing is still broken. I cannot find an alternative plugin of VSC for SNBT highlighting either.

Tnze commented 4 months ago

👉👈

ZZZank commented 4 months ago

I tried to add \n to delimiters myself, and it turns out to be incredibly simple. Syntax highlighting for non-standard SNBT can be on pair with the one for standard SNBT with only one change. See https://github.com/ZZZank/snbt-vscode/commit/c8a373fc268ab76ed5af30524ae302dd046442d1

there's a real-world example, showing syntax highlighting for an SNBT file that uses both , and \n as delimiter: image

Subilan commented 4 months ago

@ZZZank Awesome. Seems like you find where the regex about delimiter at. But is it real SNBT can use two different delimiters at the same time? Is there any plan to make a pull request of your commit on the author's branch so that a new version of the extension can be released?

Tnze commented 4 months ago

@ZZZank Would you like to make a PR for this feature?

And I think it needs to be controlled by an option, which is disabled by default.

ZZZank commented 4 months ago

But is it real SNBT can use two different delimiters at the same time?

This is apparently not standard, but some popular SNBT parsers (like the one embedded in FTB Library) actually do support using \n as delimiter, because no one in the right mind will intentionally split a string or number using \n

And I think it needs to be controlled by an option, which is disabled by default.

Indeed better than always accepting \n, but I'm not sure if it can be implemented, I've not yet found a way of doing so.

Subilan commented 4 months ago

I think an option is not so necessary, as we can already use the two delimiters freely now. But there still can be a boolean option to determine which of , and \n should be used as delimiter, which avoids hybrid use of them.

These two is quite enough (and thanks to FTB we've got two now) and further customization of delimiter should be avoided as we all don't want to see SNBT to be the unique file format allowing using random delimiter.

Tnze commented 4 months ago

Indeed better than always accepting \n, but I'm not sure if it can be implemented, I've not yet found a way of doing so.

As a reference, vscode support a format named "JSON (with comments)" as a supplement of standard JSON. I believe the non-standard NBT should be regard as language other than the standard one.

Subilan commented 4 months ago

I believe the non-standard NBT should be regard as language other than the standard one.

At present I think SNBT is too narrowly used to be split into two languages. While FTB team's usage of SNBT is not considered standard, since their mods are somehow widely used among mod servers, I think their standard should be accepted temporarily so that configuring FTB mods won't be colorless. As @ZZZank said they hadn't replied to the request of changing the delimiter to , so...

Tnze commented 4 months ago

I think their standard should be accepted temporarily so that configuring FTB mods won't be colorless. As @ZZZank said they hadn't replied to the request of changing the delimiter to , so...

But on the other hand, if we accept both , and \n, someone who is working on standard SNBT will be unable to know they are forgetting to add , as the delimiter by visualization effects.

Subilan commented 4 months ago

But on the other hand, if we accept both , and \n, someone who is working on standard SNBT will be unable to know they are forgetting to add , as the delimiter by visualization effects.

Yes, that's right. In this case, adding an option to avoid hybrid use of two delimiters becomes necessary. See my previous reply:

But there still can be a boolean option to determine which of , and \n should be used as delimiter, which avoids hybrid use of them.

Tnze commented 4 months ago

Yes, that's right. In this case, adding an option to avoid hybrid use of two delimiters becomes necessary.

We can't implement this due to current technical limitations. Unless we split it into two languages. Or we write a language server instead.

I think provide a second language in the extension is the best solution.

ZZZank commented 1 month ago

Hi again, I've implemented seperate supports for Vanilla and FTB style SNBT support in #5