我写了一个 pegjs 语法,它可以解析任何类型的 js/c 风格的注释。但是,它并不能很好地工作,因为我只设法捕获了评论本身,而忽略了其他所有内容。我应该如何更改此语法以仅从任何类型的输入中解析注释?
语法:
Start
= Comment
Character
= .
Comment
= MultiLineComment
/ SingleLineComment
LineTerminator
= [\n\r\u2028\u2029]
MultiLineComment
= "/*" (!"*/" Character)* "*/"
MultiLineCommentNoLineTerminator
= "/*" (!("*/" / LineTerminator) Character)* "*/"
SingleLineComment
= "//" (!LineTerminator Character)*
输入:
/**
* Trending Content
* Returns visible videos that have the largest view percentage increase over
* the time period.
*/
Other text here
错误
Line 5, column 4: Expected end of input but "\n" found.