Improve macro parsing

This commit is contained in:
madmaurice 2021-04-04 01:44:28 +02:00
parent c909c8880d
commit ed59a6a04e

View file

@ -420,7 +420,10 @@ sub parser_call {
if (defined $macros{$name})
{
shift @$ts;
return $macros{$name}->($ts);
my $parsed = $macros{$name}->($ts);
my $rpar = shift @$ts;
die "Expected ) after macro $name" unless $rpar->{type} == RPAREN;
return $parsed;
}
}
@ -476,8 +479,8 @@ sub macro_let {
$pctx->{$ident->{value}} = $assignment;
}
$tok = shift @$ts;
die "Expected ) after parameter list in let" unless $tok->{type} == RPAREN;
die "Expected ) after parameter list in let" unless $ts->[0]->{type} == RPAREN;
shift @$ts;
my $inner = macro_progn($ts);
@ -510,8 +513,7 @@ sub macro_lambda {
my $body = parser_expr($ts);
$tok = shift @$ts;
die "Expected ) after lambda" unless $tok->{type} == RPAREN;
die "Expected ) after lambda" unless $ts->[0]->{type} == RPAREN;
return sub {
my $octx = shift;
@ -542,9 +544,7 @@ sub macro_if {
my $fbranch = parser_expr($ts);
my $tok = shift @$ts;
die "Expected ) after else expression" unless $tok->{type} == RPAREN;
die "Expected ) after else expression" unless $ts->[0]->{type} == RPAREN;
return sub {
my $ctx = shift;
@ -569,8 +569,6 @@ sub macro_progn {
push @steps, parser_expr($ts);
}
shift @$ts; # Remove RPAREN
return sub {
my $ctx = shift;