Skip to content

Share one MySQL lexer between the rewriter and the placeholder scanner #249

Description

@rayakame

The MySQL lexing rules (backslash escapes in strings, backtick identifiers, # comments, the ---needs-whitespace rule, live /*! bodies) are implemented twice: rewriteMySQLSQL in internal/transform/mysql_sql.go rewrites ? to pyformat at generation time, and placeholderSequence in internal/driver/common.go scans the rewritten text to order binding slots for reused sqlc.slice markers.

The two are kept in sync by tests that pin each rule on both sides, but a divergence silently misorders reused-slice arguments - review on #248 caught two such cases (odd-length dash runs, the \r line-end rule) before merge. A single shared scanner would remove the failure class entirely; the open question is where it lives, since transform and driver do not import each other today. An alternative is computing the placeholder sequence during the rewrite and carrying it on the IR, dropping the second lexer.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    goPull requests that update go code

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions