from d: any[] to d: any, so you can use a tuple to define the type of the parameter, which makes much more sense, instead of an array, since production rules match a specific sequence of tokens, in a particular order, for example, with a grammar like this:
that tuple is not assignable to any[], since the any[] array could be any length, less than 3, but that will never happen.
for it to be assignable to any[], the postprocessor should look like this:
function returnStatement(data: (ReturnToken | Expression | Semicolon)[]): ReturnStatement {
return {
type: 'ReturnStatement',
expression: data[1], // error, data[1] could be any of those 3 types
}
}
which adds the need for runtime type checking with type predicates or something.
this change wouldn't cause any compilation error on existing grammars because any[] is assignable to any, so any code assuming d is an array, will still work!
the interface currently looks like this
I suggest this small change
from
d: any[]
tod: any
, so you can use a tuple to define the type of the parameter, which makes much more sense, instead of an array, since production rules match a specific sequence of tokens, in a particular order, for example, with a grammar like this:and a postprocessor like this:
that tuple is not assignable to
any[]
, since theany[]
array could be any length, less than 3, but that will never happen. for it to be assignable toany[]
, the postprocessor should look like this:which adds the need for runtime type checking with type predicates or something.
this change wouldn't cause any compilation error on existing grammars because
any[]
is assignable toany
, so any code assumingd
is an array, will still work!