Show
Ignore:
Timestamp:
01/16/08 05:01:53 (4 years ago)
Author:
Don Clugston
Message:

SyntaxTree? now creates a tuple of the types. This opens the way to significant simplification of some of the code (eg, I should be able to remove the rank stuff from SyntaxTree?).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/blade/BladeVisitor.d

    r175 r176  
    2020V.ReturnType beginVisit(V)(V visitor, char [] expr) 
    2121{ 
    22     if (exprLength(expr)==expr.length) { 
    23         return doVisit(visitor, expr); //  
     22    if (isSimpleExpr(expr)) { 
     23        return doVisit(visitor, expr); 
    2424    } else return doVisit(visitor, "(" ~ expr ~ ")"); 
    2525} 
     
    127127} 
    128128 
     129// Return true if the function is a single variable, or an intrinsic. 
     130bool isSimpleExpr(char [] s) 
     131{ 
     132    if (s.length==1) return true; 
     133    if (s[0]<'a' || s[0]>'z') return false; 
     134    return exprLength(s)==s.length; 
     135} 
     136 
    129137unittest { 
    130138    assert(exprLength("A*B")==1); 
     
    142150bool expressionContainsAssignment(char [] expr) 
    143151{ 
     152    if (isSimpleExpr(expr)) return false; 
    144153    // BUG: also need to deal with comma, ?:, &&, ||, is, !is, in,  
    145154    // unary &, unary ! 
    146155    if (expr.length>1 && expr[0]=='(') expr = expr[1..$-1]; 
    147     else if (expr.length==1 && ((expr[0]>='A' && expr[0]<='Z') || expr[0]=='$')){ 
    148         return false; 
    149     } 
    150     if (expr.length>3 && (expr[0]>='a' && expr[1]<='z')) { // function 
    151         return false; 
    152     } 
    153156    if (expr.length>2 && (expr[0..2]=="++" || expr[0..2]=="--")) { 
    154157        return false; 
     
    158161    } 
    159162    if (expr.length>2 && (expr[$-2..$]=="++" || expr[$-2..$]=="--")) { 
    160         return false; // BUG: actually this is an assignment 
     163        return false; // BUG: actually this _is_ an assignment 
    161164    } 
    162165    int y = exprLength(expr);