From 42b5567c29ed774a2b93a15051299b738eff17f7 Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Tue, 6 Apr 2021 23:17:38 +0200 Subject: [PATCH] Utilize peek_token where possible --- lib/Minilisp.pm | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Minilisp.pm b/lib/Minilisp.pm index 5866270..de2c8ab 100644 --- a/lib/Minilisp.pm +++ b/lib/Minilisp.pm @@ -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); }