0

I want to able to parse single spaces between terms (even there exist multiple single spaces) using this parser. I tried adding the qi::space parser to the character rule like this _character = alnum | char_("\"'| !#$%&()*+,./:;>=<?@]\\^_`{}~[-") | qi::space; but this doesn't even compile. How can I enforce single space parsing even if the exist multiple whitespaces.

r360
  • 49
  • 4
  • Can you show what is "going wrong"? Because there's no reason "it" should not compile, nor not do what you expect. – sehe May 28 '21 at 13:21

1 Answers1

0

The way I look at it,

  1. _character is already lexeme so skipper issues are out (Boost spirit skipper issues)
  2. char_("abc") | char_("d") is equivalent char_("abcd")`
  3. The expresion char_("\"'| !#$%&()*+,./:;>=<?@]\\^_{}~[-")ALREADY contains the space, so tacking on| qi::char_(' ')` would not change a thing
  4. You seem to expect that space actually matches ' ' (ASCII 32). Which is almost true, but it matches anything your locale classifies as isspace. That includes (horizontal) tab, formfeed, newline and possibly others.

I think you need to rethink your problem, likely you're confused about something else

  • Review that linked post to check your understanding of the skipper (which is active on rules _rule, _expression and _list).

  • Perhaps you are seeing "multiple matched" because tabs appear as multiple spaces, and will get matched

  • Perhaps you have a mistaken understanding about what the effect of changin _character would be: it's actually exclusively used inside quoted literals. It's highly unlikely that you needed to special-case space parsing inside literals.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • maybe this may clarify my question; I want to be able to read the whitespace between literals, terms or a literal and a term. For example: ` ::= a | b b`. I want to able to read the whitespace in between. – r360 May 28 '21 at 13:58
  • So, why are you mucking with `_character` rule? That makes... no sense for the reason I explained in the answer. Can you post a new question, where you post the code you have, the input you want to parse and the output you want to achieve? – sehe May 28 '21 at 14:04
  • (Oh, and maybe also state the GOAL, why you are trying to read significance into BNF whitespace. So we don't get stuck in the next station of [X/Y problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)) – sehe May 28 '21 at 14:08