What is wrong: "The value of Parsers is not included in the scala.util.parsing.combinator package"?

I got the odd error message above that I don’t understand. Parsers is not a member of the scala.util.parsing.combinator package. "

I am trying to learn Parser combinators by writing a C-parser C step by step. I started with a token, so I have 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 

It is as simple as I could do it.

The code below works fine, but if I uncomment the commented line, I get the error message 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) } } 

If this is a problem with my setup, I use scala 2.7.6 via scala -plugin for intellij. Can anyone shed some light on this? The message is incorrect, Parsers is a member of scala.util.parsing.combinator .

--- Following actions

This person http://www.scala-lang.org/node/5475 seems to have the same problem, but I don’t understand the answer I gave him. Can anyone explain this?

+4
source share
2 answers

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

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

+4
source

The problem is that Parsers is not a package or class, it is a sign, so its members cannot be imported. You need to import from a specific class extending the trait.

In this case, the specific class is CeeParser, so the val type must be CeeParser.Parser [CeeExpr]:

 val parser : CeeParser.Parser[CeeExpr] 
+1
source

Source: https://habr.com/ru/post/1305302/


All Articles