-
Notifications
You must be signed in to change notification settings - Fork 165
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
Java Backend: Add line number support. #217
Conversation
Consider this a first pass. If there's something that doesn't match the project's style, or you'd like to see re-worked, let me know. |
Thanks for the PR and your contribution to BNFC. I took your PR as opportunity to put out some contribution guidelines, see README at https://github.com/BNFC/bnfc, section Contribute. I am a bit confused about the title
Looking forward to the updated PR! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly request for documentation. Avoid magic numbers.
source/src/BNFC/Backend/Java.hs
Outdated
parserLexerSelector :: String -> JavaLexerParser -> ParserLexerSpecification | ||
parserLexerSelector _ JLexCup = ParseLexSpec | ||
{ lexer = cf2JLex | ||
parserLexerSelector :: String -> JavaLexerParser -> Bool -> ParserLexerSpecification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid Bool
(or at least document function argument).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
then if jflex then "" | ||
else "int yycolumn = -2;" | ||
else vcat | ||
[ "int yyline = -2;" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic numbers like -2
should be avoided.
If unavoidable, document properly. (Why -2
, why doesn't it work without the magic?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
, "%public" | ||
, "%{" | ||
, nest 2 $ vcat | ||
[ "String pstring = new String();" | ||
, "ComplexSymbolFactory.Location left = new ComplexSymbolFactory.Location(-1, -1);" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document magic numbers (-1
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
then "right.move(0, yylength(), yylength());" | ||
else "") | ||
, " return right;" | ||
, "}" | ||
, "public String buff()" <+> braces | ||
(if jflex | ||
then "return new String(zzBuffer,zzCurrentPos,10).trim();" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic number 10
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic number 10 was there before.
d88b429
to
9bae6f9
Compare
No. The line number support currently extends only as far the lexer. The symbols created for the parser have no line information, so syntax errors have no context info to find them. ComplexSymbol is necessary because the standard JLex Symbol class only keeps track of character position, oddly enough. Expect an eventual followup to record the line info in the generated abstract syntax tree. |
Added tests to the testsuite, and verified they pass for jlex and jflex, both with and without line numbers. |
Thanks for the quick response! Will you update this PR or make a new one, with the changes you outlined above? |
It's already updated.
Edit: I realized you may have meant adding line info the Abstract Syntax Tree. I'll do that in a separate PR, but the other changes are already in this one.
…On Dec 13, 2017 12:20 AM, "Andreas Abel" ***@***.***> wrote:
Thanks for the quick response!
Will you update this PR or make a new one, with the changes you outlined
above?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#217 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AgRziCtUftUy-R9wtQ5fK-4MBIk0MAeJks5s_4jjgaJpZM4Q-IuU>
.
|
Thanks for the update. Almost there, can we make the title a bit more precise?
The new text should make clear
Please write this up in a paragraph or so and put it into Thanks for your contribution so far! |
Currently the help message includes the following for Java: Special options for the Java backend -l Add and set line_number field for all syntax classes The only place this support existed was in the help documentation. A quick glance through the Java backend files will show that the Option.linenumbers was never inspected. This change adds that support for parsing. Cup's "Symbol" class only supports character offsets, so we use its "ComplexSymbol" class, which supports line, column, and offset. JLex does not provide column info, but JFlex does. ComplexSymbol tracks the left and right extents of a production, and so for variable length tokens we capture this info. The abstract syntax classes still do not record line information, but the necessary information is now available during parsing, and a follow-up commit will handle adding the info to the Absyn classes and code to record it to the generated cup file.
9bae6f9
to
856d2db
Compare
I added the additional documentation to the commit message. Java.hs didn't seem like the right place for it. |
Thanks for the good work! |
Er, the testsuite does not pass. I am getting errors like:
According to http://czt.sourceforge.net/dev/java-cup-runtime/apidocs/java_cup/runtime/ComplexSymbolFactory.Location.html there is no Could be that your patch requires a different version of cup? ubuntu xenial comes with version 0.11a.
What is the minimal version of |
It seems that with the latest version of java-cup, there are no problems with the testsuite. How can we ensure that or test whether the necessary version is installed? |
With the move in there, it requires a fairly new cup, 2015 or so. Without it, any cup 0.11b will do. I can also adjust the code to work with 0.11a. I have that working already. I'll create a new PR that does that. |
Use complex symbol for automatic context with syntax errors.