From 9e345650e116c355fad8e104fc088f15e211fcb0 Mon Sep 17 00:00:00 2001 From: jbeder Date: Mon, 31 Jan 2011 17:47:20 +0000 Subject: [PATCH] Added Anchor() regex (so that we're not just using Alphanumeric to match anchors), but it's still not 100% right (it shouldn't allow non-printable characters, e.g.). Also fixed a test that was broken along these lines (if a colon immediately follows an anchor, it's part of the anchor) --- src/exp.h | 4 ++++ src/scantoken.cpp | 2 +- test/parsertests.cpp | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/exp.h b/src/exp.h index 8b84214..c42daec 100644 --- a/src/exp.h +++ b/src/exp.h @@ -112,6 +112,10 @@ namespace YAML static const RegEx e = RegEx('#'); return e; } + inline const RegEx& Anchor() { + static const RegEx e = !(RegEx("[]{},", REGEX_OR) || BlankOrBreak()); + return e; + } inline const RegEx& AnchorEnd() { static const RegEx e = RegEx("?:,]}%@`", REGEX_OR) || BlankOrBreak(); return e; diff --git a/src/scantoken.cpp b/src/scantoken.cpp index 82ea733..06d9cd6 100644 --- a/src/scantoken.cpp +++ b/src/scantoken.cpp @@ -238,7 +238,7 @@ namespace YAML alias = (indicator == Keys::Alias); // now eat the content - while(Exp::AlphaNumeric().Matches(INPUT)) + while(INPUT && Exp::Anchor().Matches(INPUT)) name += INPUT.get(); // we need to have read SOMETHING! diff --git a/test/parsertests.cpp b/test/parsertests.cpp index f013234..c432ef6 100644 --- a/test/parsertests.cpp +++ b/test/parsertests.cpp @@ -472,7 +472,7 @@ namespace Test bool AliasAsSimpleKey() { - std::string input = "- &a b\n- *a: c"; + std::string input = "- &a b\n- *a : c"; std::stringstream stream(input); YAML::Parser parser(stream);