Wrote a simplified regular expression parser to make life easier (it only does single matches; i.e., no one-or-more matches, etc.).

Fixed some of the whitespace/line break matching.
This commit is contained in:
Jesse Beder 2008-06-27 08:20:41 +00:00
parent 873dbc2421
commit 4e435b1321
7 changed files with 277 additions and 75 deletions

View file

@ -5,22 +5,49 @@
#include <queue>
#include <stack>
#include <set>
#include "regex.h"
namespace YAML
{
class Token;
namespace Exp
{
// misc
const RegEx Blank = RegEx(' ') || RegEx('\t');
const RegEx Break = RegEx('\n');
const RegEx BlankOrBreak = Blank || Break;
// actual tags
const RegEx DocStart = RegEx("---") + (BlankOrBreak || RegEx(EOF) || RegEx());
const RegEx DocEnd = RegEx("...") + (BlankOrBreak || RegEx(EOF) || RegEx());
const RegEx BlockEntry = RegEx('-') + (BlankOrBreak || RegEx(EOF));
const RegEx Key = RegEx('?'),
KeyInFlow = RegEx('?') + BlankOrBreak;
const RegEx Value = RegEx(':'),
ValueInFlow = RegEx(':') + BlankOrBreak;
const RegEx Comment = RegEx('#');
// Plain scalar rules:
// . Cannot start with a blank.
// . Can never start with any of , [ ] { } # & * ! | > \' \" % @ `
// . In the block context - ? : must be not be followed with a space.
// . In the flow context ? : are illegal and - must not be followed with a space.
const RegEx PlainScalar = !(BlankOrBreak || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-?:") + Blank)),
PlainScalarInFlow = !(BlankOrBreak || RegEx("?:,[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx('-') + Blank));
const RegEx IllegalColonInScalar = RegEx(':') + !BlankOrBreak;
const RegEx EndScalar = RegEx(':') + BlankOrBreak,
EndScalarInFlow = (RegEx(':') + BlankOrBreak) || RegEx(",:?[]{}");
}
namespace Keys
{
const char Comment = '#';
const char FlowSeqStart = '[';
const char FlowSeqEnd = ']';
const char FlowMapStart = '{';
const char FlowMapEnd = '}';
const char FlowEntry = ',';
const char BlockEntry = '-';
const char Key = '?';
const char Value = ':';
const char Alias = '*';
const char Anchor = '&';
const char Tag = '!';
@ -49,8 +76,6 @@ namespace YAML
void EatLineBreak();
bool IsWhitespaceToBeEaten(char ch);
bool IsLineBreak(char ch);
bool IsBlank(char ch);
bool IsDocumentStart();
bool IsDocumentEnd();
bool IsBlockEntry();