help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: filename() field should be const std::string* not std::string*


From: Akim Demaille
Subject: Re: filename() field should be const std::string* not std::string*
Date: Mon, 25 May 2020 08:16:08 +0200

Hi Martin,

> Le 24 mai 2020 à 16:56, Martin Blais <address@hidden> a écrit :
> 
> Dear grammar-generators,
> I'm setting up my %initial-action directive this morning (so much fun)

I sense some true joy here :)  If you see how to improve things, don't
hesitate making suggestions.

> and
> I can't help notice that the C++ location() and position() constructors and
> initializers accept an "std::string*" and not a "const std::string*",
> despite not modifying their value anywhere. The docs on the "position"
> class say:
> 
> Instance Variable of position: std::string* file

This should be filename.

>  The name of the file. It will always be handled as a pointer, the parser
> will never duplicate nor deallocate it. As an experimental feature you may
> change it to ‘type*’ using ‘%define filename_type "type"’.
> 
> The generated parser doesn't seem to modify it.
> This forces by driver object to cast away what should otherwise be a
> comforting const access.

What do you mean?  Do you have an example of this?  In my parsers, I don't
need it.

> I can "fix" this by using
> %define filename_type "const std::string"
> 
> Is there any reason not to make the default const?

Wow, it dates back to the creation of lalr1.cc.  See

commit 7548fed236e50c5ba9933c373a537f1a1dd15224
Author: Akim Demaille <address@hidden>
Date:   Thu Feb 6 10:04:29 2003 +0000

and then 9a0d8becd844eba80ff657a7391b2e85b7ff2077 for the introduction
of filename_type.

I agree the parser doesn't need to be able to change the file name.
However that does not suffice to make it const: the user might have
reasons to change the file name.

I'm not sure why she would though.

We could indeed try to make that change and see what happens.  The
test suite is happy, but will the users be?


Cheers!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]