Parsing 在Scala combinator解析器中忽略C样式的注释

Parsing 在Scala combinator解析器中忽略C样式的注释,parsing,scala,parser-combinators,Parsing,Scala,Parser Combinators,让解析器尊重(忽略)C风格注释的最简单方法是什么。我对这两种注释类型都感兴趣,不过也欢迎只针对一种类型的解决方案 我目前只是在扩展JavaTokenParser。只要不嵌套注释,就可以使用简单的正则表达式。将其放在空格中: scala> object T extends JavaTokenParsers { | protected override val whiteSpace = """(\s|//.*|(?m)/\*(\*(?!/)|[^*])*\*/)+""".r

让解析器尊重(忽略)C风格注释的最简单方法是什么。我对这两种注释类型都感兴趣,不过也欢迎只针对一种类型的解决方案


我目前只是在扩展JavaTokenParser。

只要不嵌套注释,就可以使用简单的正则表达式。将其放在
空格中

scala> object T extends JavaTokenParsers {
     |    protected override val whiteSpace = """(\s|//.*|(?m)/\*(\*(?!/)|[^*])*\*/)+""".r
     |    def simpleParser = ident+
     | }
defined module T

scala> val testString = """ident // comment to the end of line
     | another ident /* start comment
     | end comment */ final ident"""
testString: java.lang.String = 
ident // comment to the end of line
another ident /* start comment
end comment */ final ident

scala> T.parseAll(T.simpleParser, testString)
res0: T.ParseResult[List[String]] = [3.27] parsed: List(ident, another, ident, final, ident)

您正在使用哪个解析器库?