1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

simplifying the grammar by replacing all of our trailing comma rules with an OptComma nonterminal.

This commit is contained in:
Jeremy Ashkenas 2010-04-25 21:17:46 -04:00
parent ca4ea7649d
commit 315a2c63fa
3 changed files with 171 additions and 192 deletions

View file

@ -169,6 +169,8 @@
return 'boundfunc';
})
],
// An optional, trailing comma.
OptComma: [o(''), o(',')],
// The list of parameters that a function accepts can be of any length.
ParamList: [o("", function() {
return [];
@ -241,13 +243,9 @@
})
],
// In CoffeeScript, an object literal is simply a list of assignments.
Object: [o("{ AssignList }", function() {
Object: [o("{ AssignList OptComma }", function() {
return new ObjectNode($2);
}), o("{ IndentedAssignList }", function() {
return new ObjectNode($2);
}), o("{ AssignList , }", function() {
return new ObjectNode($2);
}), o("{ IndentedAssignList , }", function() {
}), o("{ IndentedAssignList OptComma }", function() {
return new ObjectNode($2);
})
],
@ -266,9 +264,7 @@
})
],
// An **AssignList** within a block indentation.
IndentedAssignList: [o("INDENT AssignList OUTDENT", function() {
return $2;
}), o("INDENT AssignList , OUTDENT", function() {
IndentedAssignList: [o("INDENT AssignList OptComma OUTDENT", function() {
return $2;
})
],
@ -325,16 +321,12 @@
})
],
// 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() {
Arguments: [o("CALL_START ArgList OptComma 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() {
Super: [o("SUPER CALL_START ArgList OptComma CALL_END", function() {
return new CallNode('super', $3);
})
],
@ -365,9 +357,7 @@
})
],
// The array literal.
Array: [o("[ ArgList ]", function() {
return new ArrayNode($2);
}), o("[ ArgList , ]", function() {
Array: [o("[ ArgList OptComma ]", function() {
return new ArrayNode($2);
})
],
@ -388,7 +378,7 @@
return $1.concat([$4]);
}), o("ArgList , INDENT Expression", function() {
return $1.concat([$4]);
}), o("ArgList OUTDENT"), o("ArgList , OUTDENT")
}), o("ArgList OptComma OUTDENT")
],
// Just simple, comma-separated, required arguments (no fancy syntax). We need
// this to be separate from the **ArgList** for use in **Switch** blocks, where

File diff suppressed because one or more lines are too long

View file

@ -185,6 +185,12 @@ grammar: {
o "=>", -> 'boundfunc'
]
# An optional, trailing comma.
OptComma: [
o ''
o ','
]
# The list of parameters that a function accepts can be of any length.
ParamList: [
o "", -> []
@ -249,10 +255,8 @@ grammar: {
# In CoffeeScript, an object literal is simply a list of assignments.
Object: [
o "{ AssignList }", -> new ObjectNode $2
o "{ IndentedAssignList }", -> new ObjectNode $2
o "{ AssignList , }", -> new ObjectNode $2
o "{ IndentedAssignList , }", -> new ObjectNode $2
o "{ AssignList OptComma }", -> new ObjectNode $2
o "{ IndentedAssignList OptComma }", -> new ObjectNode $2
]
# Assignment of properties within an object literal can be separated by
@ -267,8 +271,7 @@ grammar: {
# An **AssignList** within a block indentation.
IndentedAssignList: [
o "INDENT AssignList OUTDENT", -> $2
o "INDENT AssignList , OUTDENT", -> $2
o "INDENT AssignList OptComma OUTDENT", -> $2
]
# Class definitions have optional bodies of prototype property assignments,
@ -320,14 +323,12 @@ grammar: {
# The list of arguments to a function call.
Arguments: [
o "CALL_START ArgList CALL_END", -> $2
o "CALL_START ArgList , CALL_END", -> $2
o "CALL_START ArgList OptComma 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
o "SUPER CALL_START ArgList OptComma CALL_END", -> new CallNode 'super', $3
]
# A reference to the *this* current object.
@ -355,8 +356,7 @@ grammar: {
# The array literal.
Array: [
o "[ ArgList ]", -> new ArrayNode $2
o "[ ArgList , ]", -> new ArrayNode $2
o "[ ArgList OptComma ]", -> new ArrayNode $2
]
# The **ArgList** is both the list of objects passed into a function call,
@ -370,8 +370,7 @@ grammar: {
o "ArgList TERMINATOR Expression", -> $1.concat [$3]
o "ArgList , TERMINATOR Expression", -> $1.concat [$4]
o "ArgList , INDENT Expression", -> $1.concat [$4]
o "ArgList OUTDENT"
o "ArgList , OUTDENT"
o "ArgList OptComma OUTDENT"
]
# Just simple, comma-separated, required arguments (no fancy syntax). We need