Commit 2e71ad16 authored by Kenton Varda's avatar Kenton Varda

Move parser-combinator framework to subdirectory.

parent feb5c1ab
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "parse.h" #include "common.h"
#include "string.h" #include "../string.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
namespace kj { namespace kj {
...@@ -32,7 +32,7 @@ namespace { ...@@ -32,7 +32,7 @@ namespace {
typedef IteratorInput<char, const char*> Input; typedef IteratorInput<char, const char*> Input;
typedef Span<const char*> TestLocation; typedef Span<const char*> TestLocation;
TEST(Parsers, ExactElementParser) { TEST(CommonParsers, ExactElementParser) {
StringPtr text = "foo"; StringPtr text = "foo";
Input input(text.begin(), text.end()); Input input(text.begin(), text.end());
...@@ -55,7 +55,7 @@ TEST(Parsers, ExactElementParser) { ...@@ -55,7 +55,7 @@ TEST(Parsers, ExactElementParser) {
EXPECT_TRUE(input.atEnd()); EXPECT_TRUE(input.atEnd());
} }
TEST(Parsers, ExactlyConstParser) { TEST(CommonParsers, ExactlyConstParser) {
StringPtr text = "foo"; StringPtr text = "foo";
Input input(text.begin(), text.end()); Input input(text.begin(), text.end());
...@@ -78,7 +78,7 @@ TEST(Parsers, ExactlyConstParser) { ...@@ -78,7 +78,7 @@ TEST(Parsers, ExactlyConstParser) {
EXPECT_TRUE(input.atEnd()); EXPECT_TRUE(input.atEnd());
} }
TEST(Parsers, ExactChar) { TEST(CommonParsers, ExactChar) {
constexpr auto parser = exactChar<'a'>(); constexpr auto parser = exactChar<'a'>();
{ {
...@@ -96,7 +96,7 @@ TEST(Parsers, ExactChar) { ...@@ -96,7 +96,7 @@ TEST(Parsers, ExactChar) {
} }
} }
TEST(Parsers, ConstResultParser) { TEST(CommonParsers, ConstResultParser) {
auto parser = constResult(exactly('o'), 123); auto parser = constResult(exactly('o'), 123);
StringPtr text = "o"; StringPtr text = "o";
...@@ -110,7 +110,7 @@ TEST(Parsers, ConstResultParser) { ...@@ -110,7 +110,7 @@ TEST(Parsers, ConstResultParser) {
EXPECT_TRUE(input.atEnd()); EXPECT_TRUE(input.atEnd());
} }
TEST(Parsers, SequenceParser) { TEST(CommonParsers, SequenceParser) {
StringPtr text = "foo"; StringPtr text = "foo";
{ {
...@@ -163,7 +163,7 @@ TEST(Parsers, SequenceParser) { ...@@ -163,7 +163,7 @@ TEST(Parsers, SequenceParser) {
} }
} }
TEST(Parsers, ManyParser) { TEST(CommonParsers, ManyParser) {
StringPtr text = "foooob"; StringPtr text = "foooob";
auto parser = transform( auto parser = transform(
...@@ -204,7 +204,7 @@ TEST(Parsers, ManyParser) { ...@@ -204,7 +204,7 @@ TEST(Parsers, ManyParser) {
} }
} }
TEST(Parsers, OptionalParser) { TEST(CommonParsers, OptionalParser) {
auto parser = sequence( auto parser = sequence(
transform(exactly('b'), [](TestLocation) -> uint { return 123; }), transform(exactly('b'), [](TestLocation) -> uint { return 123; }),
optional(transform(exactly('a'), [](TestLocation) -> uint { return 456; })), optional(transform(exactly('a'), [](TestLocation) -> uint { return 456; })),
...@@ -250,7 +250,7 @@ TEST(Parsers, OptionalParser) { ...@@ -250,7 +250,7 @@ TEST(Parsers, OptionalParser) {
} }
} }
TEST(Parsers, OneOfParser) { TEST(CommonParsers, OneOfParser) {
auto parser = oneOf( auto parser = oneOf(
transform(sequence(exactly('f'), exactly('o'), exactly('o')), transform(sequence(exactly('f'), exactly('o'), exactly('o')),
[](TestLocation) -> StringPtr { return "foo"; }), [](TestLocation) -> StringPtr { return "foo"; }),
...@@ -282,7 +282,7 @@ TEST(Parsers, OneOfParser) { ...@@ -282,7 +282,7 @@ TEST(Parsers, OneOfParser) {
} }
} }
TEST(Parsers, TransformParser) { TEST(CommonParsers, TransformParser) {
StringPtr text = "foo"; StringPtr text = "foo";
auto parser = transform( auto parser = transform(
...@@ -304,7 +304,7 @@ TEST(Parsers, TransformParser) { ...@@ -304,7 +304,7 @@ TEST(Parsers, TransformParser) {
} }
} }
TEST(Parsers, References) { TEST(CommonParsers, References) {
struct TransformFunc { struct TransformFunc {
int value; int value;
...@@ -344,7 +344,7 @@ TEST(Parsers, References) { ...@@ -344,7 +344,7 @@ TEST(Parsers, References) {
} }
} }
TEST(Parsers, AcceptIfParser) { TEST(CommonParsers, AcceptIfParser) {
auto parser = acceptIf( auto parser = acceptIf(
oneOf(transform(exactly('a'), [](TestLocation) -> uint { return 123; }), oneOf(transform(exactly('a'), [](TestLocation) -> uint { return 123; }),
transform(exactly('b'), [](TestLocation) -> uint { return 456; }), transform(exactly('b'), [](TestLocation) -> uint { return 456; }),
...@@ -383,7 +383,7 @@ TEST(Parsers, AcceptIfParser) { ...@@ -383,7 +383,7 @@ TEST(Parsers, AcceptIfParser) {
} }
} }
TEST(Parsers, CharRange) { TEST(CommonParsers, CharRange) {
constexpr auto parser = charRange('a', 'z'); constexpr auto parser = charRange('a', 'z');
{ {
...@@ -447,7 +447,7 @@ TEST(Parsers, CharRange) { ...@@ -447,7 +447,7 @@ TEST(Parsers, CharRange) {
} }
} }
TEST(Parsers, AnyChar) { TEST(CommonParsers, AnyChar) {
constexpr auto parser = anyChar("axn2B"); constexpr auto parser = anyChar("axn2B");
{ {
...@@ -511,7 +511,7 @@ TEST(Parsers, AnyChar) { ...@@ -511,7 +511,7 @@ TEST(Parsers, AnyChar) {
} }
} }
TEST(Parsers, CharGroupCombo) { TEST(CommonParsers, CharGroupCombo) {
constexpr auto parser = constexpr auto parser =
many(charRange('0', '9').orRange('a', 'z').orRange('A', 'Z').orAny("-_")); many(charRange('0', '9').orRange('a', 'z').orRange('A', 'Z').orAny("-_"));
......
...@@ -35,14 +35,14 @@ ...@@ -35,14 +35,14 @@
// will have updated the input cursor to point to the position just past the end of what was parsed. // will have updated the input cursor to point to the position just past the end of what was parsed.
// On failure, the cursor position is unspecified. // On failure, the cursor position is unspecified.
#ifndef KJ_PARSER_H_ #ifndef KJ_PARSE_COMMON_H_
#define KJ_PARSER_H_ #define KJ_PARSE_COMMON_H_
#include "common.h" #include "../common.h"
#include "memory.h" #include "../memory.h"
#include "array.h" #include "../array.h"
#include "tuple.h" #include "../tuple.h"
#include "vector.h" #include "../vector.h"
namespace kj { namespace kj {
namespace parse { namespace parse {
...@@ -632,4 +632,4 @@ constexpr CharGroup_ anyChar(const char* chars) { ...@@ -632,4 +632,4 @@ constexpr CharGroup_ anyChar(const char* chars) {
} // namespace parse } // namespace parse
} // namespace kj } // namespace kj
#endif // KJ_PARSER_H_ #endif // KJ_PARSE_COMMON_H_
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