Sample nodes file, more semantic actions

- Note: This parser is still untested.
This commit is contained in:
2014-12-02 16:33:00 -05:00
parent 01f0a62160
commit d1a8db9b70
2 changed files with 16 additions and 2 deletions

View File

@@ -11,9 +11,12 @@
using namespace boost::spirit::qi;
std::string temp_symbol;
int cur_node;
symbols<char, int> defn;
void init() {cur_node = 0; temp_symbol.clear();}
void prep_add_symbol(char c) {temp_symbol += c;}
void add_symbol(int i) {defn.add(temp_symbol, i); temp_symbol.clear();}
void skip_to(int i) {cur_node = i;}
auto ws = char_(" \t");
auto comment = char_('#') >> *(print | char_('\t'));
@@ -44,8 +47,8 @@ auto command = datcode >> ws >> *ws >> val >> (eps | *ws >> char_(',') >> *ws >>
auto def_line = *ws >> lit("def") >> ws >> *ws >> symbol >> *ws >> char_('=') >> *ws >> uint_[add_symbol] >> (comment | eps) >> eol;
auto cmd_line = *ws >> (command | eps) >> *ws >> (comment | eps) >> eol;
auto op_line = *ws >> char_('@') >> opcode >> (eps | *ws >> char_('=') >> *ws >> val) >> (comment | eps) >> eol;
auto op_line = *ws >> char_('@') >> opcode >> (eps | *ws >> char_('=') >> *ws >> val[skip_to]) >> (comment | eps) >> eol;
auto command_block = op_line >> *(cmd_line | def_line);
auto nodes_file = *def_line >> *command_block;
auto nodes_file = eps[init] >> *def_line >> *command_block;

11
rsrc/boes/town/t0.spec Normal file
View File

@@ -0,0 +1,11 @@
# Sample special node sequence.
@if-gold # The first node is node 0
ex1 50, 5 # If they have 50 gold, take it and jump to node 5
goto 1 # Otherwise, jump to node 1
@disp-msg # Subsequent nodes increment from the previous one
msg 2 # Shows string 2; the omitted argument is assumed to be -1
@town-visible = 5 # Explicitly specify node number
msg 3,4 # Shows strings 3 and 4 in the message dialog
ex1 3,1 # Town 3, set visibility to true