Fix comment parsing to respect word boundaries around '#' - #18
Merged
Conversation
ridlfmt treated any '#' as a comment marker, but webrpc's ridl lexer only starts a comment when '#' is not touching an in-progress word token. This caused ridlfmt to split values like v0.0.1#version into a value and a comment, altering the parsed meaning of the schema. Fixes #17 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This was referenced Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parseCommentused a naivestrings.SplitN(s, "#", 2), treating any#in a line as a comment marker. webrpc's real ridl lexer only starts a comment when#is not touching an in-progress word token — e.g. inv0.0.1#beta, the#is part of the value, not a comment. ridlfmt was silently altering parsed values by inserting a space before such a#.reduceSpacesinprocessor.gohad the same naive-hash-index bug and fed corrupted (space-squashed) input intoparseComment, so it's fixed the same way._examples/e1.ridl,main_test.go) that had a#glued directly to a value with no separating space — that's genuinely ambiguous per webrpc's grammar, so a space was added to make them valid, unambiguous RIDL.formatter/comments_test.gocovering the exact cases from the issue.Fixes #17
Examples
Case 1 —
#glued to a value (version=v0.0.1#beta)version=v0.0.1#betaversion = v0.0.1 # beta— split the value, changing it fromv0.0.1#betatov0.0.1version = v0.0.1#beta— value preserved intactCase 2 — trailing
#with nothing after it (name =foo-bar#)name =foo-bar#name = foo-bar #— turned the trailing#into an (empty) comment, changing the value fromfoo-bar#tofoo-barname = foo-bar#— value preserved intactA real inline comment (
#after whitespace) is unaffected in both versions, e.g.version = v1 # my commentstaysversion = v1 # my comment.Test plan
go build ./...go test ./...(all pass, including newformatterpackage tests)gofmt -l ./go vet ./...cleanmasterand this branch