解析具有未知数量嵌套语句的日志文件
我有一个以下形式的日志文件:
begin; x1
begin; y1
end; y1
begin; z1
begin; z2
end; z2
end; z1
end;x1
我希望将此文件解析为如下所示的数据结构:
x1 >
y1
z1 >
z2
因此 x1 事件包含 y1 & z1 事件,并且 z1 事件包含 z2 事件。
在这种情况下是否有可能使用的标准算法?
我想也许递归可以通过在每个“开始”语句上分支来正确解析所有子事件来帮助我。如有任何建议,我们将不胜感激。
编辑: 最终目标是在分层 ListView 类型组件内的 GUI 上显示事件。我希望通过能够像这样显示日志文件,可以更好地可视化系统内的事件序列。
I have a log file in the form:
begin; x1
begin; y1
end; y1
begin; z1
begin; z2
end; z2
end; z1
end;x1
I am looking to parse this file into a data structure that could look like the following:
x1 >
y1
z1 >
z2
so the x1 event contains the y1 & z1 events and the z1 event contains the z2 event.
Is there a standard algorithm that might be of use in this situation?
I'm thinking perhaps recursion might be able to help me here by branching on each 'begin' statement to correctly parse all sub-events. Any suggestions would be gratefully received.
Edit:
The ultimate goal for this will be to display the events on a GUI within a hierarchical ListView-type component. I am hoping that by being able to display the log files like this it will be possible to better visualize sequence of events within my system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会选择递归下降解析器。
等等。
这里我们有
I would go for a recursive descent parser.
etc.
Here we have
为什么不将其转换为 XML 作为使用数据的最简单方法:
why not convert it to XML as the easiest way to use the data: