YAML: Implement block scalar parsing.

This commit implements the parsing of YAML block scalars.
Some code existed for it before, but it couldn't parse block
scalars.

This commit adds a new yaml node type to represent the block
scalar values. 

This commit also deletes the 'spec-09-27' and 'spec-09-28' tests
as they are identical to the test file 'spec-09-26'.

This commit introduces 3 new utility functions to the YAML scanner
class: `skip_s_space`, `advanceWhile` and `consumeLineBreakIfPresent`.

Reviewers: Duncan P. N. Exon Smith

Differential Revision: http://reviews.llvm.org/D9503


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237314 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alex Lorenz
2015-05-13 23:10:51 +00:00
parent 7c001dac7a
commit b96942f6ec
15 changed files with 363 additions and 59 deletions

View File

@ -107,6 +107,7 @@ public:
enum NodeKind {
NK_Null,
NK_Scalar,
NK_BlockScalar,
NK_KeyValue,
NK_Mapping,
NK_Sequence,
@ -222,6 +223,36 @@ private:
SmallVectorImpl<char> &Storage) const;
};
/// \brief A block scalar node is an opaque datum that can be presented as a
/// series of zero or more Unicode scalar values.
///
/// Example:
/// |
/// Hello
/// World
class BlockScalarNode : public Node {
void anchor() override;
public:
BlockScalarNode(std::unique_ptr<Document> &D, StringRef Anchor, StringRef Tag,
std::string &Value, StringRef RawVal)
: Node(NK_BlockScalar, D, Anchor, Tag), Value(std::move(Value)) {
SMLoc Start = SMLoc::getFromPointer(RawVal.begin());
SMLoc End = SMLoc::getFromPointer(RawVal.end());
SourceRange = SMRange(Start, End);
}
/// \brief Gets the value of this node as a StringRef.
StringRef getValue() const { return Value; }
static inline bool classof(const Node *N) {
return N->getType() == NK_BlockScalar;
}
private:
std::string Value;
};
/// \brief A key and value pair. While not technically a Node under the YAML
/// representation graph, it is easier to treat them this way.
///