Keep original token for literals
This commit is contained in:
@@ -17,7 +17,7 @@ export abstract class Expr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Literal extends Expr {
|
export class Literal extends Expr {
|
||||||
constructor(public literal: ExpressionData) {
|
constructor(public literal: ExpressionData, public token: Token) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ export class Parser {
|
|||||||
|
|
||||||
if (this.match(TokenType.IDENTIFIER)) {
|
if (this.match(TokenType.IDENTIFIER)) {
|
||||||
let property = this.previous();
|
let property = this.previous();
|
||||||
expr = new IndexAccess(expr, new Literal(new data.StringData(property.lexeme)));
|
expr = new IndexAccess(expr, new Literal(new data.StringData(property.lexeme), property));
|
||||||
} else if (this.match(TokenType.STAR)) {
|
} else if (this.match(TokenType.STAR)) {
|
||||||
expr = new IndexAccess(expr, new Star());
|
expr = new IndexAccess(expr, new Star());
|
||||||
} else {
|
} else {
|
||||||
@@ -254,19 +254,19 @@ export class Parser {
|
|||||||
private primary(): Expr {
|
private primary(): Expr {
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case this.match(TokenType.FALSE):
|
case this.match(TokenType.FALSE):
|
||||||
return new Literal(new data.BooleanData(false));
|
return new Literal(new data.BooleanData(false), this.previous());
|
||||||
|
|
||||||
case this.match(TokenType.TRUE):
|
case this.match(TokenType.TRUE):
|
||||||
return new Literal(new data.BooleanData(true));
|
return new Literal(new data.BooleanData(true), this.previous());
|
||||||
|
|
||||||
case this.match(TokenType.NULL):
|
case this.match(TokenType.NULL):
|
||||||
return new Literal(new data.Null());
|
return new Literal(new data.Null(), this.previous());
|
||||||
|
|
||||||
case this.match(TokenType.NUMBER):
|
case this.match(TokenType.NUMBER):
|
||||||
return new Literal(new data.NumberData(this.previous().value as number));
|
return new Literal(new data.NumberData(this.previous().value as number), this.previous());
|
||||||
|
|
||||||
case this.match(TokenType.STRING):
|
case this.match(TokenType.STRING):
|
||||||
return new Literal(new data.StringData(this.previous().value as string));
|
return new Literal(new data.StringData(this.previous().value as string), this.previous());
|
||||||
|
|
||||||
case this.match(TokenType.LEFT_PAREN):
|
case this.match(TokenType.LEFT_PAREN):
|
||||||
const expr = this.expression();
|
const expr = this.expression();
|
||||||
|
|||||||
Reference in New Issue
Block a user