9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Repeated Bungetc or Bungetrune
@ 2007-02-15  0:39 Joel Salomon
  2007-02-15  0:58 ` Joel C. Salomon
  0 siblings, 1 reply; 4+ messages in thread
From: Joel Salomon @ 2007-02-15  0:39 UTC (permalink / raw)
  To: 9fans

Although bio(2) says:
	Bungetc and Bungetrune may back up a maximum of five bytes.
I’ve found that Bungetrune is idempotent.

The code in question is from my lexer (switching on the return value from Bgetrune):
	case 'l':	case 'L':
		switch(Bgetrune(bin)) {
		case '\'':
			return charlex(1);
		case '"':
			return strlex(1);
		default:
		Bungetrune(bin);
		}
		// fall through
	case 'a':	case 'b':	case 'c':	case 'd':	case 'e':
	case 'f':	case 'g':	case 'h':	case 'i':	case 'j':
	case 'k':		case 'm':	case 'n':	case 'o':
	case 'p':	case 'q':	case 'r':	case 's':	case 't':
	case 'u':	case 'v':	case 'w':	case 'x':	case 'y':
	case 'z':
	case 'A':	case 'B':	case 'C':	case 'D':	case 'E':
	case 'F':	case 'G':	case 'H':	case 'I':	case 'J':
	case 'K':		case 'M':	case 'N':	case 'O':
	case 'P':	case 'Q':	case 'R':	case 'S':	case 'T':
	case 'U':	case 'V':	case 'W':	case 'X':	case 'Y':
	case 'Z':
	case '_':
		Bungetrune(bin);
		return idlex();
This doesn’t work; identifiers beginning with ‘l’ lose their initial character.

>From a cursory reading of /sys/src/libbio/bgetc.c and
/sys/src/libbio/bgetrune.c, it seems that Bungetc will allow itself to
be called more than once where Bungetrune sets a condition to prevent
that (bp->runesize = 0;).  (Actually, it seems that there is no
hard-coded limit to how many times Bungetc can be called.  Will
arbitrary back-up work, or will something break deep within the Biobuf
if I abuse it?)

For this case anyway, where I know that the Rune read was a
single-byte character, is it safe to use Bungetc, and will that allow
me to back-up more than once?  I need (I think) three bytes of
back-up.

--Joel



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-02-15  9:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-15  0:39 [9fans] Repeated Bungetc or Bungetrune Joel Salomon
2007-02-15  0:58 ` Joel C. Salomon
2007-02-15  2:37   ` Joel C. Salomon
2007-02-15  9:05     ` Charles Forsyth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).