shithub: xml-9atom

ref: f1e559d47916b74f473153a0a04df6956ca4052b
dir: /libxpath/xmlpathl.l/

View raw version
%{
#include <xml.h>
#include <xpath.h>
#include "dat.h"
#include "y.tab.h"
#undef input
#undef unput
#define input() (xinput())
#define unput(c) (xunput(c))

char *inputpath;
char *currentchar;

void
setinputpath(char *s)
{
	currentchar = inputpath = s;
}

int
xinput(void)
{
	char c;
	c = *currentchar;
	currentchar++;
	return c;
}

int
xunput(int c)
{
	/* do I need to handle that? */
	if (currentchar <= inputpath)
		sysfatal("error");
	
	currentchar--;
	*currentchar = c;
	return c;
}
%}

A	[a-zA-Z_.]
AN	[a-zA-Z0-9_.]
D	[0-9]
LIT	[/@=*()'!<>]
Q	[^']

%s	SPEC
%s	QUOT

%%	
{D}+	{ yylval.n = atoi(yytext); return NUMBER; }
{AN}+	{ yylval.nm = addname(yytext); return NAME; }
'{Q}+'	{ yylval.nm = addname(yytext); return NAME; }

\[  	{ BEGIN SPEC; return '['; }
<SPEC>\]  	{ BEGIN 0; return ']'; }

\/\/	return DSLASH;
child::             	return CHILD;
ancestor::          	return ANCESTOR;
ancestor-or-self::  	return ANCESTOR_OR_SELF;
attribute::         	return ATTRIBUTE;
descendant::        	return DESCENDANT;
descendant-or-self::	return DESCENDANT_OR_SELF;
following::         	return FOLLOWING;
following-sibling:: 	return FOLLOWING_SIBLING;
namespace::         	return NAMESPACE;
parent::            	return PARENT;
preceding::         	return PRECEDING;
preceding-sibling:: 	return PRECEDING_SIBLING;
self::              	return SELF;

<SPEC>and	return AND;
<SPEC>or 	return OR;

!=	{ return NEQ; }
\<=	{ return LE; }
\<	{ return LT; }
\>=	{ return GE; }
\>	{ return GT; }
= 	{ return EQ; }

{LIT}	{ return *yytext; }