From e5a79fa6ef2230505665022512ae60f1bab4b29d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 28 Nov 2016 15:07:45 +0200 Subject: Sketch testscript line regex object model --- build2/test/script/regex | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ doc/testscript.cli | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 build2/test/script/regex diff --git a/build2/test/script/regex b/build2/test/script/regex new file mode 100644 index 0000000..c6e711c --- /dev/null +++ b/build2/test/script/regex @@ -0,0 +1,76 @@ +// file : build2/test/script/regex -*- C++ -*- +// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BUILD2_TEST_SCRIPT_REGEX +#define BUILD2_TEST_SCRIPT_REGEX + +#include + +#include +#include + +namespace build2 +{ + namespace test + { + namespace script + { + // @@ How can we get the position the first line_char in the output that + // did not match, for diagnostics? Failed that it will be very hard + // to debug match failures. + // + + using char_string = std::basic_string; + using char_regex = std::basic_regex; + + // Newlines are line separators and are not part of the line: + // + // lineline + // + // Specifically, this means that a customary trailing newline creates a + // trailing blank line. + // + // Special characters should only be compared to special. All others + // can inter-compare (though there cannot be regex characters in the + // output, only in line_regex). + // + enum class line_type + { + blank, + special, + literal, + regex + }; + + struct line_char + { + line_type type; + + union + { // Uninitialized if type is blank. + char special; // [()|*+?{\}0123456789,=!] (excluding []). + char_string literal; + char_regex regex; + }; + }; + + // Note: line_string is not NUL-terminated. + // + using line_string = vector; + + class line_regex: public std::basic_regex + { + public: + using base_type = std::basic_regex; + + using base_type::base_type; + + explicit + line_regex (const line_string&); + }; + } + } +} + +#endif // BUILD2_TEST_SCRIPT_REGEX diff --git a/doc/testscript.cli b/doc/testscript.cli index a9ba608..c09e69c 100644 --- a/doc/testscript.cli +++ b/doc/testscript.cli @@ -1486,7 +1486,7 @@ which case it will only be equal to an identical line in the output. Or a line-char can be an inner level regex (like \c{ba+r} above) in which case it will be equal to any line in the output that matches this regex. Where not clear from context we will refer to this inner expression as -\i{char-regex} and its characters as \c{char}. +\i{char-regex} and its characters as \i{char}. A line is treated as literal unless it starts with the \i{regex introducer character} (\c{/} in the above example). In contrast, the line-regex is always -- cgit v1.1