Alien-LibJIT

 view release on metacpan or  search on metacpan

libjit/tools/gen-rules-scanner.l  view on Meta::CPAN

		{
			break;
		}
		else if(ch == '*')
		{
			ch = input();
			while(ch == '*')
			{
				ch = input();
			}
			if(ch == EOF || ch == '/')
			{
				break;
			}
			else if(ch == '\n')
			{
				++gensel_linenum;
			}
		}
		else if(ch == '\n')
		{
			++gensel_linenum;
		}
	}
}

/*
 * Add a character to a reallocatable buffer.
 */
#define	ADD_CH(c)	\
		do { \
			if((buflen + 1) >= bufmax) \
			{ \
				buf = (char *)realloc(buf, bufmax + 64); \
				if(!buf) \
				{ \
					exit(1); \
				} \
				bufmax += 64; \
			} \
			buf[buflen++] = (char)c; \
			buf[buflen] = (char)'\0'; \
		} while (0)

/*
 * Read a literal code block from the input stream.
 */
static char *gensel_read_block(void)
{
	char *buf = 0;
	int buflen = 0;
	int bufmax = 0;
	int ch;
	int level = 1;
	ADD_CH('{');
	for(;;)
	{
		ch = input();
		if(ch == EOF)
		{
			fprintf(stderr, "Unexpected EOF in code block\n");
			exit(1);
		}
		ADD_CH(ch);
		if(ch == '{')
		{
			++level;
		}
		else if(ch == '\n')
		{
			++gensel_linenum;
		}
		else if(ch == '}')
		{
			--level;
			if(level == 0)
			{
				break;
			}
		}
	}
	return buf;
}

/*
 * Read a literal string from the input stream.
 */
static char *gensel_read_literal()
{
	char *buf = 0;
	int buflen = 0;
	int bufmax = 0;
	int escape = 0;
	int ch;
	for(;;)
	{
		ch = input();
		if(ch == EOF)
		{
			fprintf(stderr, "Unexpected EOF in string literal\n");
			exit(1);
		}
		if(ch == '\n')
		{
			fprintf(stderr, "Unexpected newline in string literal\n");
			exit(1);
		}
		if(escape)
		{
			escape = 0;
			if(ch == 'n')
			{
				ch = '\n';
			}
			else if(ch == 't')
			{
				ch = '\t';
			}
		}
		else
		{
			if(ch == '\\')
			{
				escape = 1;
				continue;
			}
			if(ch == '"')
			{
				break;
			}
		}
		ADD_CH(ch);
	}
	return buf;
}



( run in 0.559 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )