Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use antlr4 to parse bbcode #684

Merged
merged 9 commits into from
Feb 2, 2025
Merged

Conversation

ErBWs
Copy link
Contributor

@ErBWs ErBWs commented Feb 1, 2025

解析为 AST 树解析的挺好的,但我不知道怎么继续处理了,发上来讨论一下(

image image image
import 'package:flutter/material.dart';
import 'bbcode/bbcode.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('BBCode Parser')),
        body: Card(
          color: Theme.of(context).colorScheme.secondaryContainer,
          child: const Padding(
            padding: EdgeInsets.all(8.0),
            child: Padding(
              padding: EdgeInsets.all(16),
              child: BBCodeWidget(
                bbcode:
                    '[url=https://bangumi.tv/blog/348736]测试链接[/url][url]https://bangumi.tv/blog/348736[/url][quote][b]用户[/b]测试表情(bgm35)[/quote]测试换行\t\n测试特殊符号[]()测试字符表情(TAT)哈哈哈哈[img]https://p.inari.site/guest/25-01/22/67907598b3a74.jpg[/img]',
              ),
            ),
          ),
        ),
      ),
    );
  }
}

@Predidit
Copy link
Owner

Predidit commented Feb 1, 2025

之前有人提到过 https://github.com/realth000/flutter_bbcode_editor

这个库似乎是基于 AST 语法树,但是我没有实际看过

我现在正在尝试实现追番同步,这里有相当多的问题

@ErBWs
Copy link
Contributor Author

ErBWs commented Feb 1, 2025

可以用 squash merge 吗?现在有点 cherry-pick 地狱了(
image

@ErBWs
Copy link
Contributor Author

ErBWs commented Feb 1, 2025

看起来还行,不过总感觉这个做法非常丑陋
image

@Predidit
Copy link
Owner

Predidit commented Feb 1, 2025

我们确实应该压缩单个PR中的提交。

虽然这个PR中目标是很优雅的,但是实际实现时引入了大量的模板代码,所以看上去似乎不是那么的好。

我在想将其拆分出去作为独立的包怎么样。

@ErBWs
Copy link
Contributor Author

ErBWs commented Feb 1, 2025

可以拆分,不过这个通用性有点太低了

虽然是 bbcode,但是是专为 bangumi 评论设计的 bbcode 解析

我可以删掉点模板代码,比如 Visitor 没用到,一开始传上来是因为没有头绪就勾选全部生成了

Listener 我看看怎么删,这里是为了其他人也可以看懂解析器是怎么实现的,所以我还写了个 README

@ErBWs
Copy link
Contributor Author

ErBWs commented Feb 2, 2025

应该差不多了

image image

@ErBWs ErBWs marked this pull request as ready for review February 2, 2025 09:27
@Predidit
Copy link
Owner

Predidit commented Feb 2, 2025

这可真是一个大工程

我没有用过这个库,相关实现并不是很能看懂。让我们在 CI 完成后简单测试一下就合并吧

有问题的话再修

@Predidit
Copy link
Owner

Predidit commented Feb 2, 2025

看上去之前的 Utils.richTextParser 相关实现已经不再使用,我们不移除它们吗

@Predidit
Copy link
Owner

Predidit commented Feb 2, 2025

我意识到这部分仍然在吐槽箱中使用

是什么阻止了我们在吐槽箱中使用新的解析器

@ErBWs
Copy link
Contributor Author

ErBWs commented Feb 2, 2025

看上去之前的 Utils.richTextParser 相关实现已经不再使用,我们不移除它们吗

忘记删了

我意识到这部分仍然在吐槽箱中使用

吐槽箱应该没在使用,吐槽箱获取的文字是普通的 String 不是 bbcode

@ErBWs ErBWs changed the title use antlr4 to parse bbcode feat: use antlr4 to parse bbcode Feb 2, 2025
@Predidit Predidit merged commit f888506 into Predidit:main Feb 2, 2025
6 checks passed
@Predidit
Copy link
Owner

Predidit commented Feb 2, 2025

我们应该会在今晚发布新的版本

我们已经按照 F-Droid 的要求在第一次启动时提供了更新来源选择,应该可以继续 F-Droid 的上架

@ErBWs ErBWs deleted the feat-antlr4-bbcode branch February 2, 2025 10:30
ErBWs added a commit to ErBWs/Kazumi that referenced this pull request Feb 2, 2025
* add BBCode.g4

* Rename bbcode.g4 to BBCode.g4

* try

* basic

* delete useless files

* fix

* Done

* dart format

* remove old parser

(cherry picked from commit f888506)
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