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

Commit

Permalink
Do not complain about indentation if it is a symbol reference
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Jul 28, 2014
1 parent 4916e3b commit 6fe41fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/CodeBlockUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ namespace snowcrash {
// Other blocks, process & warn
content += mdp::MapBytesRangeSet(node->sourceMap, pd.sourceData);

if (checkSymbol(content)) {
return;
}

// WARN: Not a preformatted code block
size_t level = codeBlockIndentationLevel(pd.parentSectionContext());
std::stringstream ss;
Expand Down Expand Up @@ -95,9 +99,14 @@ namespace snowcrash {
content += remainingContent;
content += "\n";

if (checkSymbol(content)) {
return;
}

// WARN: Not a preformatted code block but multiline signature
size_t level = codeBlockIndentationLevel(pd.parentSectionContext());
std::stringstream ss;

ss << SectionName(pd.sectionContext());
ss << " is expected to be a pre-formatted code block, separate it by a newline and ";
ss << "indent every of its line by ";
Expand All @@ -109,6 +118,16 @@ namespace snowcrash {
sourceMap));
}

static bool checkSymbol(const mdp::ByteBuffer& content) {

This comment has been minimized.

Copy link
@zdne

zdne Aug 1, 2014

Contributor

Please add source code comment – explanation of the purpose of this function (what it does)


mdp::ByteBuffer data = content;
SymbolName symbol;

TrimString(data);

return GetSymbolReference(data, symbol);
}

/**
* \brief Check for potential excessive indentation of a list section
* \return True if code block contains a recognized list section, false otherwise.
Expand Down
2 changes: 1 addition & 1 deletion src/PayloadParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ namespace snowcrash {
Payload& out) {

mdp::ByteBuffer content;
CodeBlockUtility::contentAsCodeBlock(node, pd, report, content);

if (!out.symbol.empty()) {
//WARN: ignoring extraneous content after symbol reference
Expand All @@ -97,6 +96,7 @@ namespace snowcrash {
IgnoringWarning,
sourceMap));
} else {
CodeBlockUtility::contentAsCodeBlock(node, pd, report, content);
out.body += content;

parseSymbolReference(pd, report, out);
Expand Down
4 changes: 2 additions & 2 deletions test/test-PayloadParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ TEST_CASE("Parse inline payload with symbol reference", "[payload]")
SectionParserHelper<Payload, PayloadParser>::parse(SymbolFixture, RequestBodySectionType, report, payload, symbols);

REQUIRE(report.error.code == Error::OK);
REQUIRE(report.warnings.size() == 1);
REQUIRE(report.warnings.size() == 0);

REQUIRE(payload.name.empty());
REQUIRE(payload.description == "Foo");
Expand All @@ -278,7 +278,7 @@ TEST_CASE("Parse inline payload with symbol reference with foreign content", "[p
SectionParserHelper<Payload, PayloadParser>::parse(source, RequestBodySectionType, report, payload, symbols);

REQUIRE(report.error.code == Error::OK);
REQUIRE(report.warnings.size() == 3); // ignoring foreign entry

This comment has been minimized.

Copy link
@zdne

zdne Aug 1, 2014

Contributor

Minus one warning for the indentation, but where did the other warning go?

REQUIRE(report.warnings.size() == 1); // ignoring foreign entry

REQUIRE(payload.name.empty());
REQUIRE(payload.description == "Foo");
Expand Down

1 comment on commit 6fe41fb

@zdne
Copy link
Contributor

@zdne zdne commented on 6fe41fb Aug 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again for a code review, and communication clarity – it would help if you provide a snippet of a blueprint and summary of the behavior pre and after behavior

Please sign in to comment.