Commit 0683cbf8 by Jesse Beder

Mostly finished refactoring the scalar scanning.

parent 5f8252ee
......@@ -11,10 +11,10 @@ namespace YAML
class IllegalMapKey: public Exception {};
class IllegalMapValue: public Exception {};
class IllegalScalar: public Exception {};
class IllegalTabInScalar: public Exception {};
class IllegalTabInIndentation: public Exception {};
class IllegalFlowEnd: public Exception {};
class DocIndicatorInQuote: public Exception {};
class EOFInQuote: public Exception {};
class IllegalDocIndicator: public Exception {};
class IllegalEOF: public Exception {};
class RequiredSimpleKeyNotFound: public Exception {};
class ZeroIndentationInBlockScalar: public Exception {};
class UnexpectedCharacterInBlockScalar: public Exception {};
......
......@@ -25,6 +25,7 @@ namespace YAML
const RegEx DocStart = RegEx("---") + (BlankOrBreak || RegEx(EOF) || RegEx());
const RegEx DocEnd = RegEx("...") + (BlankOrBreak || RegEx(EOF) || RegEx());
const RegEx DocIndicator = DocStart || DocEnd;
const RegEx BlockEntry = RegEx('-') + (BlankOrBreak || RegEx(EOF));
const RegEx Key = RegEx('?'),
KeyInFlow = RegEx('?') + BlankOrBreak;
......
......@@ -19,19 +19,20 @@ namespace YAML
~Scanner();
Token *GetNextToken();
void Scan();
private:
// scanning
void ScanNextToken();
void ScanToNextToken();
Token *PushIndentTo(int column, bool sequence);
void PopIndentTo(int column);
// checking input
void InsertSimpleKey();
bool VerifySimpleKey();
void VerifyAllSimpleKeys();
void Scan();
private:
bool IsWhitespaceToBeEaten(char ch);
bool IsDocumentStart();
bool IsDocumentEnd();
......
......@@ -7,35 +7,29 @@
namespace YAML
{
enum CHOMP { STRIP = -1, CLIP, KEEP };
enum ACTION { NONE, BREAK, THROW };
struct ScanScalarInfo {
ScanScalarInfo(): eatEnd(false), indent(0), eatLeadingWhitespace(0), escape(0), fold(false), trimTrailingSpaces(0), chomp(CLIP) {}
ScanScalarInfo(): eatEnd(false), indent(0), detectIndent(false), eatLeadingWhitespace(0), escape(0), fold(false),
trimTrailingSpaces(0), chomp(CLIP), onDocIndicator(NONE), onTabInIndentation(NONE), leadingSpaces(false) {}
// input:
RegEx end; // what condition ends this scalar?
bool eatEnd; // should we eat that condition when we see it?
int indent; // what level of indentation should be eaten and ignored?
bool detectIndent; // should we try to autodetect the indent?
bool eatLeadingWhitespace; // should we continue eating this delicious indentation after 'indent' spaces?
char escape; // what character do we escape on (i.e., slash or single quote) (0 for none)
bool fold; // do we fold line ends?
bool trimTrailingSpaces; // do we remove all trailing spaces (at the very end)
CHOMP chomp; // do we strip, clip, or keep trailing newlines (at the very end)
// Note: strip means kill all, clip means keep at most one, keep means keep all
};
void GetBlockIndentation(Stream& INPUT, int& indent, std::string& breaks, int topIndent);
std::string ScanScalar(Stream& INPUT, ScanScalarInfo info);
struct WhitespaceInfo {
WhitespaceInfo();
ACTION onDocIndicator; // what do we do if we see a document indicator?
ACTION onTabInIndentation; // what do we do if we see a tab where we should be seeing indentation spaces
void SetChompers(char ch);
void AddBlank(char ch);
void AddBreak(const std::string& line);
std::string Join(bool lastline = false);
bool leadingBlanks;
bool fold;
std::string whitespace, leadingBreaks, trailingBreaks;
int chomp, increment;
// output:
bool leadingSpaces;
};
std::string ScanScalar(Stream& INPUT, ScanScalarInfo& info);
}
---
- "quoted scalar\twith a tab\nand a newline"
- 'This is Jesse''s single quote!'
- |
here's a literal:
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
return 0;
}
- key1: value1
key2: value2
\ No newline at end of file
- here's a key: value
here's the first block: |
after the block: value
and here's a block: |-
What's going on?
How are you doing?
Here's some code:
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
}
I'm doing fine!
and last key: value
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment