Commits

David Mugnai  committed 385b2e6

slam: parser pass attributes to the Tag constructor

  • Participants
  • Parent commits cced286

Comments (0)

Files changed (3)

File slam/ast.cpp

 Node::~Node() {}
 
 Tag::Tag() : Tag{""} {}
-Tag::Tag(string const& name) : name(name) {}
+Tag::Tag(string const& name) : Tag{name, {}} {}
+Tag::Tag(string const& name, std::map<string, string> const& attribs) : name(name), attribs(attribs) {}
 
 void Tag::apply(slam::io::Renderer* r) const {
     if(this->type == Tag::TagType::standard || this->children.size() > 0) {
 
     Tag();
     Tag(string const&);
+    Tag(string const&, std::map<string, string> const&);
 
     void apply(slam::io::Renderer*) const;
 };

File slam/parser.h

 
         node %= (tag >> (qi::eol | qi::eoi));
 
-        tag = identifier[
-            _val = bind([](string const& name) -> Tag* {
-                return new Tag{name};
-            }, _1)
+        tag = (identifier >> -attributes_list) [
+            _val = bind([](string const& name, boost::optional<std::map<string, string>> const& attrs) -> Tag* {
+                return new Tag{name, attrs ? *attrs : std::map<string, string>() };
+            }, _1, qi::_2)
         ];
 
         // matches at least _r1 spaces -> expose the number of matched spaces