Minor modifications to the grammar to allow a single trailing comma for function call arguments, array literal and object literals. Adjusted tests accordingly

This commit is contained in:
matehat 2010-03-26 11:44:25 -04:00
parent c8f969b4a2
commit b9b87f7d8e
5 changed files with 152 additions and 112 deletions

View File

@ -233,6 +233,10 @@
return new ObjectNode($2);
}), o("{ IndentedAssignList }", function() {
return new ObjectNode($2);
}), o("{ AssignList , }", function() {
return new ObjectNode($2);
}), o("{ IndentedAssignList , }", function() {
return new ObjectNode($2);
})
],
// Class definitions have optional bodies of prototype property assignments,
@ -292,11 +296,15 @@
// The list of arguments to a function call.
Arguments: [o("CALL_START ArgList CALL_END", function() {
return $2;
}), o("CALL_START ArgList , CALL_END", function() {
return $2;
})
],
// Calling super.
Super: [o("SUPER CALL_START ArgList CALL_END", function() {
return new CallNode('super', $3);
}), o("SUPER CALL_START ArgList , CALL_END", function() {
return new CallNode('super', $3);
})
],
// A reference to the *this* current object, either naked or to a property.
@ -323,6 +331,8 @@
// The array literal.
Array: [o("[ ArgList ]", function() {
return new ArrayNode($2);
}), o("[ ArgList , ]", function() {
return new ArrayNode($2);
})
],
// The **ArgList** is both the list of objects passed into a function call,

File diff suppressed because one or more lines are too long

View File

@ -230,6 +230,8 @@ grammar: {
Object: [
o "{ AssignList }", -> new ObjectNode $2
o "{ IndentedAssignList }", -> new ObjectNode $2
o "{ AssignList , }", -> new ObjectNode $2
o "{ IndentedAssignList , }", -> new ObjectNode $2
]
# Class definitions have optional bodies of prototype property assignments,
@ -283,11 +285,13 @@ grammar: {
# The list of arguments to a function call.
Arguments: [
o "CALL_START ArgList CALL_END", -> $2
o "CALL_START ArgList , CALL_END", -> $2
]
# Calling super.
Super: [
o "SUPER CALL_START ArgList CALL_END", -> new CallNode 'super', $3
o "SUPER CALL_START ArgList , CALL_END", -> new CallNode 'super', $3
]
# A reference to the *this* current object, either naked or to a property.
@ -311,6 +315,7 @@ grammar: {
# The array literal.
Array: [
o "[ ArgList ]", -> new ArrayNode $2
o "[ ArgList , ]", -> new ArrayNode $2
]
# The **ArgList** is both the list of objects passed into a function call,

View File

@ -111,3 +111,13 @@ ok func(1)(2)(3) is 3
# Ensure that functions with the same name don't clash with helper functions.
del: -> 5
ok del() is 5
# Ensure that functions can have a trailing comma in their argument list
mult: (x, mids..., y) ->
x: * n for n in mids
x: * y
x
ok mult(1, 2,) is 2
ok mult(1, 2, 3,) is 6
ok mult(10,[1..6]...,) is 7200

View File

@ -25,6 +25,11 @@ reg: /\\/
ok reg(str) and str is '\\'
trailing_comma: [1, 2, 3,]
ok (trailing_comma[0] is 1) and (trailing_comma[2] is 3) and (trailing_comma.length is 3)
trailing_comma: {k1: "v1", k2: 4, k3: (-> true),}
ok trailing_comma.k3() and (trailing_comma.k2 is 4) and (trailing_comma.k1 is "v1")
money$: 'dollars'