36 const char* reading = source.c_str();
38 std::vector<std::string>* filled =
nullptr;
41 while (*reading != 0) {
42 if (*reading ==
'=') {
48 }
else if (*reading ==
'\n') {
50 if (filled) filled->push_back(buf);
54 }
else if (*reading ==
'|') {
55 if (!filled || !current) {
56 lg::wml_error() <<
"[context_free_grammar_generator] Parsing error: misplaced | symbol";
59 filled->push_back(buf);
63 }
else if (*reading ==
'\\' && reading[1] ==
'n') {
66 }
else if (*reading ==
'\\' && reading[1] ==
't') {
70 if (*reading ==
'{') {
72 lg::wml_error() <<
"[context_free_grammar_generator] Parsing error: misplaced { symbol";
75 filled->push_back(buf);
78 else if (*reading ==
'}') {
80 lg::wml_error() <<
"[context_free_grammar_generator] Parsing error: misplaced } symbol";
85 }
else buf.push_back(*reading);
89 if (filled) filled->push_back(buf);
102 std::vector<std::string>* filled = &
nonterminals_[key].possibilities_.back();
108 lg::wml_error() <<
"[context_free_grammar_generator] Parsing error: misplaced { symbol";
111 filled->push_back(buf);
116 lg::wml_error() <<
"[context_free_grammar_generator] Parsing error: misplaced } symbol";
121 }
else buf.push_back(
c);
124 filled->push_back(buf);
133 std::map<std::string, nonterminal>::const_iterator found =
nonterminals_.find(name);
135 lg::wml_error() <<
"[context_free_grammar_generator] Warning: needed nonterminal " << name <<
" not defined";
139 unsigned int picked = seed[seed_pos++] % got.
possibilities_.size();
141 if (picked == got.
last_) {
146 const std::vector<std::string>& used = got.
possibilities_[picked];
147 for (
unsigned int i = 0;
i < used.size();
i++) {
149 else result += used[
i];
rng * generator
This generator is automatically synced during synced context.
std::string & strip(std::string &str)
Remove whitespace from the front and back of the string 'str'.
std::vector< std::vector< std::string > > possibilities_
uint32_t next_random()
Provides the next random draw.
GLenum GLuint GLsizei const char * buf
std::string generate() const override
Generates a possible word in the grammar set before.
context_free_grammar_generator(const std::string &source)
Initialisation.
std::stringstream & wml_error()
Use this logger to send errors due to deprecated WML.
std::string print_nonterminal(const std::string &name, uint32_t *seed, short int seed_pos) const
GLuint const GLchar * name
std::map< std::string, nonterminal > nonterminals_
Standard logging facilities (interface).
~context_free_grammar_generator()
GLsizei const GLcharARB ** string
GLsizei GLsizei GLchar * source
static const short unsigned int seed_size