LL parser framework represents parsers directly as EBNF grammars in inlined C++14
Questions tagged [boost-spirit-x3]
281 questions
5
votes
0 answers
Boost Spirit X3: "Attribute does not have the expected size," but why does it care?
I am trying to write a parser with Spirit X3, but I haven't gotten very far because I'm running into a compilation error that I can't figure out. I think I know what the compiler is complaining about, but what I don't understand is why it cares. The…

Willis Blackburn
- 8,068
- 19
- 36
5
votes
1 answer
How do I get this recursive rule to work?
I want to parse (in first instance, recognize only, keeping symbols) LaTeX math. Right now, I'm having trouble with the super and subscripts, in combination with curly braces (e.g. a^{bc} and combinations thereof, I've got the basic a^b working just…

rubenvb
- 74,642
- 33
- 187
- 332
5
votes
1 answer
error handling and annotation in Boost.Spirit X3
What is the logic under using boost::spirit::x3::position_tagged as base class for some AST nodes (how to choose which should be tagged, e.g. for C-like language?) and other constructions, used in rule ID definition, like:
struct…

Tomilov Anatoliy
- 15,657
- 10
- 64
- 169
4
votes
2 answers
Boost Spirit X3: Parsing (some) whitespace into an enum
I have a parser in which I want to capture certain types of whitespace as enum values and preserve the spaces for the "text" values.
My whitespace parser is pretty basic (Note: I've only added the pipe character here for test/dev purposes):
struct…

Addy
- 2,414
- 1
- 23
- 43
4
votes
1 answer
Boost spirit x3 - lazy parser
Does latest boost::spirit::x3 implement lazy parser? I have found it in documentation but cannot find it in source code on github and can't use boost::spirit::x3::lazy. Am I missing something or lazy parsers were removed from spirit or renamed or…

bartop
- 9,971
- 1
- 23
- 54
4
votes
1 answer
Boost Spirit x3: parse into structs
From the Boost Spirit X3 tutorial:
First, let's create a struct representing an employee:
namespace client { namespace ast
{
struct employee
{
int age;
std::string surname;
std::string forename;
double salary;
…

Filippo
- 361
- 1
- 5
- 16
4
votes
2 answers
Boost.x3: attribute accumulates between alternatives
I have a parser for parsing an Identifier like foo, bar, baz and one for parsing also nested identifiers like foo::bar, foo::bar.baz, foo::bar.baz.baham
They both parse into the same ast struct, which looks like this:
struct identifier :…

Exagon
- 4,798
- 6
- 25
- 53
4
votes
1 answer
parse into vector using boost::spirit::x3
This is a follow-up question to my previous one regarding boost::spirit::x3 and boost::string_view.
While I can parse into a std::vector (live example), parsing into a std::vector fails with the following compile…

m.s.
- 16,063
- 7
- 53
- 88
4
votes
1 answer
Matching a sequence of two integers into an `std::pair`
I'm trying to use Boost.Sprit x3 to match a sequence of two integers into an std::pair. Judging by the documentation, the following code should compile:
#include
#include
#include…

Vittorio Romeo
- 90,666
- 33
- 258
- 416
4
votes
1 answer
Compiler difference: Extending x3::variant requires definiton of copy constrctor, copy assign operator, and default constructor with gcc but not clang
I adapted an example from the x3 documentation (http://ciere.com/cppnow15/x3_docs/spirit/tutorials/rexpr.html) to parse a simple binary prefix notation grammar, and I found that I needed to define the copy con, copy assign op, and the default…

golvok
- 1,015
- 12
- 25
4
votes
2 answers
parsing identifiers except keywords
I am struggeling writing a identifier parser, which parses a alphanum string which is not a keyword.
the keywords are all in a table:
struct keywords_t : x3::symbols {
keywords_t() {
add("for", x3::unused)
…

Exagon
- 4,798
- 6
- 25
- 53
4
votes
2 answers
boost spirit x3 int32 | double_ fails to parse double
I am trying to write a parser, which parses either a int32_t or a double.
As a first try I wrote this parser:
const auto int_or_double = boost::spirit::x3::int32 | boost::spirit::x3::double_;
which I expect to get back a boost::variant

Exagon
- 4,798
- 6
- 25
- 53
4
votes
1 answer
Attributes from Boost.Spirit grammar: error from std:vector of boost::variant
I got a working parser for reading position descriptions for a board game (international draughts, official grammar):
#include
#include
namespace x3 = boost::spirit::x3;
auto const colon = x3::lit(':');
auto…

TemplateRex
- 69,038
- 19
- 164
- 304
4
votes
1 answer
Defining skipper in separate translation unit using Boost.Spirit X3
How to define skipper grammar in separate translation unit?
What is the type of output attribute should be? Or can I simply specify boost::spirit::x3::unused_type as Attribute template parameter to boost::spirit::x3::rule template class for skipper…

Tomilov Anatoliy
- 15,657
- 10
- 64
- 169
3
votes
2 answers
Spirit X3: Rule that parses a single character and generates a string
Is it possible to create a rule in Spirit X3 that parses a single character and generates a string?
I'd like to use this in the context of a parser for version numbers, where each numeric identifier can be either a single digit, or a non-zero digit…

Romain Deterre
- 546
- 4
- 16