1 /* 2 * Copyright 2018 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef fiddleParser_DEFINED 9 #define fiddleParser_DEFINED 10 11 #include "parserCommon.h" 12 13 class BmhParser; 14 15 class FiddleBase : public JsonCommon { 16 protected: FiddleBase(BmhParser * bmh)17 FiddleBase(BmhParser* bmh) 18 : fBmhParser(bmh) 19 , fContinuation(false) 20 , fTextOut(false) 21 , fPngOut(false) 22 { 23 this->reset(); 24 } 25 reset()26 void reset() override { 27 INHERITED::reset(); 28 } 29 30 Definition* findExample(string name) const; 31 bool parseFiddles(); 32 virtual bool pngOut(Definition* example) = 0; 33 virtual bool textOut(Definition* example, const char* stdOutStart, 34 const char* stdOutEnd) = 0; 35 36 BmhParser* fBmhParser; // must be writable; writes example hash 37 string fFullName; 38 bool fContinuation; 39 bool fTextOut; 40 bool fPngOut; 41 private: 42 typedef JsonCommon INHERITED; 43 }; 44 45 class FiddleParser : public FiddleBase { 46 public: FiddleParser(BmhParser * bmh)47 FiddleParser(BmhParser* bmh) : FiddleBase(bmh) { 48 fTextOut = true; 49 } 50 51 bool parseFromFile(const char* path) override; 52 53 private: pngOut(Definition * example)54 bool pngOut(Definition* example) override { 55 return true; 56 } 57 58 bool textOut(Definition* example, const char* stdOutStart, 59 const char* stdOutEnd) override; 60 61 typedef FiddleBase INHERITED; 62 }; 63 64 class Catalog : public FiddleBase { 65 public: Catalog(BmhParser * bmh)66 Catalog(BmhParser* bmh) : FiddleBase(bmh) {} 67 68 bool appendFile(string path); 69 bool closeCatalog(const char* outDir); 70 bool openCatalog(const char* inDir); 71 bool openStatus(const char* inDir); 72 73 bool parseFromFile(const char* path) override ; 74 private: 75 bool pngOut(Definition* example) override; 76 bool textOut(Definition* example, const char* stdOutStart, 77 const char* stdOutEnd) override; 78 79 string fDocsDir; 80 81 typedef FiddleBase INHERITED; 82 }; 83 84 #endif 85