]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Translatable string constants
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 25 Nov 2012 17:22:00 +0000 (18:22 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 25 Nov 2012 17:22:00 +0000 (18:22 +0100)
parser.c

index 5d0045d3bdff1c63f604a1cacd8e48c444bc9ec4..f669b37b0a54913618a4565e37a205689beb654c 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1304,7 +1304,36 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
         else
             parser->memberof = 0;
 
-        if (parser->tok == TOKEN_IDENT)
+        if (parser->tok == TOKEN_IDENT && !strcmp(parser_tokval(parser), "_")) {
+            /* a translatable string */
+            ast_value *val;
+
+            if (wantop) {
+                parseerror(parser, "expected operator or end of statement, got constant");
+                goto onerr;
+            }
+
+            if (!parser_next(parser) || parser->tok != '(') {
+                parseerror(parser, "use _(\"string\") to create a translatable string constant");
+                goto onerr;
+            }
+            if (!parser_next(parser) || parser->tok != TOKEN_STRINGCONST) {
+                parseerror(parser, "expected a constant string in translatable-string extension");
+                goto onerr;
+            }
+            val = parser_const_string(parser, parser_tokval(parser), true);
+            wantop = true;
+            if (!val)
+                return false;
+            vec_push(sy.out, syexp(parser_ctx(parser), (ast_expression*)val));
+            DEBUGSHUNTDO(con_out("push string\n"));
+
+            if (!parser_next(parser) || parser->tok != ')') {
+                parseerror(parser, "expected closing paren after translatable string");
+                goto onerr;
+            }
+        }
+        else if (parser->tok == TOKEN_IDENT)
         {
             ast_expression *var;
             if (wantop) {