Re: How to parse blocks lead by spaces

Dan Bloomquist <[email protected]> Sun, 25 Mar 2018 19:07:20 -0700
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
Seth wrote:
>
Thanks Seth,
I've gotten over the front end, it just works. I won't have to worry 
about scope like that. Especially as most Scope has an EndScope.

But here I am learning how to get the data to the attribute(s). I've 
decided to keep the TextStyle in a set here is what I've done so far 
with testing. I'll take it to the bigger program when I get it.

~~~~~~~~~~~~~~~~~~~
struct Dual
{
     std::string name;
     int num;
     bool operator < (const Dual& d) { return d.name < name; }
};
BOOST_FUSION_ADAPT_STRUCT(Dual,
     name,
     num
)

namespace x3 = boost::spirit::x3;
x3::rule<class pair_rule, std::pair<std::string, std::string>> const 
pair_rule("pair");
x3::rule<class string_rule, std::string> const string_rule("string");

auto const bare_string
= x3::lexeme[+x3::char_("a-zA-Z0-9$_.\\*?+-")]; // bare string taken 
from old "param" rule

auto const string_rule_def = x3::lexeme[*x3::alnum];
auto const pair_rule_def = string_rule > x3::lit('=') >> string_rule;

// ........................................
#define DEF_RULE( RuleName, Attr ) static auto const RuleName = 
x3::rule<struct Attr##_def, Attr>( #RuleName )

DEF_RULE(dual_rule, Dual) = bare_string > x3::int_;

BOOST_SPIRIT_DEFINE(pair_rule, string_rule, dual_rule);



int main()
{

     std::string str("mark1 name 123, mark2 and 234");
     auto begin = str.begin();
     auto end = str.end();

//this just parses a Dual
     Dual aDual;
     //auto testd = x3::phrase_parse( begin, end, dual_rule, x3::space, 
aDual );

//this works too and stores in a map
     std::unordered_map< std::string, Dual > container;
     auto testb= x3::phrase_parse(begin, end, +(string_rule >> dual_rule 
 >> -x3::lit(',') ), x3::space, container);

//and alas, but I'll keep at it, this doesn't compile.
     std::set< Dual > d_set;
     auto testc = x3::phrase_parse(begin, end, +dual_rule , x3::space, 
d_set);

     return 0;

}
> Off-Topic:
>
>> What I'm out to do is parse a decompressed BXL file into my object
> It seems a cruel joke that a proprietary firm convinced everyone to use
> their "vendor neutral" file format when that format seems not be freely
> documented, and people need to use the "Free" reader tools and the
> (surprise) paid tooling to create/manipulate these files.
>
> I haven't been able to find a specification, do you have one?

No, and I had only recently gotten lucky to find a decompressor written 
in Java, that I converted to C. But the data follows well with what I've 
seen with TinyCAD, KiCad, and others. Well enough it will work out. I'll 
know better when I start to show it in a visualizer. Yes, they seem to 
have all the big guys using their tools to create the docs. And their 
tool is rather a pain. The later versions won't export in XML, but I 
still have a 6.x that does. On the other hand, they now export to KiCad 
but still no TinyCAD so I'll keep at it.

Best, Dan.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot