Skip to main content

Module strip

Module strip 

Source
Expand description

Blanking of comments, text literals and quoted identifiers.

Every textual comparison in this product runs over the output of this module and never over the raw statement. Two measured defects in the reference implementations come from comparing raw text: a legitimate query carrying a reserved word inside a literal was refused, and a destructive statement hidden behind a comment was admitted.

§What is blanked

Blanked regions are replaced byte for byte with spaces, so every offset in the output still names the same position in the input and a refusal message can point at the right place.

Quoted identifiers are blanked too. They are names rather than literals, but a name may legally contain a separator or a reserved word, and blanking is what stops `a;b` from being read as two statements.

§What is not blanked

A conditional comment (/*! ... */ or /*M! ... */) is executable on this server, so its body is code and stays. Only the introducer and the closing delimiter are blanked. Callers that must know a statement carried one ask Stripped::has_conditional_comment.

§Why the same scan also feeds the parser

expand_conditional_comments applies that one rule and nothing else, so the parser is handed the statement the server will run. Leaving that to the parser crate was measured to be wrong: it expands the introducer that starts with an exclamation mark and drops the server-specific one as whitespace, which took a file-reading call out of the tree the refusals walk.

Structs§

Stripped
A statement with its comments, text literals and quoted identifiers blanked.
Unterminated
A quoted or commented region that never closed.

Enums§

UnterminatedKind
The kinds of region that can be left open.

Functions§

expand_conditional_comments
The statement as the server will run it, with conditional comments expanded.
strip
Blanks comments, text literals and quoted identifiers.