Utilize peek_token where possible

This commit is contained in:
madmaurice 2021-04-06 23:17:38 +02:00
parent f86caf6b5f
commit 42b5567c29

View file

@ -481,7 +481,7 @@ sub parser_list {
slurp_token($ts, LPAREN, "Expected ( after ' for list");
my @elements;
while ($ts->[0]->{type} != RPAREN)
while (!peek_token($ts,RPAREN))
{
push @elements, parser_expr($ts);
}
@ -500,7 +500,7 @@ my %macros;
sub parser_call {
my $ts = shift;
if ($ts->[0]->{type} == IDENT)
if (peek_token($ts,IDENT))
{
my $name = $ts->[0]->{value};
if (defined $macros{$name})
@ -516,7 +516,7 @@ sub parser_call {
my @params;
while ($ts->[0]->{type} != RPAREN)
while (!peek_token($ts,RPAREN))
{
push @params, parser_expr($ts);
}
@ -539,14 +539,14 @@ sub gen_macro_let {
my @assignments;
while ($ts->[0]->{type} != RPAREN)
while (!peek_token($ts,RPAREN))
{
slurp_token($ts, LPAREN, "Expected ( before assignment in let");
my $ident = slurp_token($ts, IDENT)->{value};
my $expr;
if ($ts->[0]->{type} == RPAREN)
if (peek_token($ts,RPAREN))
{
$expr = sub { return undef };
}
@ -585,7 +585,7 @@ sub macro_lambda {
slurp_token($ts, LPAREN, "Expected ( after lambda keyword");
my @param_list;
while ($ts->[0]->{type} != RPAREN)
while (!peek_token($ts,RPAREN))
{
my $ident = slurp_token($ts, IDENT)->{value};
push @param_list, $ident;
@ -645,7 +645,7 @@ sub macro_progn {
my @steps;
while ($ts->[0]->{type} != RPAREN)
while (!peek_token($ts,RPAREN))
{
push @steps, parser_expr($ts);
}
@ -689,7 +689,7 @@ sub macro_cond {
my $ts = shift;
my @cases;
while ($ts->[0]->{type} != RPAREN)
while (!peek_token($ts,RPAREN))
{
die "Expected ( before case in cond"
unless (shift @$ts)->{type} == LPAREN;
@ -783,7 +783,7 @@ sub macro_and {
my $ts = shift;
my @operands_parsed;
while ( $ts->[0]->{type} != RPAREN )
while (!peek_token($ts,RPAREN))
{
push @operands_parsed, parser_expr($ts);
}
@ -807,7 +807,7 @@ sub macro_or {
my $ts = shift;
my @operands_parsed;
while ( $ts->[0]->{type} != RPAREN )
while (!peek_token($ts,RPAREN))
{
push @operands_parsed, parser_expr($ts);
}