bug-bison
[Top][All Lists]
Advanced

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

Re: RFC: "count_chars" function for locations


From: Akim Demaille
Subject: Re: RFC: "count_chars" function for locations
Date: Wed, 13 Mar 2019 19:43:10 +0100

Hi Frank!

Sorry for the delays, I was on vacations.

> Le 5 mars 2019 à 02:17, Frank Heckenbach <address@hidden> a écrit :
> [...]
> Since this may be of interest to others, you might want to add this
> function to location.cc. (It doesn't cost anything if it's not
> used.) If you prefer another name instead of "count_chars", just
> change it; I'm not attached to this name, just didn't have a better
> idea ATM.
> 
>  class position:
> 
>    /// Advance the position according to the
>    /// content of the N characters starting from S.
>    /// Note: This implies an additional O(N) pass over the text.
>    void count_chars (const char *s, size_t n)
>    {
>      while (n--)
>        if (*s++ == '\n')
>          lines ();
>        else
>          columns ();
>    }
> 
>  class location:
> 
>    /// Extend the current location according to the
>    /// content of the N characters starting from S.
>    /// Note: This implies an additional O(N) pass over the text.
>    void count_chars (const char *s, size_t n)
>    {
>      end.count_chars (s, n);
>    }

I understand the need, and agree with the proposal.  However I'm
concerned by the fact that this gives a meaning to 'columns'.  Currently,
it is unspecified: it could be just bytes, or actual characters, it's
entirely up to the user to give a precise semantics to column.  Another
issue is the handling of tabulations.  Bison's own location struct
deals with them to implement them as 'goes to the column which is the
next multiple of 8'.

So I'm not sure we should start giving some semantics to 'column'.

Maybe something like %code location and %code position.  WDYT?  One
issue would then be that if someone introduced something new in position
or location, and we later add the same name, we would break the
user's code :(


reply via email to

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