Tokei uses a SyntaxCounter to manage the state of a file during analysis. The counter operates in three primary modes to ensure accurate counting of code, comments, and strings:
plain mode: The default state. Blanks are counted as blanks, and the parser looks for triggers to enter string or comment modes.string mode: Triggered when the parser enters a string literal. While in this mode, comments are ignored and cannot trigger a transition to comment mode.comment mode: Triggered when the parser enters a comment block. While in this mode, strings are ignored and cannot trigger a transition to string mode.
This state machine allows Tokei to correctly distinguish between actual code and text that looks like code but is actually inside a comment or a string literal.
/// - `plain` mode: This is the normal state, blanks are counted as blanks,
/// string literals can trigger `string` mode, and comments can trigger `comment` mode.
/// - `string` mode: This when the state machine is current inside a string
/// literal for a given language, comments cannot trigger `comment` mode while
/// in `string` mode.
/// - `comment` mode: This when the state machine is current inside a comment
/// for a given language, strings cannot trigger `string` mode while in
/// `comment` mode.