[ragel-users] Re: integrating ragel w/ bison

Adrian Thurston thurs... at cs.queensu.ca
Thu Jan 4 00:47:11 UTC 2007


Jason wrote:
> Would you just make repeated calls to the scanner? i.e. would the state
> be such that it just picks up where you left off?

That's what I was thinking. I haven't tried this out, but you should be able
to do something like the following. Note that you need to manually get local
copies of p and pe because the access statement does not affect them.

void scan( Scanner *s )
{
	char *p = s->p;
	char *pe = s->pe;

	while ( true ) {
		if ( p == pe ) {
			check_for_preserve_condition();
			if ( ! fetch_more_data() )
				return EOF;
		}

		token = no_token;

		%%{
			machine Scanner;
			access s->;

			main := |*

			# Identifiers
			( [a-zA-Z_] [a-zA-Z0-9_]* ) =>
				{ token = Identifier; fbreak; };

			# Whitespace
			[ \t\n];

			# Anything else
			any => { token = *p; fbreak; };

			*|;

			write exec;
		}%%

		if ( token != no_token ) {
			s->p = p;
			s->pe = pe;
			return token;
		}

		if ( s->cs == Scanner_error )
			return ERR;
	}
}



More information about the ragel-users mailing list