feat: add comment support to saccharine language #25

Merged
mvhutz merged 3 commits from feat/comment-support into main 2026-01-13 02:00:01 +00:00
Owner

Description

The saccharine language previously lacked comment support, preventing proper code documentation.
This PR implements '#' comment syntax similar to Python.
Comments can appear on their own line or at the end of a line, with all content after '#' ignored until the next newline or EOF.
The tokenizer now detects '#' and skips characters appropriately without creating tokens.

Decisions

Comments are silently consumed during tokenization rather than being preserved as tokens, keeping the token stream clean for the parser.
The implementation preserves newlines after comments by using the iterator's Back() method, allowing them to be processed as soft breaks.

Benefits

Developers can now document their saccharine code with inline and full-line comments.
The implementation is minimal and efficient, adding no overhead to the token stream.
Tests verify that comments work correctly in various positions without breaking code execution.

Checklist

  • Code follows conventional commit format.
  • Branch follows naming convention (<type>/<description>). Always use underscores.
  • Tests pass (if applicable).
  • Documentation updated (if applicable).

Closes #24

## Description The saccharine language previously lacked comment support, preventing proper code documentation. This PR implements '#' comment syntax similar to Python. Comments can appear on their own line or at the end of a line, with all content after '#' ignored until the next newline or EOF. The tokenizer now detects '#' and skips characters appropriately without creating tokens. ### Decisions Comments are silently consumed during tokenization rather than being preserved as tokens, keeping the token stream clean for the parser. The implementation preserves newlines after comments by using the iterator's Back() method, allowing them to be processed as soft breaks. ## Benefits Developers can now document their saccharine code with inline and full-line comments. The implementation is minimal and efficient, adding no overhead to the token stream. Tests verify that comments work correctly in various positions without breaking code execution. ## Checklist - [x] Code follows conventional commit format. - [x] Branch follows naming convention (`<type>/<description>`). Always use underscores. - [x] Tests pass (if applicable). - [x] Documentation updated (if applicable). Closes #24
mvhutz added 1 commit 2026-01-13 01:54:06 +00:00
Add '#' comment syntax that works like Python comments.
Comments can take up a whole line or appear at the end of a line.
All characters after '#' until the next newline or EOF are ignored.

Closes #24
mvhutz added 1 commit 2026-01-13 01:58:42 +00:00
mvhutz added 1 commit 2026-01-13 01:59:37 +00:00
The loop was checking 'for i.Done()' instead of 'for !i.Done()',
which prevented the comment content from being consumed.
This caused the tokenizer to treat comment text as code.
mvhutz merged commit 335ce95c50 into main 2026-01-13 02:00:01 +00:00
mvhutz deleted branch feat/comment-support 2026-01-13 02:00:01 +00:00
Sign in to join this conversation.