mail[Wesnoth-commits] r24993 - in /trunk/src: formula.cpp formula_tokenizer.cpp formula_tokenizer.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by dhains on March 22, 2008 - 23:10:
Author: dhains
Date: Sat Mar 22 23:10:10 2008
New Revision: 24993

URL: http://svn.gna.org/viewcvs/wesnoth?rev=24993&view=rev
Log:
Added support for formula scripting to formulaAI parser

Modified:
    trunk/src/formula.cpp
    trunk/src/formula_tokenizer.cpp
    trunk/src/formula_tokenizer.hpp

Modified: trunk/src/formula.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula.cpp?rev=24993&r1=24992&r2=24993&view=diff
==============================================================================
--- trunk/src/formula.cpp (original)
+++ trunk/src/formula.cpp Sat Mar 22 23:10:10 2008
@@ -540,18 +540,27 @@
 
        if(i1->type == TOKEN_KEYWORD &&
                        (i1+1)->type == TOKEN_IDENTIFIER) {
-               if(std::string(i1->begin,i1->end) == "def") {
+               if(std::string(i1->begin, i1->end) == "def") {
                        ++i1;
-                       const std::string formula_name = 
std::string(i1->begin,i1->end);
+                       const std::string formula_name = 
std::string(i1->begin, i1->end);
                        std::vector<std::string> args;
                        parse_function_args(++i1, i2, &args);
-                       const std::string formula_str = 
std::string(i1->begin, (i2-1)->end);
+                       const token* beg = i1;
+                       while((i1 != i2) && (i1->type != TOKEN_SEMICOLON)) {
+                               ++i1;
+                       }
+                       const std::string formula_str = 
std::string(beg->begin, (i1-1)->end);
                        const std::string precond = "";
                        symbols->add_formula_function(formula_name,
                                        const_formula_ptr(new 
formula(formula_str, symbols)),
                                        
formula::create_optional_formula(precond, symbols),
                                        args);
-                       return expression_ptr(new 
function_list_expression(symbols));
+                       if((i1 == i2) || (i1 == (i2-1))) {
+                               return expression_ptr(new 
function_list_expression(symbols));
+                       }
+                       else {
+                               return parse_expression((i1+1), i2, symbols);
+                       }
                }
        }
 

Modified: trunk/src/formula_tokenizer.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_tokenizer.cpp?rev=24993&r1=24992&r2=24993&view=diff
==============================================================================
--- trunk/src/formula_tokenizer.cpp (original)
+++ trunk/src/formula_tokenizer.cpp Sat Mar 22 23:10:10 2008
@@ -32,17 +32,18 @@
 
 //create the array with list of possible tokens
 token_type token_types[] = { { 
regex("^(not\\b|and\\b|or\\b|where\\b|d(?=[^a-zA-Z])|\\*|\\+|\\-|\\^|%|/|<=|>=|<|>|!=|=|\\.)"),
 TOKEN_OPERATOR },
-                               { regex("\\bfunctions\\b"),   TOKEN_KEYWORD },
-                               { regex("\\bdef\\b"),     TOKEN_KEYWORD },
-                               { regex("^'[^']*'"),    TOKEN_STRING_LITERAL 
},
-                               { regex("^[a-zA-Z_]+"), TOKEN_IDENTIFIER },
-                               { regex("^\\d+"),       TOKEN_INTEGER },
-                               { regex("^\\("),        TOKEN_LPARENS },
-                               { regex("^\\)"),        TOKEN_RPARENS },
-                               { regex("^\\["),        TOKEN_LSQUARE },
-                               { regex("^\\]"),        TOKEN_RSQUARE },
-                               { regex("^,"),          TOKEN_COMMA },
-                               { regex("^\\s+"),       TOKEN_WHITESPACE }
+                               { regex("^functions\\b"),  TOKEN_KEYWORD },
+                               { regex("^def\\b"),        TOKEN_KEYWORD },
+                               { regex("^'[^']*'"),       
TOKEN_STRING_LITERAL },
+                               { regex("^[a-zA-Z_]+"),    TOKEN_IDENTIFIER },
+                               { regex("^\\d+"),          TOKEN_INTEGER },
+                               { regex("^\\("),           TOKEN_LPARENS },
+                               { regex("^\\)"),           TOKEN_RPARENS },
+                               { regex("^\\["),           TOKEN_LSQUARE },
+                               { regex("^\\]"),           TOKEN_RSQUARE },
+                               { regex("^,"),             TOKEN_COMMA },
+                               { regex("^;"),             TOKEN_SEMICOLON },
+                               { regex("^\\s+"),          TOKEN_WHITESPACE }
 };
 
 }

Modified: trunk/src/formula_tokenizer.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_tokenizer.hpp?rev=24993&r1=24992&r2=24993&view=diff
==============================================================================
--- trunk/src/formula_tokenizer.hpp (original)
+++ trunk/src/formula_tokenizer.hpp Sat Mar 22 23:10:10 2008
@@ -24,7 +24,8 @@
 enum TOKEN_TYPE { TOKEN_OPERATOR, TOKEN_STRING_LITERAL,
                          TOKEN_IDENTIFIER, TOKEN_INTEGER,
                   TOKEN_LPARENS, TOKEN_RPARENS,
-                                 TOKEN_LSQUARE, TOKEN_RSQUARE, TOKEN_COMMA,
+                                 TOKEN_LSQUARE, TOKEN_RSQUARE, 
+                                 TOKEN_COMMA, TOKEN_SEMICOLON, 
                                  TOKEN_WHITESPACE, TOKEN_KEYWORD };
 
 struct token {




Related Messages


Powered by MHonArc, Updated Sun Mar 23 00:01:58 2008