-
Notifications
You must be signed in to change notification settings - Fork 22
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: visitor #53
base: master
Are you sure you want to change the base?
feat: visitor #53
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
visitor 里的接口可以严谨一点参考下其他第三方库,比如 https://pypi.org/project/json-visitor/ ?
include/parser/parser.hpp
Outdated
private: | ||
parsing_iter_t _cur; | ||
parsing_iter_t _end; | ||
|
||
parse_visitor<string_t>* _vis; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
初始化
} | ||
else { | ||
return invalid_value<string_t>(); | ||
} | ||
} | ||
|
||
if constexpr (has_visitor) { | ||
_vis->value(basic_value<string_t>(), cur_pos, _pos, _path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
指针判空,还有后面的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
就是因为配置了has_visitor的时候强制传入了visitor,所以直接不判空了,从前面的入口处理了
include/parser/parser.hpp
Outdated
cur_pos = _pos; | ||
} | ||
else { | ||
std::ignore = cur_pos; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不加有 warning 吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是可以不改原来的函数,而是在外面在包一层 has_visitor=true 特化的 parse_string,这些结构就都放新的里面
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不太确定,不过直接if constexpr简洁一点,特化实在是有点啰嗦
{ | ||
if constexpr (has_visitor) { | ||
_pos.offset++; | ||
if (*_cur == '\n') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_cur != _end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些移动逻辑是直接替换原来的_cur++,原来的各个地方你不是都写了判断的吗(
sample/sample.cpp
Outdated
@@ -269,6 +341,8 @@ void parsing() | |||
// it's a std::optional<json::value> | |||
auto ret = json::parse(content); | |||
|
|||
auto another = json::parse(content, new my_visitor()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sample 和文档保持同步,不放不重要的功能。这些都放 test 里。另外这个 new 泄露了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fuzzing test 也加一下
include/parser/parser.hpp
Outdated
template <typename string_t = default_string_t> | ||
struct parse_visitor | ||
{ | ||
using json_path = std::vector<std::variant<string_t, size_t>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是干嘛的?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
昂
所以visitor是用来干嘛的 |
|
430d0a9
to
676cb37
Compare
No description provided.