Questions tagged [boost-spirit-x3]

LL parser framework represents parsers directly as EBNF grammars in inlined C++14

281 questions
1
vote
0 answers

boost spirit x3 match an end of lexeme?

Let's suppose we need to parse "a" or "ab" inputs. The following naive parser fails: auto parser = 'a' | 'a' > 'b'; One of the solution is to rewrite the parser to match the end of the input this way: auto parser = 'a' >> eoi | 'a' > 'b' And it…
Voivoid
  • 461
  • 3
  • 11
1
vote
1 answer

Spirit X3: attribute of alternative parser, not `char`, but `variant`

According to spirit x3 attribute collapsing rule, the attribute of an anternative parser with 2 alternation having same attribute, should collapse, i.e. a: A, b: A --> (a | b): A, but the code below shows its not, is it a bug or my fault? Here is…
Suen
  • 73
  • 6
1
vote
0 answers

Boost spirit x3 error handling with expectations

I am working on parsing .csv files with spirit x3. I want to use expectations to get a detailed information on the error. Further the input should be accepted if it ends with or without a new line. Here is my code so far: #include…
Max
  • 638
  • 1
  • 4
  • 19
1
vote
1 answer

Boost Spirit x3 not compiling

I'm following the x3 documentation on the boost website, and I've tried to augment the example on how to organize code with the stuff explained in the annotations example that comes after. I'm having the following error when compiling the project…
Etchelon
  • 832
  • 11
  • 27
1
vote
1 answer

How to replace left recursion in boost spirit x3?

I’m currently trying to parse recursive expressions like ***a and a*** with boost spirit x3. So I defined my abstract syntax tree as follows: namespace client { namespace ast { struct pointer; struct type : x3::variant< …
1
vote
1 answer

Spirit X3, ascii::cntrl why disparity with std::iscntrl?

I'm concentrating on checking for error conditions in an parser design using Spirit X3. One of which is the character category checks like isalpha or ispunct. According to the X3 documentation Character Parsers they should match what C++ provides as…
Zeyneb
  • 115
  • 1
  • 8
1
vote
2 answers

Spirit X3, How to fail parse on non-ascii input?

So the objective is to not tolerate characters from 80h through FFh in the input string. I was under the impression that using ascii::char_; would take care of this. But as you can see in the example code it will happily print Parsing succeeded. In…
Zeyneb
  • 115
  • 1
  • 8
1
vote
1 answer

How to make recursive Spirit X3 parser with a separate visitor class

A parser application where I’m working on calls for recursive rules. Besides looking into the Recursive AST tutorial examples of Boost Spirit X3 which can be found here: https://www.boost.org/doc/libs/develop/libs/spirit/doc/x3/html/index.html, I…
Zeyneb
  • 115
  • 1
  • 8
1
vote
1 answer

Synthesizing std::pair attributes in boost::spirit::x3

I'm trying to create a parser using boost::spirit::x3 and stumbled upon a strange issue. Despite that this particular use case is presented in the "Using X3" document by Joel de Guzman and Michael Caisse (https://ciere.com/cppnow15/), not all…
r0mko
  • 11
  • 2
1
vote
1 answer

How to test string for valid double content with boost::spirit::x3?

I am trying to determine if a given string is a valid double representation. The code I am using looks like this: bool testNumeric(const std::string& s) { try { const auto doubleParser = boost::spirit::x3::double_; auto iter…
mgr
  • 344
  • 4
  • 11
1
vote
1 answer

Boost spirit x3 inserting empty strings while direct parsing

I am trying to parse some text files with boost spirit X3 parser, and I have found some differences while using a lambda function or while using "direct" parsing rules. My sample code is next: #include #include…
Pablo
  • 557
  • 3
  • 16
1
vote
1 answer

Boost Spirit: how to count occurences of certain characters and then put the result in AST?

I would like to parse the following text: group RGB group RRGB group GBBB group RRGGG The resulting AST would be a struct that represents counts of each character: struct group { int r; int g; int b; }; For the inputs above it would be…
Xeverous
  • 973
  • 1
  • 12
  • 25
1
vote
2 answers

Boost Spirit - project builds with -O1 but not with -O2

I have a small project (similar to their example - https://github.com/cierelabs/x3_fun/) using Boost Spirit X3 and it builds in debug but not in release. X3 program structure recommendation + another example:…
Xeverous
  • 973
  • 1
  • 12
  • 25
1
vote
1 answer

How do semantic actions (using _val and _attr) influence rule definition with %= and x3::rule's force_attribute=true?

Given semantic actor template class divide { public: divide(ValueType value) : divisor{value} {} template void operator()(ContextType& context) const { _val(context) /= divisor; } private: …
rubenvb
  • 74,642
  • 33
  • 187
  • 332
1
vote
1 answer

Boost Spirit X3: Collapsing one-element lists

Say I have a (simplified) recursive grammar like this: OrExpr := AndExpr % "or" AndExpr := Term % "and" Term := ParenExpr | String ParenExpr := '(' >> OrExpr >> ')' String := lexeme['"' >> *(char_ - '"') >> '"'] So this works, but the…
Robert Fraser
  • 10,649
  • 8
  • 69
  • 93