Boost logo

Boost :

Subject: [boost] [geometry][metaparse] UDL-based compile-time DSL parser (was: Re: [offtopic] user-defined raw string literals)
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2014-02-01 07:31:11


Hi Abel,

Abel Sinkovics wrote:
> On 2014-01-30 17:25, Adam Wulkiewicz wrote:
>> Ok so now the tricky part. It should be parsed in compile-time, the
>> type of the geometry retrieved from the string literal and proper
>> type returned (bg::polygon<> in this case).
>> Unfortunately string literals can't be handled as raw literals, e.g.
>> using the variadic-template version of operator"":
>>
>> template <char...>
>> void operator "" ()
>>
>> Why? Is there a reason for this?
>> If we had the ability to use the compile-time version with string
>> literals it would be possible to implement various compile-time
>> parsers, not only for the mentioned WKT.
>>
>> So what do you think about it?
>
> I don't know the reason for the string literal limitation,

AFAIU it would be difficult to implement consistent behavior because
string literals are concatenated by the preprocessor automatically.

> but I have a workaround for it. You can use the MPLLIBS_STRING macro
> from Metaparse - not in Boost yet. (see
> http://abel.web.elte.hu/mpllibs/metaparse/manual.html#the-input-of-the-parsers
> and http://abel.web.elte.hu/mpllibs/metaparse/MPLLIBS_STRING.html).
> Using that you can parse string literals at compile-time.
>
> Metaparse itself is a library supporting the creation of parsers for
> DSLs that are parsed at compile time. You might be able to create an
> interface like this using that:
>
> auto polygon = WKT("POLYGON((30 10,40 40,20 40,10 20,30 10))");
> auto point = WKT("POINT(30 10)");
> // ...
>
> where WKT is a macro expanding to a template metaprogram-based parser
> invocation. If you are interested in trying it out, there is a
> tutorial which helps you getting started:
> https://github.com/sabel83/metaparse_tutorial#metaparse-tutorial.

Thanks for the info. However using macros isn't exactly the thing I
wanted to do because it would be less readable:

auto polygon = BOOST_GEOMETRY_WKT("POLYGON((30 10,40 40,20 40,10 20,30
10))");

vs

auto polygon = "POLYGON((30 10,40 40,20 40,10 20,30 10))"_wkt;

but I'll for sure check Metaparse out in a free time. I may let you know
when it's done. Even if it wasn't released with Geometry you'd be able
to put it as an example in the docs.

Regards,
Adam


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk