From 8e27a8e87344e187d67407a37c8818f91ed016fa Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 9 Apr 2015 12:11:20 +0200 Subject: handled output transformation of syntax descriptors (except for special tokens). --- src/plugins/xml/XmlOutput.cpp | 87 +++++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/plugins/xml/XmlOutput.cpp b/src/plugins/xml/XmlOutput.cpp index 5615bba..1bc1ab7 100644 --- a/src/plugins/xml/XmlOutput.cpp +++ b/src/plugins/xml/XmlOutput.cpp @@ -220,27 +220,24 @@ static std::string getStructuredClassRef(Handle referencing, return res; } -static Rooted transformSyntaxDescriptor(Handle parent, - SyntaxDescriptor &stx, - TransformParams &P) +static Rooted transformTokenDescriptor(Handle parent, + const TokenDescriptor &descr, + const std::string &tagName, + TransformParams &P) { - Rooted syntax{new Element(P.mgr, parent, "syntax")}; - if (stx.open != Tokens::Empty) { - Rooted open{new Element(P.mgr, syntax, "open")}; - syntax->addChild(open); - // TODO: Transform token. - } - if (stx.close != Tokens::Empty) { - Rooted close{new Element(P.mgr, syntax, "close")}; - syntax->addChild(close); - // TODO: Transform token. + if (descr.isEmpty()) { + return nullptr; } - if (stx.shortForm != Tokens::Empty) { - Rooted shortForm{new Element(P.mgr, syntax, "short")}; - syntax->addChild(shortForm); - // TODO: Transform token. + Rooted tag{new Element(P.mgr, parent, tagName)}; + std::string str; + if (descr.special) { + // TODO: Handle this case + } else { + str = descr.token; } - return syntax; + Rooted token{new Text(P.mgr, parent, str)}; + tag->addChild(token); + return tag; } static Rooted transformFieldDescriptor(Handle parent, @@ -264,9 +261,20 @@ static Rooted transformFieldDescriptor(Handle parent, // create the XML element itself. Rooted fieldDescriptor{new Element(P.mgr, parent, tagName, attrs)}; // translate the syntax. - SyntaxDescriptor stx = fd->getSyntaxDescriptor(); - Rooted syntax = transformSyntaxDescriptor(fieldDescriptor, stx, P); + Rooted syntax{new Element(P.mgr, parent, "syntax")}; fieldDescriptor->addChild(syntax); + { + Rooted open = + transformTokenDescriptor(syntax, fd->getOpenToken(), "open", P); + if (open != nullptr) { + syntax->addChild(open); + } + Rooted close = + transformTokenDescriptor(syntax, fd->getCloseToken(), "close", P); + if (close != nullptr) { + syntax->addChild(close); + } + } // translate the child references. for (auto s : fd->getChildren()) { std::string ref = @@ -278,17 +286,24 @@ static Rooted transformFieldDescriptor(Handle parent, return fieldDescriptor; } -static void transformDescriptor(Handle elem, Handle d, - TransformParams &P) +static void transformDescriptor(Handle elem, Handle syntax, + Handle d, TransformParams &P) { // add name. addNameAttribute(d, elem->getAttributes()); // TODO: transform the attributes descriptor. - // transform the syntactic sugar descriptors + // transform the syntactic sugar description. { - SyntaxDescriptor stx = d->getSyntaxDescriptor(); - Rooted syntax = transformSyntaxDescriptor(elem, stx, P); - elem->addChild(syntax); + Rooted open = + transformTokenDescriptor(syntax, d->getOpenToken(), "open", P); + if (open != nullptr) { + syntax->addChild(open); + } + Rooted close = + transformTokenDescriptor(syntax, d->getCloseToken(), "close", P); + if (close != nullptr) { + syntax->addChild(close); + } } // transform all field descriptors. for (auto fd : d->getFieldDescriptors()) { @@ -302,6 +317,7 @@ static Rooted transformStructuredClass(Handle parent, TransformParams &P) { Rooted structuredClass{new Element(P.mgr, parent, "struct")}; + // transform the specific StructuredClass properties. structuredClass->getAttributes().emplace( "cardinality", toString(Variant(s->getCardinality()), P)); if (s->getSuperclass() != nullptr) { @@ -312,7 +328,20 @@ static Rooted transformStructuredClass(Handle parent, "transparent", getStringForBool(s->isTransparent())); structuredClass->getAttributes().emplace( "root", getStringForBool(s->hasRootPermission())); - transformDescriptor(structuredClass, s, P); + + // transform the syntactic sugar descriptors + Rooted syntax{new Element(P.mgr, structuredClass, "syntax")}; + structuredClass->addChild(syntax); + { + Rooted shortForm = + transformTokenDescriptor(syntax, s->getShortToken(), "short", P); + if (shortForm != nullptr) { + syntax->addChild(shortForm); + } + } + + // transform the descriptor properties + transformDescriptor(structuredClass, syntax, s, P); return structuredClass; } @@ -321,7 +350,9 @@ static Rooted transformAnnotationClass(Handle parent, TransformParams &P) { Rooted annotationClass{new Element(P.mgr, parent, "struct")}; - transformDescriptor(annotationClass, a, P); + Rooted syntax{new Element(P.mgr, annotationClass, "syntax")}; + annotationClass->addChild(syntax); + transformDescriptor(annotationClass, syntax, a, P); return annotationClass; } -- cgit v1.2.3