Permalink
Browse files

experimental syntactic sugar for var declaratios initialized with new

  • Loading branch information...
1 parent 3357c6a commit 9b4a16782707476add2ab7dcd2b5edb0256d3bb0 @NotFound committed Jun 1, 2012
Showing with 52 additions and 4 deletions.
  1. +26 −2 winxedst1.winxed
  2. +26 −2 winxedst2.winxed
View
@@ -2095,9 +2095,33 @@ function parseStatement(var tk, var owner)
return new CompoundStatement(t, tk, owner);
if (t.isop(":")) {
var open = tk.get();
- if (! open.isop("("))
+ switch {
+ case open.isop("("):
+ return parseSig(t, tk, owner);
+ case open.isidentifier():
+ // EXPERIMENTAL
+ var cl = new ClassSpecifierId(tk, owner, open);
+ var tname = tk.get();
+ RequireIdentifier(tname);
+
+ // Violating encapsulation for fun and profit!
+ var varst = new VarStatement;
+ varst.initvarbase(tname, owner, tname, 0);
+ var newexpr = new NewQualifiedExpr;
+ newexpr.Expr(varst, tname);
+ newexpr.nskey = cl;
+ t = tk.get();
+ if (t.isop("(")) {
+ newexpr.parseinitializer(tk);
+ t = tk.get();
+ }
+ RequireOp(";", t);
+ varst.init = newexpr;
+
+ return varst;
+ default:
Unexpected("':'", t);
- return parseSig(t, tk, owner);
+ }
}
switch (t.checkkeyword()) {
View
@@ -2520,9 +2520,33 @@ function parseStatement(var tk, var owner)
return new PiropStatement(t, tk, owner);
if (t.isop(":")) {
var open = tk.get();
- if (! open.isop("("))
+ switch {
+ case open.isop("("):
+ return parseSig(t, tk, owner);
+ case open.isidentifier():
+ // EXPERIMENTAL
+ var cl = new ClassSpecifierId(tk, owner, open);
+ var tname = tk.get();
+ RequireIdentifier(tname);
+
+ // Violating encapsulation for fun and profit!
+ var varst = new VarStatement;
+ varst.initvarbase(tname, owner, tname, 0);
+ var newexpr = new NewQualifiedExpr;
+ newexpr.Expr(varst, tname);
+ newexpr.nskey = cl;
+ t = tk.get();
+ if (t.isop("(")) {
+ newexpr.parseinitializer(tk);
+ t = tk.get();
+ }
+ RequireOp(";", t);
+ varst.init = newexpr;
+
+ return varst;
+ default:
Unexpected("':'", t);
- return parseSig(t, tk, owner);
+ }
}
switch (t.checkkeyword()) {

0 comments on commit 9b4a167

Please sign in to comment.