www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3073] New: expressions starting with string mixin don't parse

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3073

           Summary: expressions starting with string mixin don't parse
           Product: D
           Version: 1.040
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: shro8822 vandals.uidaho.edu


void main()
{
int s;
mixin("s") = 5;
}

-----
Line 4: found '=' when expecting ';'

this should work:
http://www.digitalmars.com/d/1.0/expression.html#MixinExpression



quoting Ary from the NG thread:
=============================

Yes, at that point the parser is parsing statements, so if it finds a 
"mixin(...)" it turns it into a statement.

I'm thinking about how to fix this. I think the parser should peek the 
next token after the closing parenthesis. If it's a semicolon, then 
treat it as a statement-mixin. Else, just invoke parseAssignExp and 
create a new ExpStatement.

I modified this in Descent and it seems to work. :-)

Here's the code (in Java, but the idea is simple to translate to C++):

// inside Parser::parseStatement
case TOKmixin: {
     Dsymbol d;
     t = peek(token);
     if (t.value == TOKlparen)
     {
         if (peekPastParen(t).value != TOKsemicolon) {
             Expression e = parseAssignExp();
             s = new ExpStatement(loc(), e);
         } else {
             // mixin(string)
             nextToken();
             check(TOKlparen);
             Expression e = parseAssignExp();
             check(TOKrparen);
             check(TOKsemicolon);
             s = newCompileStatement(loc(), e);
         }
         break;
     } else {
         d = parseMixin();
         s = newDeclarationStatement(loc(), d);
         break;
     }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 16 2009
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3073




21:53:24 PDT ---
Created an attachment (id=687)
lookahead to see if semicolon follows

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 28 2010