shithub: xml-9atom

ref: 47a288683dbdc55c5df9b9f65db9909de6021af0
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 ']'; }

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;

{LIT}	{ return *yytext; }