Skip to content

Fix parser exception on lone comment in keyvals. #1661#1698

Open
sangwinc wants to merge 1 commit intodevfrom
iss1661
Open

Fix parser exception on lone comment in keyvals. #1661#1698
sangwinc wants to merge 1 commit intodevfrom
iss1661

Conversation

@sangwinc
Copy link
Member

@sangwinc sangwinc commented Mar 9, 2026

Fix to issue #1661.

@sangwinc sangwinc requested a review from aharjula March 9, 2026 16:09
}

$str = $this->raw;
$str = maxima_parser_utils::remove_comments($this->raw);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make my own branch...

This is a problem. If you go and modify the source code before parsing, then the parser-generated position data will be off, and any error messages given will reference the wrong lines/columns, which would be a shame if we ever get a line-numbered code editor.

So instead of trimming and removing extra stuff, we should always just give the raw input to the parser. Well, you can always just do if(trim($str)==='') first to avoid having to init the parser for truly empty stuff, but you should not give the parser the trimmed content.

Even if the old comment remover might be faster and more efficient than the full parsing logic, the price would be the loss of position data, and we do not want to pay that.

If the new parser does not already parse "empty" or "just comments" contents without trouble, I'll make it do so, after all, the Rust version of it does do so.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks @aharjula I didn't really appreciate we need the position data later. That makes perfect sense. Yes, the test case here fails without some changes.

7b70035#diff-13d288001e398079c72696b47904ebfc96bb7dbe04b9aba0a3d0af367609925bR450

@aharjula
Copy link
Member

I do have to wonder if #1661 was even an issue with the new parser? The new parser was returning null, which was expected when receiving such "empty" input. My new branch changes it to return an empty MP_Root instead and allows one to parse comments even from such empty content if need be.

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.

2 participants