Skip to content

graphql_parser: drop the re dependency - #222

Open
cuihtlauac wants to merge 1 commit into
andreas:masterfrom
cuihtlauac:drop-re-dependency
Open

cuihtlauac wants to merge 1 commit into
andreas:masterfrom
cuihtlauac:drop-re-dependency

Conversation

@cuihtlauac

Copy link
Copy Markdown

Summary

graphql_parser pulled in re — a full regex engine — only for a handful of single-character and newline operations. Since re is a hard dependency, every downstream package (graphql, graphql-lwt, …) inherited it transitively. This removes it entirely.

Fixes #221.

Changes

  • block_string.ml: replace the Re.split on \r\n / \n / \r in dedent_block_string_value with a hand-rolled split_lines that scans the string directly, mirroring the newline handling already present in get_block_string_indentation.
  • ast.ml: replace the chain of Re.replace_string calls in quote_string (escaping \, ", \b, \f, \n, \r, \t) with a single-pass Buffer escape.
  • Drop re from graphql_parser/src/dune and graphql_parser.opam.

Notes

The issue only mentioned the Re.split site, but ast.ml also used Re for pretty-printing escapes; both are replaced so the dependency can actually be dropped.

split_lines preserves empty lines (including interior ones), which the existing block-string tests rely on. The single-pass escape is equivalent to the previous sequential replacements.

Testing

dune runtest graphql_parser passes (all 7 parser tests, including block string and escaped string). graphql and graphql-lwt build cleanly against the updated parser.

🤖 Generated with Claude Code

`re` was pulled into `graphql_parser` only for a handful of
single-character/newline operations, forcing a full regex engine onto
every downstream package.

- `block_string.ml`: replace `Re.split` (split on \r\n, \n, \r) with a
  hand-rolled `split_lines` that scans the string directly, mirroring
  the existing `get_block_string_indentation` logic.
- `ast.ml`: replace the chain of `Re.replace_string` calls in
  `quote_string` with a single-pass buffer escape.
- Drop `re` from `graphql_parser/src/dune` and `graphql_parser.opam`.

Closes andreas#221

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cuihtlauac

Copy link
Copy Markdown
Author

Heads-up: the red ocaml-ci checks on this PR are pre-existing and unrelated to this change — graphql_parser itself builds and tests green. For the record, from the job logs for this commit:

  • lint-fmt — fails before formatting anything: Error: Missing 'version=' line in .ocamlformat. ocaml-ci requires a pinned version= in .ocamlformat (the repo only sets profile = conventional), so the check bails immediately. Affects every commit, including master.
  • Build matrix (debian/fedora/ubuntu/macos/…) — fails in graphql-cohttp, not in graphql_parser: module Cohttp_lwt_unix.IO deprecated and a ~flush argument mismatch against cohttp 6.x. This diff doesn't touch that code.
  • lint-opam — fails on opam-dune-lint: Missing field 'license' across the .opam files. Unrelated metadata gap.
  • lint-doc — succeeds.

This PR only touches graphql_parser (replacing the two Re uses with pure Stdlib) and drops re from its dune/opam deps. Verified locally: dune runtest graphql_parser passes (7/7, incl. the block-string and escaped-string cases), and graphql/graphql-lwt build cleanly against the updated parser.

@cuihtlauac

Copy link
Copy Markdown
Author

Gentle ping: @andreas @samoht

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

graphql_parser: drop the re dependency (used only to split on newlines)

1 participant