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

Add support for single line comments. #31

Open
1 of 7 tasks
tacosontitan opened this issue Nov 26, 2024 · 0 comments · May be fixed by #29
Open
1 of 7 tasks

Add support for single line comments. #31

tacosontitan opened this issue Nov 26, 2024 · 0 comments · May be fixed by #29
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@tacosontitan
Copy link
Owner

tacosontitan commented Nov 26, 2024

Single-line comments in JSON are defined in the same way they are in JavaScript:

fragment Single_Line_Comment
    : '//' Input_Character*
    ;

fragment Input_Character
    // anything but New_Line_Character
    : ~('\u000D' | '\u000A'   | '\u0085' | '\u2028' | '\u2029')
    ;
    
fragment New_Line_Character
    : '\u000D'  // carriage return
    | '\u000A'  // line feed
    | '\u0085'  // next line
    | '\u2028'  // line separator
    | '\u2029'  // paragraph separator
    ;

👆🏻 multiline comment lexical structure excluded.

This issue requests the addition of support for single-line comments to the JSON library even though they aren't an official part of the spec. Many developers still add comments to JSON files and the JsonLexer could simply discard those, but that's likely a better decision for the consumer to make instead.

Acceptance Criteria

  • JsonLexer returns CommentToken for single-line comments.
  • Column number advances when horizontal movement is captured.
  • Line number advances when vertical movement is captured.
    • Column number is reset to 0 when line number advances.
  • Captured comments exclude whitespace.
    • 👆🏻 this should be configurable.
  • Test coverage for implementation.
@tacosontitan tacosontitan converted this from a draft issue Nov 26, 2024
@tacosontitan tacosontitan added the enhancement New feature or request label Nov 26, 2024
@tacosontitan tacosontitan self-assigned this Nov 26, 2024
@tacosontitan tacosontitan added this to the JSON milestone Nov 26, 2024
@tacosontitan tacosontitan linked a pull request Nov 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

1 participant