![Avatar](https://secure.gravatar.com/avatar/537d208f522e2d50f727370037b3a75f.jpg?s=64&d=identicon&r=g)
Hi
I've been working on a VBScript syntax language for the last few months (not full time) and I'm about to embark on the same task for JavaScript. The VBScript implementation is not 100% complete, but I decided to get started on JavaScript now as they will share some common code.
I've been looking at the makeup of JavaScript and the only major issue I see at the moment (I'm sure I will find more later) is how to parse JavaScript classes. JavaScript classes are something of a hack, in that they are not declared as such :
function House(name,rooms,price,garage) {
this.name=name;
this.rooms=rooms;
this.price=price;
this.garage=garage;
}
house1 = new House('House 1',4,100000,false);
The thing that determines whether the method House is a constructor or not is the assignment to "this.xxxxx"
As to how to deal with this in the grammar/Ast, my first thought would be to walk the block statement (as it's assigned to the method declaration) and check for assignment statements and then check for this.xxx on the left side of the assignment.. if so then flag the method as a class constructor.
Oh, and it gets worse with class methods :
function view() {
with (this) document.write(name+' has '+rooms+' rooms, '+(garage?'a':'no')+' garage, and costs £'+price+'<BR>');
}
House.prototype.view = view;
The assignment of methods can happen outside of the object constructor, I can see that is going to be fun to parse and hook up for intellisense!
Anyone have any other suggestions?
Regards
Vincent.
I've been working on a VBScript syntax language for the last few months (not full time) and I'm about to embark on the same task for JavaScript. The VBScript implementation is not 100% complete, but I decided to get started on JavaScript now as they will share some common code.
I've been looking at the makeup of JavaScript and the only major issue I see at the moment (I'm sure I will find more later) is how to parse JavaScript classes. JavaScript classes are something of a hack, in that they are not declared as such :
function House(name,rooms,price,garage) {
this.name=name;
this.rooms=rooms;
this.price=price;
this.garage=garage;
}
house1 = new House('House 1',4,100000,false);
The thing that determines whether the method House is a constructor or not is the assignment to "this.xxxxx"
As to how to deal with this in the grammar/Ast, my first thought would be to walk the block statement (as it's assigned to the method declaration) and check for assignment statements and then check for this.xxx on the left side of the assignment.. if so then flag the method as a class constructor.
Oh, and it gets worse with class methods :
function view() {
with (this) document.write(name+' has '+rooms+' rooms, '+(garage?'a':'no')+' garage, and costs £'+price+'<BR>');
}
House.prototype.view = view;
The assignment of methods can happen outside of the object constructor, I can see that is going to be fun to parse and hook up for intellisense!
Anyone have any other suggestions?
Regards
Vincent.