Nick Fortescue
Nick Fortescue

Reputation: 44183

what is wrong: "value Parsers is not a member of package scala.util.parsing.combinator"?

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?

Upvotes: 4

Views: 2903

Answers (2)

Daniel C. Sobral
Daniel C. Sobral

Reputation: 297265

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.

Upvotes: 4

Nick Fortescue
Nick Fortescue

Reputation: 44183

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]

Upvotes: 1

Related Questions