Skip to content

Make final newline mandatory #1779

@hryx

Description

@hryx

While working on doc gen (#21) I discovered that there is special code in the tokenizer state machine to "wrap up" the current state when EOF is encountered (stage1 and std/zig/tokenizer).

  • The logic here to terminate certain tokens or raise errors is duplicated from the main loop.
  • This final, extra state handler is a place where discrepancies or accidentally omitted cases could be introduced when updating tokenizer rules.
  • When I see a diff with no trailing newline, I cry. Just a drop, but all those tears add up.

🚫 ↩️ 😢

Inspired by #663 and feeling brassy, I thought I'd propose one further source file encoding requirement: The final character must be LF (0x0A).

Benefits:

  • Simpler tokenizing logic: upon EOF, no need to handle unterminated tokens.
  • We get to remove code: stage1 and std/zig/tokenizer
  • Increases source code uniformity and minor accidental diff noise.

Downsides:

  • Adds one more rule to source file validation (not sure of the status in stage1; according to Zig source encoding #663 self-hosted is compliant).
  • Adds a new restriction by which the programmer/editor must abide.
  • Questions from newcomers and those who have not configured their editors.
  • Unconventional.

Neutral:

  • This restriction on the programmer/editor would be the same level of severity as The Hard Tabs Issue #544, and just as easy for them to acquiesce, so we have a precedent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions