Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScalaParserException should indicate line or char number of syntax error #104

Open
RichardBradley opened this issue Mar 6, 2014 · 3 comments

Comments

@RichardBradley
Copy link
Contributor

I have a source code file which compiles and runs fine, but which crashes scalariform (called via Scalastyle).

The error includes only a Token "pos", which as far as I can tell is just the index of the current token in the array of tokens after the file was lexed. This is next to no help in diagnosing the problem, as I can't figure out which part of the file is confusing scalariform

My current error looks like:

Expected token ARROW but got Token(RBRACE,},11265,})
scalariform.parser.ScalaParser.scalariform$parser$ScalaParser$$accept(ScalaParser.scala:80)
scalariform.parser.ScalaParser.scalariform$parser$ScalaParser$$caseBlock(ScalaParser.scala:896)
scalariform.parser.ScalaParser$$anonfun$39.apply(ScalaParser.scala:885)
scalariform.parser.ScalaParser$$anonfun$39.apply(ScalaParser.scala:885)
scalariform.parser.ScalaParser.tokenSeparated(ScalaParser.scala:170)
scalariform.parser.ScalaParser.caseSeparated(ScalaParser.scala:179)
scalariform.parser.ScalaParser.scalariform$parser$ScalaParser$$caseClauses(ScalaParser.scala:884)
scalariform.parser.ScalaParser$$anonfun$38.apply(ScalaParser.scala:875)
scalariform.parser.ScalaParser$$anonfun$38.apply(ScalaParser.scala:875)
scalariform.parser.ScalaParser.inBraces(ScalaParser.scala:31)
scalariform.parser.ScalaParser.scalariform$parser$ScalaParser$$blockExpr(ScalaParser.scala:874)
scalariform.parser.ScalaParser$$anonfun$scalariform$parser$ScalaParser$$argumentExprs$1.applyOrElse(ScalaParser.scala:862)
scalariform.parser.ScalaParser$$anonfun$scalariform$parser$ScalaParser$$argumentExprs$1.applyOrElse(ScalaParser.scala:861)
scala.PartialFunction$Lifted.apply(PartialFunction.scala:218)
scala.PartialFunction$Lifted.apply(PartialFunction.scala:214)
scala.PartialFunction$.condOpt(PartialFunction.scala:281)
scalariform.parser.ScalaParser.scalariform$parser$ScalaParser$$argumentExprs(ScalaParser.scala:861)
scalariform.parser.ScalaParser.simpleExprRest(ScalaParser.scala:835)
Scalariform.parser.ScalaParser.simpleExpr(ScalaParser.scala:806)

It would be far more helpful if this error included a line number or a char index. A token index is next to useless AFAICT.

@RichardBradley
Copy link
Contributor Author

(For anyone else who has this problem and is trying to track down what has offended scalariform, you can use head -n X MyFile.scala to find where offset "X" is in the file.)

@robert-vandell-ck
Copy link

On OSX it's head -c X MyFile.scala where -c is to display the first X bytes.

@mwz
Copy link

mwz commented Mar 13, 2020

I had a look at this and opened #287 - would be good to get some feedback as I'm not sure if this is the right way to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants