fix(muscript): handle "this" correctly
This commit is contained in:
parent
c8b5a186ba
commit
ab6c3b5b2d
|
@ -326,17 +326,18 @@ public class Parser extends VersionedComponent {
|
|||
|
||||
private Expr primary() {
|
||||
if (match(Token.Null)) return Expr.literalNull(previous.location());
|
||||
if (match(Token.String)) return "this".equals(previous.lexeme()) ? new This(previous.location()) : Expr.literal(previous.location(), previous.lexeme());
|
||||
if (match(Token.String)) return Expr.literal(previous.location(), previous.lexeme());
|
||||
if (match(Token.True, Token.False)) return Expr.literal(previous.location(), previous.lexeme().equals("true"));
|
||||
if (match(Token.Number)) return Expr.literal(previous.location(), Double.parseDouble(previous.lexeme()));
|
||||
if (match(Token.Identifier)) {
|
||||
CodeLocation location = previous.location();
|
||||
String name = previous.lexeme();
|
||||
if (match(Token.Assign)) {
|
||||
if (name.equals("this")) throw error("Cannot assign to 'this' keyword");
|
||||
Expr expr = expression();
|
||||
return new DynamicAssign(location, name, ExprUtils.asDynamic(expr));
|
||||
}
|
||||
else return new Variable(location, name);
|
||||
else return name.equals("this") ? new This(location) : new Variable(location, name);
|
||||
}
|
||||
|
||||
if (match(Token.LeftParen)) {
|
||||
|
|
Loading…
Reference in New Issue