Skip to content

Add support for newline separated SNBTs#1

Open
Taskeren wants to merge 6 commits into
HMCL-dev:mainfrom
Taskeren:newline-snbt
Open

Add support for newline separated SNBTs#1
Taskeren wants to merge 6 commits into
HMCL-dev:mainfrom
Taskeren:newline-snbt

Conversation

@Taskeren
Copy link
Copy Markdown

@Taskeren Taskeren commented Apr 7, 2026

FTB-Library splits the compounds and lists with \n, and this PR adds the support for it.

New-lines will only be tokenized when allowNewLineAsSeparator = true, and in the context of reading compounds and lists.

applied_energistics.snbt is obtained from the modpack Star Technology, which is licensed under MIT. Removed

@Glavo

Copy link
Copy Markdown
Member

@Glavo Glavo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本审查建议由 GPT-5 生成


已将具体审查建议标注在对应代码行。

Comment thread src/main/java/org/glavo/nbt/internal/snbt/SNBTParser.java
Comment thread src/main/java/org/glavo/nbt/io/SNBTCodec.java Outdated
Comment thread src/main/java/org/glavo/nbt/io/SNBTCodec.java
@Taskeren Taskeren requested a review from Glavo June 2, 2026 19:28
Copy link
Copy Markdown
Member

@Glavo Glavo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本审查建议由 GPT-5 生成


已将具体审查建议标注在对应代码行。

Token peekToken(boolean tokenizeNewLine) {
// nullability of lookaheadNewLineParam is same to lookahead.
assert (lookahead == null) == (lookaheadNewLineParam == null);
if (lookahead == null || tokenizeNewLine != lookaheadNewLineParam) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本审查建议由 GPT-5 生成


[P1] peekToken(boolean)tokenizeNewLine 参数变化时直接重新调用 readNextToken(tokenizeNewLine),但此时 cursor 已经被上一次 peek 推进了,不能重新读取同一个 token。当前新增测试里的 str_dict 就会触发:解析 a: foo\nb: bar 时,nextTag() 为了检查 foo(...) 调用 peekToken(false),跳过换行并把 b 缓存在 lookahead,同时 cursor 已在 b 后面;随后 compound separator 调用 peekToken(true),这段代码从 b 后继续读,得到的是 COLON,最终抛出 Unexpected token: COLON。结果是启用 allowNewLineAsSeparator 后,包含未加引号字符串值的 newline-separated SNBT 仍然无法读取,并且 PR 新增的 SNBTCodecTest.testNewLineSeparatedSNBT 应该会失败。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants