Skip to content

Add error position and json_path to the JRuby extension - #1067

Open
ojuschugh1 wants to merge 2 commits into
ruby:masterfrom
ojuschugh1:java-parser-positions
Open

Add error position and json_path to the JRuby extension#1067
ojuschugh1 wants to merge 2 commits into
ruby:masterfrom
ojuschugh1:java-parser-positions

Conversation

@ojuschugh1

Copy link
Copy Markdown
Contributor

Follow-up to #1062, as suggested there: this brings ParserError#line, #column and #json_path to the JRuby extension.

The Java parser already shares the C parser's architecture (frame stack + value stack), so the implementation mirrors it closely: positions are computed by scanning backwards from the error offset like cursor_position does in C, and @json_path is collected as raw segments from the frame stack, then formatted by the shared Ruby code from #1062. Everything happens at raise time, so nothing is added to the happy path. NestingError stays bare, matching the C extension.

Positions and paths come out identical to the C parser:

**jruby 10.0.2.0**
unexpected token at 'xyz}]}}' at line 1 column 34
line=1 column=34 json_path=$.user.roles[1].admin
duplicate key "c" at line 1 column 17
line=1 column=17 json_path=$.a.b[1].c


The duplicate key case reuses the existing cursor rewind to the object's opening brace, so line/column match C exactly there too. Error message wording still differs between the two extensions ("unexpected token at" vs "unexpected character:"); I left that alone to keep the diff focused.

The four json_path test methods now run on JRuby (omit guards removed), plus a new test_parse_error_position asserting line/column values on both extensions. JRuby suite goes from 53 omissions to 49 with 0 failures; CRuby stays at 0 failures, 0 omissions.

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

Successfully merging this pull request may close these issues.

1 participant