summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-07-21 02:17:43 -0400
committerJesse Luehrs <doy@tozt.net>2013-07-21 02:17:43 -0400
commit2616052469b26e77c2f9eb161c7bffe78d3c35e8 (patch)
tree36215c91949fa73982317970ad1f52860b4918aa
parentadddde6006f8e3b9c330361f0f1734b3f6072d01 (diff)
downloadparse-keyword-2616052469b26e77c2f9eb161c7bffe78d3c35e8.tar.gz
parse-keyword-2616052469b26e77c2f9eb161c7bffe78d3c35e8.zip
improve the api a bit
-rw-r--r--Keyword.xs24
-rw-r--r--lib/Parse/Keyword.pm4
-rw-r--r--t/try/lib/Try.pm12
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
@@ -79,17 +79,6 @@ lex_read_space()
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:
I32 floor;
@@ -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;
}