Skip to content

Commit

Permalink
Allow malformed GFA files: allow trailing tab for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
asl committed Oct 15, 2022
1 parent 544c9d6 commit 040eca2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions io/cigar.inl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <lexy/callback.hpp> // lexy callbacks
#include <lexy/grammar.hpp>

#include <string>

namespace cigar::grammar {
namespace dsl = lexy::dsl;

Expand Down Expand Up @@ -61,13 +63,15 @@ namespace cigar::grammar {
};

struct tag_name : lexy::token_production {
static constexpr auto name = "tag name";

static constexpr auto rule = dsl::capture(dsl::token(dsl::ascii::alpha + dsl::ascii::alpha_digit));
static constexpr auto value = lexy::as_string<std::string_view>;
};

static constexpr auto rule = [] {
auto colon = dsl::lit_c<':'>;
return dsl::p < tag_name > +colon +
return dsl::p<tag_name> >> colon +
(
dsl::capture(LEXY_LIT("A")) >> colon + dsl::p < tag_character > |
dsl::capture(LEXY_LIT("i")) >> colon + dsl::p < tag_integer > |
Expand Down Expand Up @@ -114,10 +118,12 @@ namespace cigar::grammar {
static constexpr auto tab = dsl::lit_c<'\t'>;

struct opt_tags {
static constexpr auto name = "tags";

static constexpr auto rule = [] {
auto tags = dsl::list(dsl::p<tag>, dsl::sep(tab));
auto tags = dsl::list(dsl::p<tag>, dsl::trailing_sep(tab));
return dsl::eof | (tab >> tags + dsl::eof);
}();
static constexpr auto value = lexy::as_list<std::vector<cigar::tag>>;
};
}
}

0 comments on commit 040eca2

Please sign in to comment.