出了什么问题:“值解析器不是 scala.util.parsing.combinator 包的成员”?

发布于 2024-08-26 23:48:47 字数 980 浏览 4 评论 0原文

我收到了上述奇怪的错误消息,我不明白“值解析器不是包 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。任何人都可以阐明这一点吗?该消息是错误的,Parsersscala.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等风来 2024-09-02 23:48:47

问题在于 ParserParsers 的子类,因此引用它的正确方法是从 Parser< 的实例 /em>。也就是说,CeeParser.Parser 与任何其他 x.Parser 不同。

引用 CeeParser.token 类型的正确方法是 CeeParser.Parser

The problem is that Parser is a subclass of Parsers, so the proper way to refer to it is from an instance of Parser. That is, CeeParser.Parser is different from any other x.Parser.

The correct way to refer to the type of CeeParser.token is CeeParser.Parser.

鱼忆七猫命九 2024-09-02 23:48:47

问题是 Parsers 不是包或类,而是一个特征,因此无法导入其成员。您需要从扩展特征的特定类中导入。

在本例中,特定类是 CeeParser,因此 val 的类型应该是 CeeParser.Parser[CeeExpr]:

val parser : 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]:

val parser : CeeParser.Parser[CeeExpr]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文