1 /* Hapy is a public domain software. See Hapy README file for the details. */ 2 3 #ifndef HAPY_RULE__H 4 #define HAPY_RULE__H 5 6 #include <Hapy/Top.h> 7 #include <Hapy/Result.h> 8 #include <Hapy/String.h> 9 #include <Hapy/IosFwd.h> 10 #include <Hapy/RulePtr.h> 11 12 namespace Hapy { 13 14 class Buffer; 15 class Pree; 16 17 class Action; 18 class Algorithm; 19 20 // user-level grammar rule interface 21 // supports user-level semantics of rule creation, assignment, and manipulation 22 class Rule { 23 public: 24 Rule(); 25 Rule(const RulePtr &aBase); 26 Rule(const Rule &r); 27 Rule(const string &aName, RuleId *id); // user-level; returns id 28 Rule(const string &s); // converts to string_r 29 Rule(const char *s); // converts to string_r 30 Rule(char c); // converts to char_r 31 ~Rule(); 32 33 bool known() const; 34 const RuleId &id() const; 35 36 void committed(bool be); 37 void trim(const Rule &skipper); 38 void verbatim(bool be); 39 void leaf(bool be); 40 41 void action(const Action &a); // modifies this rule 42 Rule operator [](const Action &a) const; // produces a new rule 43 44 ostream &print(ostream &os) const; 45 46 // prevents base (id, trimming, etc.) re-initialization 47 Rule &operator =(const Rule &r); 48 Rule &operator =(const Algorithm &a); 49 50 // access to the implementation-level interface base()51 RulePtr &base() { return theBase; } base()52 const RulePtr &base() const { return theBase; } 53 54 private: 55 Rule(int); // to prevent "Rule r = 5;" from using Rule(char) 56 57 void init(const RuleId &rid); 58 void assign(RuleBase *b); 59 60 protected: 61 RulePtr theBase; 62 }; 63 64 } // namespace 65 66 #endif 67