Skip to content

refactor: Applicative parsers#2532

Merged
rprospero merged 31 commits into
develop2from
applicative_parser
Jun 26, 2026
Merged

refactor: Applicative parsers#2532
rprospero merged 31 commits into
develop2from
applicative_parser

Conversation

@rprospero

@rprospero rprospero commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

This PR adds an applicative parsing library. Additionally, as a proof of concept, the ImportXYZStructure Node and ImportXYZTrajectory Node are both updates to use an applicative parser and remove the dependency on LineParser. If this code looks like a worthwhile avenue, other instances of LineParser can be converted to use the parsers.

Currently, the parser does not return error messages on failed parses, but it's possible to allow for more informative messages in the future if we change

template <typename T> using parser_output = std::optional<std::tuple<T, std::istream &>>;

to

template <typename T> using parser_output = std::variant<std::tuple<T, std::istream &>, ErrorMessage>;

As a simple tutorial on how to use the parsers, it's worth starting by looking at tests/io/applicative.cpp, as the tests build up the different combinators.

@rprospero rprospero force-pushed the applicative_parser branch from ee5ab59 to db3c467 Compare June 23, 2026 17:10
@rprospero rprospero changed the title refector: Applicative parser refactor: Applicative parsers Jun 23, 2026
@rprospero rprospero force-pushed the applicative_parser branch from db3c467 to e8869c5 Compare June 24, 2026 08:30
@rprospero rprospero force-pushed the applicative_parser branch from 57273be to 026c85c Compare June 24, 2026 11:25
@rprospero rprospero marked this pull request as ready for review June 24, 2026 12:38

@trisyoungs trisyoungs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I really like this. My only minor concern is that the expression of the parser takes a bit of getting used to with << and >> flying around everywhere. But it is cool!

A handful of suggestions sprinkled around the place, mostly flagging the usage of snake_case vs camelCase vs PascalCase.

Comment thread src/base/parserLibrary.h Outdated
Comment thread src/base/applicative.cpp Outdated
Comment thread src/base/applicative.cpp Outdated
Comment thread src/base/applicative.cpp Outdated
Comment thread src/base/applicative.h Outdated
Comment thread tests/io/applicative.cpp Outdated
Comment thread tests/io/applicative.cpp Outdated
Comment thread tests/io/applicative.cpp Outdated
Comment thread tests/io/applicative.cpp Outdated
Comment thread tests/io/applicative.cpp Outdated
rprospero and others added 6 commits June 24, 2026 13:18
Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>
Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>
Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>
Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>
Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>
Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>
@rprospero rprospero requested a review from trisyoungs June 26, 2026 08:31

@trisyoungs trisyoungs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Love it. One added comment line.

Comment thread src/base/parserLibrary.h
Comment thread src/base/parserLibrary.cpp
rprospero and others added 2 commits June 26, 2026 10:56
Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>
Co-authored-by: Tristan Youngs <tristan.youngs@stfc.ac.uk>
@rprospero rprospero merged commit ed04a1e into develop2 Jun 26, 2026
@rprospero rprospero deleted the applicative_parser branch June 26, 2026 10:57
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