C++ Logo

std-proposals

Advanced search

Re: [std-proposals] regex over istreams

From: (wrong string) Åberg <haberg_1_at_[hidden]>
Date: Fri, 21 Feb 2025 09:55:32 +0100
> On 20 Feb 2025, at 22:35, Phil Bouchard via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On 2/20/25 16:17, Jonathan Wakely wrote:
>> This uses a hardcoded regular expression to extract from the stream. That doesn't seem very useful. Surely you would want to be able to customize the regex? What API are you proposing for that?
>
> This is just an example function. My goal is to write a robust parser using standard C++ operator >>.

I am using such a syntax for my parsers, which helps remembering how to invoke it, but also note that in the formatted input already present, one is in effect using a simple implicit parser. My parser is built up using Flex and Bison, with a grammar approaching in size that of C++, and it reads entries for a database, thus quite large.

One possibility is using manipulator syntax, in the case several different parsers can produce the same type value:
  parser p;
  A a;
  cin >> p >> a;

But if the parser is known to the type a, one can reduce to:
  A a;
  cin >> a;

The code here invokes the parser on line 279, and also showing the setup:
https://git.savannah.gnu.org/cgit/metalogic-inference.git/tree/src/main.cc

Received on 2025-02-21 08:55:53