From 252debb4897f5b2db9ef0556eeda1f779f239123 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 12 Aug 2014 19:40:32 +0900 Subject: [PATCH] remember dispatch string --- src/read.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/read.c b/src/read.c index 4cd8963b..41297b67 100644 --- a/src/read.c +++ b/src/read.c @@ -666,6 +666,8 @@ static pic_value read_nullable(pic_state *pic, struct pic_port *port, int c) { struct pic_trie *trie = pic->reader->trie; + char buf[128]; + size_t i = 0; c = skip(port, c); @@ -676,14 +678,28 @@ read_nullable(pic_state *pic, struct pic_port *port, int c) if (trie->table[c] == NULL) { read_error(pic, "invalid character at the seeker head"); } - for (trie = trie->table[c]; trie->table[peek(port)] != NULL; trie = trie->table[c]) { - c = next(port); + + buf[i++] = c; + + while (i < sizeof buf) { + trie = trie->table[c]; + + if ((c = peek(port)) == EOF) { + break; + } + if (trie->table[c] == NULL) { + break; + } + buf[i++] = next(port); + } + if (i == sizeof buf) { + read_error(pic, "too long dispatch string"); } if (trie->proc == NULL) { read_error(pic, "no reader registered for current string"); } - return pic_apply2(pic, trie->proc, pic_obj_value(port), pic_char_value(c)); + return pic_apply2(pic, trie->proc, pic_obj_value(port), pic_char_value(buf[i-1])); } static pic_value