in lib/generator.js [1591:1715]
visitExpr(ast, level) {
if (ast.type === 'boolean') {
this.emit(ast.value);
} else if (ast.type === 'property_access') {
this.visitPropertyAccess(ast);
} else if (ast.type === 'string') {
this.emit(`'${_string(ast.value)}'`);
} else if (ast.type === 'number') {
this.emit(ast.value.value);
} else if (ast.type === 'null') {
this.emit('null');
} else if (ast.type === 'object') {
this.visitObject(ast, level);
} else if (ast.type === 'variable') {
if(ast.inferred && ast.inferred.type === 'basic' && ast.inferred.name === 'class') {
this.emit(`${_avoidKeywords(_name(ast.id))}::class`);
} else {
this.emit(`$${_avoidKeywords(_name(ast.id))}`);
}
} else if (ast.type === 'virtualVariable') {
this.emit(`$this->${_vid(ast.vid)}`);
} else if (ast.type === 'decrement') {
if (ast.position === 'front') {
this.emit('--');
}
this.visitExpr(ast.expr, level);
if (ast.position === 'backend') {
this.emit('--');
}
} else if (ast.type === 'increment') {
if (ast.position === 'front') {
this.emit('++');
}
this.visitExpr(ast.expr, level);
if (ast.position === 'backend') {
this.emit('++');
}
} else if (ast.type === 'template_string') {
this.emit('\'');
for (var i = 0; i < ast.elements.length; i++) {
var item = ast.elements[i];
if (item.type === 'element') {
this.emit(_string(item.value));
} else if (item.type === 'expr') {
this.emit('\' . ');
if(item.expr.inferred && item.expr.inferred.name !== 'string') {
this.emit('(string)');
}
if(_isBinaryOp(item.expr.type)) {
this.emit('(');
}
this.visitExpr(item.expr, level);
if(_isBinaryOp(item.expr.type)) {
this.emit(')');
}
this.emit(' . \'');
} else {
throw new Error('unimpelemented');
}
}
this.emit('\'');
} else if (ast.type === 'call') {
this.visitCall(ast, level);
} else if (ast.type === 'construct') {
this.visitConstruct(ast, level);
} else if (ast.type === 'array') {
this.visitArray(ast, level);
} else if (ast.type === 'group') {
this.emit('(');
this.visitExpr(ast.expr, level);
this.emit(')');
} else if (_isBinaryOp(ast.type)) {
this.visitExpr(ast.left, level);
if (ast.type === 'or') {
this.emit(' || ');
} else if (ast.type === 'add') {
if(ast.inferred && ast.inferred.type === 'basic' && ast.inferred.name === 'string') {
this.emit(' . ');
} else {
this.emit(' + ');
}
} else if (ast.type === 'subtract') {
this.emit(' - ');
} else if (ast.type === 'div') {
this.emit(' / ');
} else if (ast.type === 'multi') {
this.emit(' * ');
} else if (ast.type === 'and') {
this.emit(' && ');
} else if (ast.type === 'or') {
this.emit(' || ');
} else if (ast.type === 'lte') {
this.emit(' <= ');
} else if (ast.type === 'lt') {
this.emit(' < ');
} else if (ast.type === 'gte') {
this.emit(' >= ');
} else if (ast.type === 'gt') {
this.emit(' > ');
} else if (ast.type === 'neq') {
this.emit(' != ');
} else if (ast.type === 'eq') {
this.emit(' == ');
}
this.visitExpr(ast.right, level);
} else if (ast.type === 'group') {
this.emit('(');
this.visitExpr(ast.expr, level);
this.emit('(');
} else if (ast.type === 'not') {
this.emit('!');
this.visitExpr(ast.expr, level);
} else if (ast.type === 'construct_model') {
this.visitConstructModel(ast, level);
} else if (ast.type === 'map_access') {
this.visitMapAccess(ast);
} else if (ast.type === 'array_access') {
this.visitArrayAccess(ast);
} else if (ast.type === 'super') {
this.visitSuper(ast, level);
} else {
console.log(ast);
throw new Error('unimpelemented');
}
}