Refactored parameter/argument list productions
Now the ellipsis is validated at parse time directly in the grammar, instead of in the sunParameterList constructor (possibly giving better error messages). I was also able to remove the parameter/argument transcient productions.
This commit is contained in:
parent
e57a55056b
commit
e575a8a741
3 changed files with 4 additions and 15 deletions
|
@ -61,12 +61,7 @@ namespace arookas {
|
|||
public sunParameterInfo ParameterInfo { get { return new sunParameterInfo(Parameters, IsVariadic); } }
|
||||
|
||||
public sunParameterList(sunSourceLocation location)
|
||||
: base(location) {
|
||||
var count = this.Count(i => i is sunEllipsis);
|
||||
if (count > 1 || (count > 0 && !(this[Count - 1] is sunEllipsis))) {
|
||||
throw new sunVariadicParameterListException(this);
|
||||
}
|
||||
}
|
||||
: base(location) { }
|
||||
}
|
||||
|
||||
class sunEllipsis : sunNode {
|
||||
|
|
|
@ -52,9 +52,7 @@ namespace arookas {
|
|||
case __sunConstants.BINARY_OPERATOR:
|
||||
case __sunConstants.UNARY_OPERATOR:
|
||||
case __sunConstants.AUGMENT_OPERATOR:
|
||||
case __sunConstants.TERM:
|
||||
case __sunConstants.PARAMETER:
|
||||
case __sunConstants.ARGUMENT: {
|
||||
case __sunConstants.TERM: {
|
||||
return ast[0];
|
||||
}
|
||||
}
|
||||
|
@ -176,9 +174,7 @@ namespace arookas {
|
|||
case __sunConstants.FUNCTION_CALL: return new sunFunctionCall(location);
|
||||
|
||||
case __sunConstants.PARAMETER_LIST: return new sunParameterList(location);
|
||||
case __sunConstants.PARAMETER: return new sunNode(location);
|
||||
case __sunConstants.ARGUMENT_LIST: return new sunNode(location);
|
||||
case __sunConstants.ARGUMENT: return new sunNode(location);
|
||||
}
|
||||
|
||||
// variables
|
||||
|
|
|
@ -193,10 +193,8 @@ prefix_augment = augment_operator IDENTIFIER;
|
|||
function_definition = FUNCTION IDENTIFIER parameter_list statement_block;
|
||||
function_call = IDENTIFIER argument_list;
|
||||
|
||||
parameter_list = L_PAREN [parameter {COMMA parameter}] R_PAREN; // e.g. (a, b, ...)
|
||||
parameter = IDENTIFIER | ELLIPSIS;
|
||||
argument_list = L_PAREN [argument {COMMA argument}] R_PAREN;
|
||||
argument = expression;
|
||||
parameter_list = L_PAREN [IDENTIFIER {COMMA IDENTIFIER} [COMMA ELLIPSIS] | ELLIPSIS] R_PAREN; // e.g. (a, b, ...)
|
||||
argument_list = L_PAREN [expression {COMMA expression}] R_PAREN;
|
||||
|
||||
// builtins
|
||||
builtin_declaration = BUILTIN IDENTIFIER parameter_list;
|
||||
|
|
Loading…
Reference in a new issue