Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Regression fixes #155

Merged
merged 9 commits into from
Aug 5, 2014
Merged

Regression fixes #155

merged 9 commits into from
Aug 5, 2014

Conversation

pksunkara
Copy link
Contributor

There is only more issue left to fix which I encountered yesterday. Meanwhile please review.

@pksunkara
Copy link
Contributor Author

Actually, I wanted to ask you about what to do for that issue. https://app.apiary.io/sandbox22/editor

@zdne
Copy link
Contributor

zdne commented Aug 1, 2014

Actually, I wanted to ask you about what to do for that issue. https://app.apiary.io/sandbox22/editor

What is the issue? Please provide concise information when asking such a question.

@zdne
Copy link
Contributor

zdne commented Aug 2, 2014

Regarding Unexpected nodes with keywords do not stop the parsing:

Objective

Break parsing on keyword-defined section nodes that are not nested to the current node section.

Break current section parser's parsing on keyword-defining section nodes that are not nested to the current node section.

Solution

Every section must define it's nested sections recursively (that is – including nested sections nested sections)

Code

  1. SectionProcessorBase should return list of nested section types like so:

    // TODO:
    typedef std::vector<SectionType> NestedSections;
    static NestedSections nestedSections() {
        return NestedSections();
    }
  2. Every section processor must implement nestedSections() unless it has no nested sections. The implementation MUST call nested sections nestedSections(). Example for Blueprint parser:

    static NestedTypes nestedSectionTypes() {
        NestedTypes types;
    
        // Resource Group & descendants
        types.push_back(ResourceGroupSectionType);
        NestedTypes sections = SectionProcessor<ResourceGroup>::nestedSections();
        types.insert(types.end(), sections.begin(), sections.end());
    
        // Resource & descendants            
        types.push_back(ResourceSectionType);
        sections = SectionProcessor<ResourceGroup>::nestedSections();
        types.insert(types.end(), sections.begin(), sections.end());
    
        return types;
    }
  3. HasSectionKeywordSignature() should be changed into a function returing the type of keyword signature section:

    NOTE: The code is most likely not complete (does not contain all the parsers)

    SectionType snowcrash::SectionKeywordSignature(const mdp::MarkdownNodeIterator& node)
    {
        SectionType type = UndefinedSectionType;
        if ((type = SectionProcessor<Headers>::sectionType(node)) != UndefinedSectionType)
            return type;
    
        if ((type = SectionProcessor<Asset>::sectionType(node)) != UndefinedSectionType)
            return type;
    
        if ((type = SectionProcessor<Values>::sectionType(node)) != UndefinedSectionType)
            return type;
    
        if ((type = SectionProcessor<Parameters>::sectionType(node)) != UndefinedSectionType)
            return type;
    
        if ((type = SectionProcessor<Action>::sectionType(node)) != UndefinedSectionType)
            return type;
    
        if ((type = SectionProcessor<Resource>::sectionType(node)) != UndefinedSectionType)
            return type;
    
        return type;
    }
  4. isDescriptionNode() shall be changed to treat nested sections' nested keyword defined sections as descriptions:

    static bool isDescriptionNode(const MarkdownNodeIterator& node,
                                  const MarkdownNodes& siblings,
                                  const T& context,
                                  SectionType sectionType) {
    
        if (isContentNode(node, sectionType))
            return false;
    
        if (nestedSectionType(node, siblings, context) != UndefinedSectionType)
            return false;
    
        SectionType keywordSectionType = SectionKeywordSignature(node);
        if (keywordSectionType == UndefinedSectionType)
            return true;
    
        NestedTypes nestedTypes = nestedSectionTypes();
        if (std::find(nestedTypes.begin(), nestedTypes.end(), keywordSectionType) != nestedTypes.end()) {
            // Node is a keyword defined section defined in one of the nested sections
            // Treat it as a description
            return true;
        }
    
        // Node is a keyword defined section not in nested sections -> break parsing
        return false;
    }

NOTE: The code snippets shown above are to demostrate proof of concenpt – feel free to shuffle and rename variables, types and function names as weel as adding any further improvements.

The test accompanying this is:

TEST_CASE("Parsing unexpected blocks", "[blueprint][now]")
{
    mdp::ByteBuffer source = \
    "FORMAT: 1A\n"\
    "\n"\
    "# S\n"\
    "\n"\
    "Hello\n"\
    "\n"\
    "+ Response\n"\
    "\n"\
    "Moar text\n"\
    "\n"\
    "# GET /\n";

    Blueprint blueprint;
    Report report;

    parse(source, 0, report, blueprint);

    REQUIRE(report.error.code == Error::OK);
    REQUIRE(report.warnings.size() == 1); // no response
    REQUIRE(report.warnings[0].code == EmptyDefinitionWarning);

    REQUIRE(blueprint.name == "S");
    REQUIRE(blueprint.description == "Hello\n\n+ Response\n\nMoar text\n\n");

    REQUIRE(blueprint.metadata.size() == 1);
    REQUIRE(blueprint.metadata[0].first == "FORMAT");
    REQUIRE(blueprint.metadata[0].second == "1A");

    REQUIRE(blueprint.resourceGroups.size() == 1);
    REQUIRE(blueprint.resourceGroups[0].resources.size() == 1);
    REQUIRE(blueprint.resourceGroups[0].resources[0].actions.size() == 1);
    REQUIRE(blueprint.resourceGroups[0].resources[0].uriTemplate == "/");
    REQUIRE(blueprint.resourceGroups[0].resources[0].actions[0].method == "GET");
}

@zdne
Copy link
Contributor

zdne commented Aug 2, 2014

It would be good to issue a warning when parser treats a keyword defined section as a description. For this the return value of isDescriptionNode() can be changed to signalize "keyword defined section node that is parsed as decryption" and the SectionParser::parse() should issue a warning ...

zdne added a commit that referenced this pull request Aug 5, 2014
@zdne zdne merged commit ede5d76 into shared/refactor-integration Aug 5, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants