出了什么问题:“值解析器不是 scala.util.parsing.combinator 包的成员”?
我收到了上述奇怪的错误消息,我不明白“值解析器不是包 scala.util.parsing.combinator 的成员”。
我正在尝试通过逐步编写 C 解析器来学习解析器组合器。我从 token 开始,所以我有课程:
import util.parsing.combinator.JavaTokenParsers
object CeeParser extends JavaTokenParsers {
def token: Parser[CeeExpr] = ident ^^ (x => Token(x))
}
abstract class CeeExpr
case class Token(name: String) extends CeeExpr
这是我能做到的最简单的。
下面的代码工作正常,但如果我取消注释行,我会收到上面给出的错误消息:
object Play {
def main(args: Array[String]) {
//val parser: _root_.scala.util.parsing.combinator.Parsers.Parser[CeeExpr] CeeParser.token
val x = CeeParser.token
print(x)
}
}
如果我的设置有问题,我通过 intellij 的 scala-plugin 使用 scala 2.7.6。任何人都可以阐明这一点吗?该消息是错误的,Parsers
是 scala.util.parsing.combinator
的成员。
--- 跟进
此人 http://www.scala-lang.org/node/ 5475似乎也有同样的问题,但我不明白他给出的答案。谁能解释一下吗?
I've got the above odd error message that I don't understand "value Parsers is not a member of package scala.util.parsing.combinator".
I'm trying to learn Parser combinators by writing a C parser step by step. I started at token, so I have the classes:
import util.parsing.combinator.JavaTokenParsers
object CeeParser extends JavaTokenParsers {
def token: Parser[CeeExpr] = ident ^^ (x => Token(x))
}
abstract class CeeExpr
case class Token(name: String) extends CeeExpr
This is as simple as I could make it.
The code below works fine, but if I uncomment the commented line I get the error message given above:
object Play {
def main(args: Array[String]) {
//val parser: _root_.scala.util.parsing.combinator.Parsers.Parser[CeeExpr] CeeParser.token
val x = CeeParser.token
print(x)
}
}
In case it is a problem with my setup, I'm using scala 2.7.6 via the scala-plugin for intellij. Can anyone shed any light on this? The message is wrong, Parsers
is a member of scala.util.parsing.combinator
.
--- Follow-up
This person http://www.scala-lang.org/node/5475 seems to have the same problem, but I don't understand the answer he was given. Can anyone explain it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题在于
Parser
是Parsers
的子类,因此引用它的正确方法是从 Parser< 的实例 /em>。也就是说,CeeParser.Parser
与任何其他x.Parser
不同。引用
CeeParser.token
类型的正确方法是CeeParser.Parser
。The problem is that
Parser
is a subclass ofParsers
, so the proper way to refer to it is from an instance of Parser. That is,CeeParser.Parser
is different from any otherx.Parser
.The correct way to refer to the type of
CeeParser.token
isCeeParser.Parser
.问题是 Parsers 不是包或类,而是一个特征,因此无法导入其成员。您需要从扩展特征的特定类中导入。
在本例中,特定类是 CeeParser,因此
val
的类型应该是 CeeParser.Parser[CeeExpr]:The issue is that Parsers is not a package or class, is is a trait, so its members can't be imported. You need to import from the specific class extending the trait.
In this case the specific class is CeeParser so the type of
val
should be CeeParser.Parser[CeeExpr]: