From 2616052469b26e77c2f9eb161c7bffe78d3c35e8 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 21 Jul 2013 02:17:43 -0400 Subject: improve the api a bit --- Keyword.xs | 24 ++++++------------------ lib/Parse/Keyword.pm | 4 +--- t/try/lib/Try.pm | 12 +++++------- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/Keyword.xs b/Keyword.xs index a1de202..56daf49 100644 --- a/Keyword.xs +++ b/Keyword.xs @@ -78,17 +78,6 @@ lex_read_space() PL_curcop = &PL_compiling; lex_read_space(0); -SV* -lex_peek_unichar() - PREINIT: - I32 ch; - CODE: - PL_curcop = &PL_compiling; - ch = lex_peek_unichar(0); - RETVAL = newSVpvf("%c", (int)ch); /* XXX unicode */ - OUTPUT: - RETVAL - SV* parse_block() PREINIT: @@ -105,8 +94,8 @@ parse_block() OUTPUT: RETVAL -void -ensure_linestr_len(len) +SV * +lex_peek(len) UV len CODE: PL_curcop = &PL_compiling; @@ -115,11 +104,10 @@ ensure_linestr_len(len) break; } } - -SV* -linestr() - CODE: - RETVAL = newSVpvn(PL_parser->bufptr, PL_parser->bufend - PL_parser->bufptr); + if (PL_parser->bufend - PL_parser->bufptr < len) { + len = PL_parser->bufend - PL_parser->bufptr; + } + RETVAL = newSVpvn(PL_parser->bufptr, len); /* XXX unicode? */ OUTPUT: RETVAL diff --git a/lib/Parse/Keyword.pm b/lib/Parse/Keyword.pm index aca308f..ed183a3 100644 --- a/lib/Parse/Keyword.pm +++ b/lib/Parse/Keyword.pm @@ -27,12 +27,10 @@ sub import { } my @helpers = qw( - lex_peek_unichar + lex_peek lex_read_space lex_read_to parse_block - ensure_linestr_len - linestr ); for my $helper (@helpers) { diff --git a/t/try/lib/Try.pm b/t/try/lib/Try.pm index 6de5bf8..64e6148 100644 --- a/t/try/lib/Try.pm +++ b/t/try/lib/Try.pm @@ -24,26 +24,24 @@ sub try_parser { lex_read_space; - die "syntax error" unless lex_peek_unichar eq '{'; + die "syntax error" unless lex_peek(1) eq '{'; $try = parse_block; lex_read_space; - ensure_linestr_len(6); - if (linestr =~ /^catch\b/) { + if (lex_peek(6) =~ /^catch\b/) { lex_read_to(5); lex_read_space; - die "syntax error" unless lex_peek_unichar eq '{'; + die "syntax error" unless lex_peek(1) eq '{'; $catch = parse_block; } lex_read_space; - ensure_linestr_len(8); - if (linestr =~ /^finally\b/) { + if (lex_peek(8) =~ /^finally\b/) { lex_read_to(7); lex_read_space; - die "syntax error" unless lex_peek_unichar eq '{'; + die "syntax error" unless lex_peek(1) eq '{'; $finally = parse_block; } -- cgit v1.2.3-54-g00ecf