mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Self-compiler: object literals.
This commit is contained in:
@@ -45,11 +45,19 @@
|
||||
return new Expressions();
|
||||
})
|
||||
],
|
||||
// All hard-coded values. These can be printed straight to JavaScript.
|
||||
Literal: [o("NUMBER", function() {
|
||||
Identifier: [o("IDENTIFIER", function() {
|
||||
return new LiteralNode(yytext);
|
||||
})
|
||||
],
|
||||
AlphaNumeric: [o("NUMBER", function() {
|
||||
return new LiteralNode(yytext);
|
||||
}), o("STRING", function() {
|
||||
return new LiteralNode(yytext);
|
||||
})
|
||||
],
|
||||
// All hard-coded values. These can be printed straight to JavaScript.
|
||||
Literal: [o("AlphaNumeric", function() {
|
||||
return $1;
|
||||
}), o("JS", function() {
|
||||
return new LiteralNode(yytext);
|
||||
}), o("REGEX", function() {
|
||||
@@ -80,12 +88,10 @@
|
||||
})
|
||||
],
|
||||
// Assignment within an object literal (can be quoted).
|
||||
AssignObj: [o("IDENTIFIER ASSIGN Expression", function() {
|
||||
return new AssignNode(new ValueNode(new LiteralNode(yytext)), $3, 'object');
|
||||
}), o("STRING ASSIGN Expression", function() {
|
||||
return new AssignNode(new ValueNode(new LiteralNode(yytext)), $3, 'object');
|
||||
}), o("NUMBER ASSIGN Expression", function() {
|
||||
return new AssignNode(new ValueNode(new LiteralNode(yytext)), $3, 'object');
|
||||
AssignObj: [o("Identifier ASSIGN Expression", function() {
|
||||
return new AssignNode(new ValueNode($1), $3, 'object');
|
||||
}), o("AlphaNumeric ASSIGN Expression", function() {
|
||||
return new AssignNode(new ValueNode($1), $3, 'object');
|
||||
}), o("Comment")
|
||||
],
|
||||
// A return statement.
|
||||
@@ -200,8 +206,8 @@
|
||||
})
|
||||
],
|
||||
// Expressions that can be treated as values.
|
||||
Value: [o("IDENTIFIER", function() {
|
||||
return new ValueNode(new LiteralNode(yytext));
|
||||
Value: [o("Identifier", function() {
|
||||
return new ValueNode($1);
|
||||
}), o("Literal", function() {
|
||||
return new ValueNode($1);
|
||||
}), o("Array", function() {
|
||||
@@ -221,12 +227,12 @@
|
||||
})
|
||||
],
|
||||
// Accessing into an object or array, through dot or index notation.
|
||||
Accessor: [o("PROPERTY_ACCESS IDENTIFIER", function() {
|
||||
return new AccessorNode(new LiteralNode(yytext));
|
||||
}), o("PROTOTYPE_ACCESS IDENTIFIER", function() {
|
||||
return new AccessorNode(new LiteralNode(yytext), 'prototype');
|
||||
}), o("SOAK_ACCESS IDENTIFIER", function() {
|
||||
return new AccessorNode(new LiteralNode(yytext), 'soak');
|
||||
Accessor: [o("PROPERTY_ACCESS Identifier", function() {
|
||||
return new AccessorNode($2);
|
||||
}), o("PROTOTYPE_ACCESS Identifier", function() {
|
||||
return new AccessorNode($2, 'prototype');
|
||||
}), o("SOAK_ACCESS Identifier", function() {
|
||||
return new AccessorNode($2, 'soak');
|
||||
}), o("Index"), o("Slice", function() {
|
||||
return new SliceNode($1);
|
||||
})
|
||||
@@ -247,11 +253,11 @@
|
||||
}), o("AssignObj", function() {
|
||||
return [$1];
|
||||
}), o("AssignList , AssignObj", function() {
|
||||
return $1.push($3);
|
||||
return $1.concat([$3]);
|
||||
}), o("AssignList TERMINATOR AssignObj", function() {
|
||||
return $1.push($3);
|
||||
return $1.concat([$3]);
|
||||
}), o("AssignList , TERMINATOR AssignObj", function() {
|
||||
return $1.push($4);
|
||||
return $1.concat([$4]);
|
||||
}), o("INDENT AssignList OUTDENT", function() {
|
||||
return $2;
|
||||
})
|
||||
@@ -290,8 +296,8 @@
|
||||
// This references, either naked or to a property.
|
||||
This: [o("@", function() {
|
||||
return new ThisNode();
|
||||
}), o("@ IDENTIFIER", function() {
|
||||
return new ThisNode(yytext);
|
||||
}), o("@ Identifier", function() {
|
||||
return new ThisNode($2);
|
||||
})
|
||||
],
|
||||
// The range literal.
|
||||
@@ -321,13 +327,13 @@
|
||||
}), o("INDENT Expression", function() {
|
||||
return [$2];
|
||||
}), o("ArgList , Expression", function() {
|
||||
return $1.push($3);
|
||||
return $1.concat([$3]);
|
||||
}), o("ArgList TERMINATOR Expression", function() {
|
||||
return $1.push($3);
|
||||
return $1.concat([$3]);
|
||||
}), o("ArgList , TERMINATOR Expression", function() {
|
||||
return $1.push($4);
|
||||
return $1.concat([$4]);
|
||||
}), o("ArgList , INDENT Expression", function() {
|
||||
return $1.push($4);
|
||||
return $1.concat([$4]);
|
||||
}), o("ArgList OUTDENT", function() {
|
||||
return $1;
|
||||
})
|
||||
@@ -351,7 +357,7 @@
|
||||
})
|
||||
],
|
||||
// A catch clause.
|
||||
Catch: [o("CATCH IDENTIFIER Block", function() {
|
||||
Catch: [o("CATCH Identifier Block", function() {
|
||||
return [$2, $3];
|
||||
})
|
||||
],
|
||||
@@ -383,9 +389,9 @@
|
||||
})
|
||||
],
|
||||
// An array comprehension has variables for the current element and index.
|
||||
ForVariables: [o("IDENTIFIER", function() {
|
||||
ForVariables: [o("Identifier", function() {
|
||||
return [$1];
|
||||
}), o("IDENTIFIER , IDENTIFIER", function() {
|
||||
}), o("Identifier , Identifier", function() {
|
||||
return [$1, $3];
|
||||
})
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user