From 0172e77ad6b73d56b57d1b5387e5bd3a9341228a Mon Sep 17 00:00:00 2001 From: fmalita Date: Thu, 25 Aug 2016 05:50:26 -0700 Subject: Revert of Experimental parsing expression grammar (PEG) template library (patchset #8 id:140001 of https://codereview.chromium.org/2271743002/ ) Reason for revert: G3 roll & Msan woes. Original issue's description: > Experimental parsing expression grammar (PEG) template library > > > BUG=skia: > GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2271743002 > > Committed: https://skia.googlesource.com/skia/+/9d08cbc8c6131ff61a1e71cc5c8cf27841d62b42 TBR=mtklein@google.com,bungeman@google.com,reed@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review-Url: https://codereview.chromium.org/2275943004 --- experimental/svg/model/SkPEG.h | 244 ----------------------------------------- 1 file changed, 244 deletions(-) delete mode 100644 experimental/svg/model/SkPEG.h (limited to 'experimental/svg') diff --git a/experimental/svg/model/SkPEG.h b/experimental/svg/model/SkPEG.h deleted file mode 100644 index 886852019e..0000000000 --- a/experimental/svg/model/SkPEG.h +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright 2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkPEG_DEFINED -#define SkPEG_DEFINED - -#include "SkTDArray.h" -#include "SkTLazy.h" - -namespace skpeg { - -/** - * The result of an expression match attempt. - * - * If the match was successful, |fNext| points to the next unconsumed character in the - * input string, and |fValue| holds an (arbitrarily nested) match result value. - * - * Otherwise, |fNext| is nullptr and |fValue| is uninitialized. - */ -template -struct MatchResult { - MatchResult(std::nullptr_t) : fNext(nullptr) {} - MatchResult(const char* next, const V& v) : fNext(next), fValue(&v) {} - - operator bool() const { - SkASSERT(fValue.isValid() == SkToBool(fNext)); - return SkToBool(fNext); - } - - const V& operator* () const { return *fValue.get(); } - const V* operator->() const { return fValue.get(); } - - const char* fNext; - SkTLazy fValue; -}; - -/** - * Optional operator (e?). Always succeeds. - * - * If e also matches, then the result of e::Match() is stored in |fValue|. - * Otherwise, |fValue| is uninitialized. - * - */ -template -struct Opt { - struct V { - V(const typename E::V* v) : fValue(v) {} - - SkTLazy fValue; - }; - using MatchT = MatchResult; - - static MatchT Match(const char* in) { - const auto m = E::Match(in); - return m ? MatchT(m.fNext, V(m.fValue.get())) - : MatchT(in, nullptr); - } -}; - -/** - * Helper for selecting the value type of the n-th expression type in the list. - */ -template struct SelectV; - -template -struct SelectV<0, E, Es...> { - using V = typename E::V; -}; - -template -struct SelectV { - using V = typename SelectV::V; -}; - -/** - * Sequence operator (e0 e1...). - * - * Succeeds when all expressions match, in sequence. The subexpression match - * results can be accessed via get() -- where get<0> returns the value - * of the first expression, and so on. - * - */ -template struct Seq; - -template <> -struct Seq<> { - struct V {}; - using MatchT = MatchResult; - - static MatchT Match(const char* in) { - return MatchT(in, V()); - } -}; - -template -struct Seq { - class V { - public: - V(const typename E::V& head, const typename Seq::V& tail) - : fHeadV(head), fTailV(tail) {} - - template ::type = 0> - const typename E::V& get() const { - return fHeadV; - } - - template ::type = 0> - const typename SelectV::V& get() const { - return fTailV.template get(); - } - - private: - typename E::V fHeadV; - typename Seq::V fTailV; - }; - using MatchT = MatchResult; - - static MatchT Match(const char* in) { - const auto headMatch = E::Match(in); - if (!headMatch) { - return nullptr; - } - - const auto tailMatch = Seq::Match(headMatch.fNext); - return tailMatch ? MatchT(tailMatch.fNext, V(*headMatch, *tailMatch)) - : nullptr; - } -}; - -/** - * Ordered choice operator (e1|e2). - * - * Succeeds when either e1 or e2 match (e1 is tried first, then e2). - * - * The (optional) match results are stored in |v1|, |v2|. - * - */ -template -struct Choice { - struct V { - V (const typename E1::V* v1, const typename E2::V* v2) : v1(v1), v2(v2) - { - SkASSERT(!v1 || !v2); - } - - SkTLazy v1; - SkTLazy v2; - }; - using MatchT = MatchResult; - - static MatchT Match(const char* in) { - if (const auto m1 = E1::Match(in)) { - return MatchT(m1.fNext, V(m1.fValue.get(), nullptr)); - } - if (const auto m2 = E2::Match(in)) { - return MatchT(m2.fNext, V(nullptr, m2.fValue.get())); - } - return nullptr; - } -}; - -/** - * Zero-or-more operator (e*). Always succeeds. - * - * Matches e greedily, and stores the match results in |fValues|. - * - */ -template -struct Any { - struct V { - V(SkTDArray&& vs) : fValues(vs) {} - - SkTDArray fValues; - }; - using MatchT = MatchResult; - - static MatchT Match(const char* in) { - SkTDArray values; - while (const auto m = E::Match(in)) { - in = m.fNext; - *values.append() = *m; - } - return MatchT(in, std::move(values)); - } -}; - -/** - * One-or-more operator (e+). - * - * Same as zero-or-more, except it fails if e doesn't match at least once. - * - */ -template -using Some = Seq>; - -/** - * End-of-string atom. Matches \0. - */ -struct EOS { - struct V {}; - using MatchT = MatchResult; - - static MatchT Match(const char* in) { - return (*in != '\0') ? nullptr : MatchT(in, V()); - } -}; - - -/** - * Literal atom. Matches a list of char literals. - */ -template struct LIT; - -template <> -struct LIT<> { - struct V {}; - using MatchT = MatchResult; - - static MatchT Match(const char* in) { - return MatchT(in, V()); - } -}; - -template -struct LIT { - struct V {}; - using MatchT = MatchResult; - - static MatchT Match(const char* in) { - if (*in != C) { - return nullptr; - } - const auto m = LIT::Match(in + 1); - return m ? MatchT(m.fNext, V()) : nullptr; - } -}; - -} // skpeg ns - -#endif // SkPEG_DEFINED -- cgit v1.2.3