javacc 跳过注释但需要保留有用的注释
我需要使用 javaCC 来解析数据文件,例如:
//这是要跳过的注释
//这也是要跳过的注释
//学生表
开始:
标题:( 1 //名称 2 //年龄 ) { "约翰" 21 } { "杰克" "22" }
#结束
//下面是教师表,这一行也是注释跳过
//教师表
开始:
标题:( 1 //名称 2 //年龄 3 //班级 ) { "Eric" 31 "英语" } { "Jasph" "32" "历史" }
#结束
这里我需要从“student”和“teacher”表中获取数据,还有其他一些表格的格式如上。从“student”表导出的数据是:
Table Name: student
name age
John 21
Jack 22
也就是说我需要跳过注释,例如:“//这也是要跳过的注释”
,但需要保留标记,例如:“//学生表”
、“//教师表”
、“//姓名”
、“//年龄”
等。写这样的SKIP表达式?谢谢。
I need to use javaCC to parse a data file like:
//This is comment to skip
//This is also comment to skip
//student Table
Begin:
header:( 1 //name
2 //age ) { "John" 21 } { "Jack" "22" }#End
//The following is teacher table, this line is also comment to skip
//Teacher Table
Begin:
header:( 1 //name
2 //age 3 //class ) { "Eric" 31 "English" } { "Jasph" "32" "History" }#End
Here I need to fetch data from "student" and "teacher" tables, there are also some other tables formatted like above. Data exported from "student" table is:
Table Name: student
name age
John 21
Jack 22
That is I need to skip comments like: "//This is also comment to skip"
, but need to keep the tokens like: "//student Table"
, "//Teacher Table"
, "//name"
, "//age"
etc. How to write such SKIP expression? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有点晚了,但你可能看错了。
当然,在您的情况下, // 并不是真正的注释,它是您正在解析的语法的一部分。只是有时 // 后面的位是无关紧要的。
我会解析这些注释并决定在 Java 代码中丢弃哪些注释。
Slightly late, but you might be looking at it wrong.
Surely in your case, // isn't really a comment, it is part of the syntax you are parsing. It just happens that sometimes the bit following // is irrelevant.
I would parse the comments and decide which ones to discard in your Java code.