Hi Marc,

The following line seems to work just fine, with-or-without the call to
.Str at the end:

method col:sym<quoted> ($/) { make $/.subst(/'""'/, '"', :global).Str }

#Gives the 12 element result below (in the context of your entire,
previously-posted Grammar):

.raku.say for CSV.parse(
    '162,1,2,"Watt, Mrs. James (Elizabeth ""Bessie"" Inglis
Milne)",female,40,0,0,C.A. 33595,15.75,,S',
    actions => CSV_as_table.new,
).made;

("162", "1", "2", "Watt, Mrs. James (Elizabeth \"Bessie\" Inglis Milne)",
"female", "40", "0", "0", "C.A. 33595", "15.75", "", "S").Seq

(Apologies to Raiph if this ground has already been covered),
HTH, Bill.


On Fri, Nov 19, 2021 at 12:32 AM Marc Chantreux <e...@phear.org> wrote:

> hello Ralph,
>
> Thank you for the whole explaination and links.
>
> > method col:sym<quoted> ($_) { .make: S:g/'""'/"/ }
>
> i dug around it but missed it! arggh ...
>
> > > am I right when i feel there is a way to do this
> > > substitution inside the grammar
>
> > As I've shown, yes. But it draws you into the `$/` dance.
>
> The way I read you is "no" as i can't reassign inside a grammar.
>
> what i was expecting is to hack the grammar itself. something like
> replacing
>
>     token col:sym<quoted> {
>         '"' ~ '"'
>         [ <( [ '""' | <-[\n"]> ]* )> ]
>     }
>
> by something close to
>
>     token col:sym<quoted> {
>         '"' ~ '"'
>         [ <( [ '""' { $0 = '"' } | <-[\n"]> ]* )> ]
>     }
>
> anyway: thanks for the detailed explaination. your solution is really
> elegant
>
> marc
>

Reply via email to