diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2016-08-05 15:03:14 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2016-08-05 15:03:14 +0200 |
commit | 535d856a39b177642724bcfe6009985bf4262dbd (patch) | |
tree | 4162702b31cff209a859ad22de426c7b83d38830 /core/kicad.cpp | |
parent | ff87ea9045a6e0979311ae7b25055d6b53b0a13d (diff) | |
download | kicad-utils-535d856a39b177642724bcfe6009985bf4262dbd.tar.gz kicad-utils-535d856a39b177642724bcfe6009985bf4262dbd.tar.bz2 kicad-utils-535d856a39b177642724bcfe6009985bf4262dbd.tar.xz kicad-utils-535d856a39b177642724bcfe6009985bf4262dbd.zip |
o More flexible parsing. More rules needs to be updated.
Diffstat (limited to 'core/kicad.cpp')
-rw-r--r-- | core/kicad.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/core/kicad.cpp b/core/kicad.cpp index 1a6ca2f..a553b62 100644 --- a/core/kicad.cpp +++ b/core/kicad.cpp @@ -112,12 +112,22 @@ public: nodes.emplace_back(ref, pin); } + template<typename T> + static + Ref<T> onlyOne(const vector<Ref<T>> items, const antlr4::ParserRuleContext *ctx, const string &parent, const string &item) { + if(items.size() != 1) { + throw kicad_parse_exception("Bad netlist: expected only one " + item + " inside of " + parent + ". Line: " + to_string(ctx->start->getLine()) + ":" + to_string(ctx->start->getCharPositionInLine())); + } + return items[0]; + } + virtual void exitComponent(KicadNetParser::ComponentContext *ctx) override { - auto ref = strings.get(ctx->ref()->string()); - auto value = strings.get(ctx->value()->string()); + auto ref = strings.get(onlyOne(ctx->ref(), ctx, "comp", "ref")->string()); + auto value = strings.get(onlyOne(ctx->value(), ctx, "comp", "value")->string()); + auto libsource = onlyOne(ctx->libsource(), ctx, "comp", "libsource"); - lib_source ls{strings.get(ctx->libsource()->lib()->string()), - strings.get(ctx->libsource()->part()->string())}; + lib_source ls{strings.get(libsource->lib()->string()), + strings.get(libsource->part()->string())}; components.emplace_back(ref, value, ls); } |