Skip to content

Conversation

@Krzmbrzl
Copy link
Collaborator

@Krzmbrzl Krzmbrzl commented Jan 26, 2026

See individual commits.

TODO:

  • Make options take syntax version param
  • Provide explicitly namespaced/versioned access to parse/deparse
  • Implement defaulted parse/deparse

@Krzmbrzl Krzmbrzl force-pushed the namespace-parse branch 3 times, most recently from 580aea4 to f2c5750 Compare January 27, 2026 09:55
Also, remove some redundant deparse() overload declarations (they are
implicitly accessible via the overload for Expr &).
Without optimizations, these tests can take forever and hence hamper
running tests repeatedly during development cycles.
@Krzmbrzl Krzmbrzl force-pushed the namespace-parse branch 2 times, most recently from 2300ab4 to 73481f8 Compare January 27, 2026 12:33
@Krzmbrzl Krzmbrzl marked this pull request as ready for review January 27, 2026 14:32
@Krzmbrzl Krzmbrzl requested a review from evaleev January 27, 2026 14:56
SeQuant supports creating expression objects by parsing an appropriately formatted input string. This process is referred to as *parsing*.
Furthermore, SeQuant can also serialize expression objects into this string representation, which is referred to as *deparsing*.

The functions for performing these tasks are :func:`parse_expr(…)`, :func:`parse_result_expr(…)` and :func:`deparse(…)` respectively. The former two
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a good time to revisit the "incosistent" naming?

  • deparse is similar to to_latex but names are very different ... how about to_sqtext or to_sqmath
  • deparse is seemingly only a word used in R language (i.e. it's not an actual word)
  • parse_expr and parse_result_expr are factories, make_expr and make_result_expr would be more in line with naming of factories in SQ and elsewhere ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do make changes, now would indeed be a good moment.

I kinda like the symmetry between the parse and deparse function names. We don't really have that with the alternate names you suggested...

Also, given that what we do is parsing, I would prefer to actually have parse in the name 👀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda like the symmetry between the parse and deparse function names. We don't really have that with the alternate names you suggested...

I like the symmetry too. I like design precision even more.

Can keep it, but not in the top-level namespace. The issue with these names (and the reason for this PR) is that these must be specific to a format that they refer to (and with parse_* function we must declare explicitly what we are constructing). So we must namespace them. So perhaps what we need is:

sequant::io::latex::parse...;
sequant::io::latex::deparse;  // does this exist? At some point deparse actually took pure latex as input ...
sequant::io::sqtext::v1::parse...;
sequant::io::sqtext::v1::deparse;
sequant::io::sqtext::v2::parse...;
sequant::io::sqtext::v2::deparse;

To avoid such long names we still need top-level sugar, such as to_latex. I propose to_text for sqtext::default::deparse and from_text<{Expr,ResultExpr}> as top-level sugar.

Also, given that what we do is parsing, I would prefer to actually have parse in the name 👀

Parsing is an implementation detail, name should reflect what users care about (to_text, from_text ... how these are implemented? They should not care).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so perhaps this is what I have in mind:

sequant::io::latex::to;
sequant::io::latex::from...;
sequant::io::sqtext::v1::to;
sequant::io::sqtext::v1::from...;
sequant::io::sqtext::v2::to;
sequant::io::sqtext::v2::from...;
using namespace sequant::io::sqtext::default = sequant::io::sqtext::v1;
sequant::to_latex = sequant::io::latex::to;
sequant::to_text = sequant::io::sqtext::default::to;
etc.

Copy link
Collaborator Author

@Krzmbrzl Krzmbrzl Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of an io namespace that bundles all different input/output formats. I would probably use function names serialize and deserialize instead of to and from though. To me that makes the function calls appear a bit more natural… I guess with to and from I would kinda expect the format to be attached as to_latex and from_latex rather than latex::to and latex::from.

However, since not all of these formats are intended to be roundtrip-capable (e.g. LaTeX only works in the expression-to-string direction afaict) serialize is probably not quite correct (though I think we could use serialize instead of sqtext). So maybe using to_string and from_string instead is the way to go?

Something like

sequant::io::latex::to_string;
sequant::io::serialization::to_string; //Note: these are actual implementations that do the forwarding at runtime
sequant::io::serialization::from_string;
sequant::io::serialization::v1::to_string;
sequant::io::serialization::v1::from_string;
sequant::io::serialization::v2::to_string;
sequant::io::serialization::v2::from_string;

// Note sure if we really should define these (users can bring the functions in their namespace as desired)
sequant::to_latex = sequant::io::latex::to_string;
sequant::serialize_to_string = sequant::io::serialization::to_string;
sequant::deserialize_from_string = sequant::io::serialization::from_string;

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.

2 participants