/*
*
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
This file is part of CLIXON.
CLIXON is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
CLIXON is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CLIXON; see the file COPYING. If not, see
.
* XML parser
*/
%{
#include "clicon_config.h"
#include
#include
#include
#include "clicon_xml_parse.tab.h" /* generated file */
/* cligen */
#include
/* clicon */
#include "clicon_xml.h"
#include "clicon_xml_parse.h"
/* Redefine main lex function so that you can send arguments to it: _ya is added to arg list */
#define YY_DECL int clicon_xml_parselex(void *_ya)
/* Dont use input function (use user-buffer) */
#define YY_NO_INPUT
/* typecast macro */
#define _YA ((struct xml_parse_yacc_arg *)_ya)
#undef clicon_xml_parsewrap
int clicon_xml_parsewrap(void)
{
return 1;
}
%}
%x START
%s STATEA
%s CMNT
%s STR
%s TEXTDECL
%s STRDQ
%s STRSQ
%%
[0-9A-Za-z_\-]+ { clicon_xml_parselval.string = strdup(yytext);
return NAME; /* rather be catch-all */
}
[ \t]+ ;
\: return *clicon_xml_parsetext;
\n { _YA->ya_linenum++;}
""/>" { BEGIN(STATEA); return ESLASH; }
"" { BEGIN(START); return ECOMMENT; }
\n _YA->ya_linenum++;
.
encoding return ENC;
version return VER;
"=" return *clicon_xml_parsetext;
"?>" { BEGIN(START);return ETEXT;}
\" { BEGIN(STRDQ); return *clicon_xml_parsetext; }
\' { BEGIN(STRSQ); return *clicon_xml_parsetext; }
[^\"]+ { clicon_xml_parselval.string = strdup(yytext); return CHAR; }
\" { BEGIN(START); return *clicon_xml_parsetext; }
1\.[0-9]+ { clicon_xml_parselval.string = strdup(yytext); return CHAR; }
[^\"]+ { clicon_xml_parselval.string = strdup(yytext); return CHAR; }
\" { BEGIN(TEXTDECL); return *clicon_xml_parsetext; }
1\.[0-9]+ { clicon_xml_parselval.string = strdup(yytext); return CHAR; }
[^\']+ { clicon_xml_parselval.string = strdup(yytext); return CHAR; }
\' { BEGIN(TEXTDECL); return *clicon_xml_parsetext; }
%%
/*! Initialize XML scanner.
*/
int
clicon_xml_parsel_init(struct xml_parse_yacc_arg *ya)
{
BEGIN(START);
ya->ya_lexbuf = yy_scan_string (ya->ya_parse_string);
if (0)
yyunput(0, ""); /* XXX: just to use unput to avoid warning */
return 0;
}
/*! Exit xml scanner */
int
clicon_xml_parsel_exit(struct xml_parse_yacc_arg *ya)
{
yy_delete_buffer(ya->ya_lexbuf);
#if defined(YY_FLEX_SUBMINOR_VERSION) && YY_FLEX_SUBMINOR_VERSION >= 9
clicon_xml_parselex_destroy(); /* modern */
#else
yy_init = 1; /* This does not quite free all buffers */
#endif
return 0;
}