francoischabot / abulafia Goto Github PK
View Code? Open in Web Editor NEWA header-only C++ parsing framework
Home Page: https://francoischabot.github.io/abulafia/
License: Boost Software License 1.0
A header-only C++ parsing framework
Home Page: https://francoischabot.github.io/abulafia/
License: Boost Software License 1.0
Add a mechanism to "tag" the dst for the entire pattern hierarchy under it. This will allow semantic actions to read and assign them.
This will require adding a second parameter to the semantic action, which will be an opaque type with the bound dst reference as member.
Having this allows us to write operator precedence parsers in a very nice and manageable way:
auto binop = [](std::tuple<char,int> v, auto p) -> void {
auto lhs = p.bound_dst;
auto rhs = get<1>(v);
switch(get<0>(v)) {
case '+':
p.bound_dst = lhs + rhs;
break;
case '-':
p.bound_dst = lhs - rhs;
break;
// etc...
}
};
auto muldiv = abu::bind_dst(
primary[assign] >> *(char_("+-*/") >> primary)[binop]
);
*(a|*b) needs to parse into a string, so by extension **a must also.
However **a should also parse into vector, without any pattern-side annotation.
We need value semantics, and the reference is getting in the way. This will also hopefully help us moe to a more composition, rather than inheritance, model.
The problematic parts are:
Both could probably be addressed with a statically sized allocator with a pre-defined maximal depth,
TEST(test_sequence, compose_vector) {
auto pattern = Int<10, 2, 2>() >> *Int<10, 1, 1>();
std::vector<int> dst;
auto status = parse(pattern, std::string("11222333"), dst);
EXPECT_EQ(result::SUCCESS, status);
EXPECT_EQ(std::vector<int>({11,222,333}), dst);
}
Not necessarily identical to qi's. Let's take our time and consider the implications.
Contexts serve many purposes, but as far as users are concerned at the moment, they only serve to choose the data source. We should consider renamming the API.
Abulafia does a few internal memory allocations, we should let users choose where the memory comes from.
Is there a particular reason why abu::result
is properly spelled in the example and CamelCase in result.h
?
Why not use std::error_code
? It makes testing for errors and handling them easier.
if (const auto ec = abu::parse(data.begin(), data.end(), ignoring_whitespace, dst)) {
for (auto v : dst) { // it has to be a value, and not a const reference for this?
std::cout << v << std::endl;
}
} else {
throw std::system_error(ec);
}
The unsigned ints and size_t were chosen out of habit, but regular ints will be more compiler friendly.
Resumability is a big feature of Abulafia, not having a resumable context out of the box is pretty silly.
We need value semantics at times, and the reference is getting seriously in the way.
The interface with patterns/parsers is fine, but it's clunky to use on the user side.
This will provide a more fleshed-out point of reference.
Currently, invoking a constructor must be done through semantic action.
This should work:
TEST(test_sequence, sequence_into_user_struct) {
struct xyz {
xyz(int x, int y, int z)
: x_(x), y_(y), z_(z) {}
int x_;
int y_;
int z_;
};
auto pattern = int_ >> lit('-') >> int_ >> lit('-') >> int_;
xyz dst{ 0, 0, 0 };
xyz expected{1, 2, 3};
auto status = parse(pattern, std::string("1-2-3"), dst);
EXPECT_EQ(result::SUCCESS, status);
EXPECT_EQ(expected, dst);
}
as<>() is a bad name for the interface. It's leaking the abstraction. Since its only usage is for constructor selection, its name should reflect that.
https://travis-ci.org/FrancoisChabot/abulafia/builds/285815946
It's not happening on my machine so I'm not sure what's going on here..
There is really bad test coverage of the various transform()
functions, and some of them are probably wrong.
Adding another test to the standard harness that exercises this code path will help a lot.
template<typename T>
auto as_recur(T const& pat) {
abu::Recur<struct as_recur_t> as_recur;
ABU_Recur_define(as_recur, as_recur_t, pat);
return as_recur;
}
This causes the following error (in GCC):
use of 'auto abu::weaken_recur(const PAT_T&) [...]' before deduction of 'auto'
ATTR_T is gone entirely from abulafia as a concept. It's still in recur to identify wether it's a nil or value parser, but that's it.
At best, we might be able to infer that information. At worst, we need to change the parameter to an enum, or a tag type.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.