public AssignableNode assignable(Token lhs, Node value) {
checkExpression(value);
switch (lhs.getType()) {
case Tokens.kSELF:
throw new SyntaxException(PID.CANNOT_CHANGE_SELF, lhs.getPosition(),
lexer.getCurrentLine(), "Can't change the value of self");
case Tokens.kNIL:
throw new SyntaxException(PID.INVALID_ASSIGNMENT, lhs.getPosition(),
lexer.getCurrentLine(), "Can't assign to nil", "nil");
case Tokens.kTRUE:
throw new SyntaxException(PID.INVALID_ASSIGNMENT, lhs.getPosition(),
lexer.getCurrentLine(), "Can't assign to true", "true");
case Tokens.kFALSE:
throw new SyntaxException(PID.INVALID_ASSIGNMENT, lhs.getPosition(),
lexer.getCurrentLine(), "Can't assign to false", "false");
case Tokens.k__FILE__:
throw new SyntaxException(PID.INVALID_ASSIGNMENT, lhs.getPosition(),
lexer.getCurrentLine(), "Can't assign to __FILE__", "__FILE__");
case Tokens.k__LINE__:
throw new SyntaxException(PID.INVALID_ASSIGNMENT, lhs.getPosition(),
lexer.getCurrentLine(), "Can't assign to __LINE__", "__LINE__");
case Tokens.tIDENTIFIER:
return currentScope.assign(lhs.getPosition(), (String) lhs.getValue(), makeNullNil(value));
case Tokens.tCONSTANT:
if (isInDef() || isInSingle()) {
throw new SyntaxException(PID.DYNAMIC_CONSTANT_ASSIGNMENT, lhs.getPosition(),
lexer.getCurrentLine(), "dynamic constant assignment");
}
return new ConstDeclNode(lhs.getPosition(), (String) lhs.getValue(), null, value);
case Tokens.tIVAR:
return new InstAsgnNode(lhs.getPosition(), (String) lhs.getValue(), value);
case Tokens.tCVAR:
if (isInDef() || isInSingle()) {
return new ClassVarAsgnNode(lhs.getPosition(), (String) lhs.getValue(), value);
}
return new ClassVarDeclNode(lhs.getPosition(), (String) lhs.getValue(), value);
case Tokens.tGVAR:
return new GlobalAsgnNode(lhs.getPosition(), (String) lhs.getValue(), value);
}
throw new SyntaxException(PID.BAD_IDENTIFIER, lhs.getPosition(), lexer.getCurrentLine(),
"identifier " + (String) lhs.getValue() + " is not valid", lhs.getValue());
}