0

I am new to boost spirit and playing around with the microSQL-Parser.
It's not possible to parse quoted strings like: 'It's driving me crazy' in the example with the following grammar definition:

string_literal = lexeme_d[ch_p( '\'' ) >> +(anychar_p - ch_p( '\'' )) 
                       >> ch_p( '\'' )] ;

I have tried a lot but can't find the right way to do it. Does anybody know how to do it right?

timrau
  • 22,578
  • 4
  • 51
  • 64

1 Answers1

1

The code above corresponds to the regular expression: '[^']+' (which will not match the empty string '', but that's another issue).

Quotes are embedded in SQL strings by doubling them, so you actually want to feed it the string: 'It''s driving me crazy' and you can use the regular expression: '(''|[^'])*'

which corresponds to the following code:

string_literal = lexeme_d[ch_p('\'') >>
    *(ch_p('\'') >> ch_p('\'') || +(anychar_p - ch_p('\''))) >>
    ch_p('\'')];
Ferruccio
  • 98,941
  • 38
  • 226
  • 299