#pragma once #include #include #include #include #include #include #include #include "sparse_vector.hh" #include "util.hh" using namespace std; namespace G { struct NT { string symbol; size_t index; NT() {}; NT(string& s); string repr() const; string escaped() const; friend ostream& operator<<(ostream& os, const NT& t); }; struct T { string word; // use word ids instead? T(const string& s); string repr() const; string escaped() const; friend ostream& operator<<(ostream& os, const NT& nt); }; enum item_type { NON_TERMINAL, TERMINAL }; struct Item { item_type type; NT* nt; T* t; Item(string& s); string repr() const; string escaped() const; friend ostream& operator<<(ostream& os, const Item& i); }; struct Rule { NT* lhs; vector rhs; vector target; size_t arity; Sv::SparseVector* f; map order; string as_str_; // FIXME Rule() {}; Rule(const string& s); string repr() const; string escaped() const; friend ostream& operator<<(ostream& os, const Rule& r); void prep_for_serialization_() { as_str_ = escaped(); }; // FIXME MSGPACK_DEFINE(as_str_); // TODO }; struct Grammar { vector rules; vector flat; vector start_nt; vector start_t; Grammar() {}; Grammar(const string& fn); void add_glue(); // TODO void add_pass_through(const string& input); // TODO friend ostream& operator<<(ostream& os, const Grammar& g); }; } // namespace G