internal type/var/prefix name changes for yacc parsing

This commit is contained in:
Olof hagsand 2020-02-22 11:15:51 +01:00
parent e1bccfa2a7
commit 3b26b22391
20 changed files with 210 additions and 207 deletions

View file

@ -39,13 +39,14 @@
/* /*
* Types * Types
*/ */
struct clicon_api_path_yacc_arg{ struct clixon_api_path_yacc {
const char *ay_name; /* Name of syntax (for error string) */ const char *ay_name; /* Name of syntax (for error string) */
int ay_linenum; /* Number of \n in parsed buffer */ int ay_linenum; /* Number of \n in parsed buffer */
char *ay_parse_string; /* original (copy of) parse string */ char *ay_parse_string; /* original (copy of) parse string */
void *ay_lexbuf; /* internal parse buffer from lex */ void *ay_lexbuf; /* internal parse buffer from lex */
clixon_path *ay_top; clixon_path *ay_top;
}; };
typedef struct clixon_api_path_yacc clixon_api_path_yacc;
/* /*
* Variables * Variables
@ -55,11 +56,11 @@ extern char *clixon_api_path_parsetext;
/* /*
* Prototypes * Prototypes
*/ */
int api_path_scan_init(struct clicon_api_path_yacc_arg *); int api_path_scan_init(clixon_api_path_yacc *);
int api_path_scan_exit(struct clicon_api_path_yacc_arg *); int api_path_scan_exit(clixon_api_path_yacc *);
int api_path_parse_init(struct clicon_api_path_yacc_arg *); int api_path_parse_init(clixon_api_path_yacc *);
int api_path_parse_exit(struct clicon_api_path_yacc_arg *); int api_path_parse_exit(clixon_api_path_yacc *);
int clixon_api_path_parselex(void *); int clixon_api_path_parselex(void *);
int clixon_api_path_parseparse(void *); int clixon_api_path_parseparse(void *);

View file

@ -79,7 +79,7 @@
#define YY_NO_INPUT #define YY_NO_INPUT
/* typecast macro */ /* typecast macro */
#define _AY ((struct clicon_api_path_yacc_arg *)_ay) #define _AY ((clixon_api_path_yacc *)_ay)
#define MAXBUF 4*4*64*1024 #define MAXBUF 4*4*64*1024
@ -124,7 +124,7 @@ identifier {namestart}{namechar}*
/*! Initialize scanner. /*! Initialize scanner.
*/ */
int int
api_path_scan_init(struct clicon_api_path_yacc_arg *ay) api_path_scan_init(clixon_api_path_yacc *ay)
{ {
BEGIN(INIT); BEGIN(INIT);
ay->ay_lexbuf = yy_scan_string(ay->ay_parse_string); ay->ay_lexbuf = yy_scan_string(ay->ay_parse_string);
@ -141,7 +141,7 @@ api_path_scan_init(struct clicon_api_path_yacc_arg *ay)
* Even within Flex version 2.5 (this is assumed), freeing buffers is different. * Even within Flex version 2.5 (this is assumed), freeing buffers is different.
*/ */
int int
api_path_scan_exit(struct clicon_api_path_yacc_arg *ay) api_path_scan_exit(clixon_api_path_yacc *ay)
{ {
yy_delete_buffer(ay->ay_lexbuf); yy_delete_buffer(ay->ay_lexbuf);
clixon_api_path_parselex_destroy(); /* modern */ clixon_api_path_parselex_destroy(); /* modern */

View file

@ -80,7 +80,7 @@
/* Here starts user C-code */ /* Here starts user C-code */
/* typecast macro */ /* typecast macro */
#define _AY ((struct clicon_api_path_yacc_arg *)_ay) #define _AY ((clixon_api_path_yacc *)_ay)
#define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_api_path_parsetext, _AY->ay_linenum); YYERROR;} #define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_api_path_parsetext, _AY->ay_linenum); YYERROR;}
@ -130,13 +130,13 @@ clixon_api_path_parseerror(void *_ay,
} }
int int
api_path_parse_init(struct clicon_api_path_yacc_arg *ay) api_path_parse_init(clixon_api_path_yacc *ay)
{ {
return 0; return 0;
} }
int int
api_path_parse_exit(struct clicon_api_path_yacc_arg *ay) api_path_parse_exit(clixon_api_path_yacc *ay)
{ {
return 0; return 0;
} }

View file

@ -39,7 +39,7 @@
/* /*
* Types * Types
*/ */
struct clicon_instance_id_yacc_arg{ struct clixon_instance_id_yacc {
const char *iy_name; /* Name of syntax (for error string) */ const char *iy_name; /* Name of syntax (for error string) */
int iy_linenum; /* Number of \n in parsed buffer */ int iy_linenum; /* Number of \n in parsed buffer */
char *iy_parse_string; /* original (copy of) parse string */ char *iy_parse_string; /* original (copy of) parse string */
@ -47,6 +47,7 @@ struct clicon_instance_id_yacc_arg{
clixon_path *iy_top; clixon_path *iy_top;
int iy_lex_state; /* lex return state */ int iy_lex_state; /* lex return state */
}; };
typedef struct clixon_instance_id_yacc clixon_instance_id_yacc;
/* /*
* Variables * Variables
@ -56,11 +57,11 @@ extern char *clixon_instance_id_parsetext;
/* /*
* Prototypes * Prototypes
*/ */
int instance_id_scan_init(struct clicon_instance_id_yacc_arg *); int instance_id_scan_init(clixon_instance_id_yacc *);
int instance_id_scan_exit(struct clicon_instance_id_yacc_arg *); int instance_id_scan_exit(clixon_instance_id_yacc *);
int instance_id_parse_init(struct clicon_instance_id_yacc_arg *); int instance_id_parse_init(clixon_instance_id_yacc *);
int instance_id_parse_exit(struct clicon_instance_id_yacc_arg *); int instance_id_parse_exit(clixon_instance_id_yacc *);
int clixon_instance_id_parselex(void *); int clixon_instance_id_parselex(void *);
int clixon_instance_id_parseparse(void *); int clixon_instance_id_parseparse(void *);

View file

@ -76,7 +76,7 @@
#define YY_NO_INPUT #define YY_NO_INPUT
/* typecast macro */ /* typecast macro */
#define _IY ((struct clicon_instance_id_yacc_arg *)_iy) #define _IY ((clixon_instance_id_yacc *)_iy)
#define MAXBUF 4*4*64*1024 #define MAXBUF 4*4*64*1024
@ -131,7 +131,7 @@ uint [1-9][0-9]*
/*! Initialize scanner. /*! Initialize scanner.
*/ */
int int
instance_id_scan_init(struct clicon_instance_id_yacc_arg *iy) instance_id_scan_init(clixon_instance_id_yacc *iy)
{ {
BEGIN(INIT); BEGIN(INIT);
iy->iy_lexbuf = yy_scan_string(iy->iy_parse_string); iy->iy_lexbuf = yy_scan_string(iy->iy_parse_string);
@ -148,7 +148,7 @@ instance_id_scan_init(struct clicon_instance_id_yacc_arg *iy)
* Even within Flex version 2.5 (this is assumed), freeing buffers is different. * Even within Flex version 2.5 (this is assumed), freeing buffers is different.
*/ */
int int
instance_id_scan_exit(struct clicon_instance_id_yacc_arg *iy) instance_id_scan_exit(clixon_instance_id_yacc *iy)
{ {
yy_delete_buffer(iy->iy_lexbuf); yy_delete_buffer(iy->iy_lexbuf);
clixon_instance_id_parselex_destroy(); /* modern */ clixon_instance_id_parselex_destroy(); /* modern */

View file

@ -88,7 +88,7 @@
/* Here starts user C-code */ /* Here starts user C-code */
/* typecast macro */ /* typecast macro */
#define _IY ((struct clicon_instance_id_yacc_arg *)_iy) #define _IY ((clixon_instance_id_yacc *)_iy)
#define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_instance_id_parsetext, _IY->iy_linenum); YYERROR;} #define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_instance_id_parsetext, _IY->iy_linenum); YYERROR;}
@ -138,13 +138,13 @@ clixon_instance_id_parseerror(void *_iy,
} }
int int
instance_id_parse_init(struct clicon_instance_id_yacc_arg *iy) instance_id_parse_init(clixon_instance_id_yacc *iy)
{ {
return 0; return 0;
} }
int int
instance_id_parse_exit(struct clicon_instance_id_yacc_arg *iy) instance_id_parse_exit(clixon_instance_id_yacc *iy)
{ {
return 0; return 0;
} }

View file

@ -40,7 +40,7 @@
* Types * Types
*/ */
struct clixon_json_yacc_arg{ /* XXX: mostly unrelevant */ struct clixon_json_yacc {
int jy_linenum; /* Number of \n in parsed buffer */ int jy_linenum; /* Number of \n in parsed buffer */
char *jy_parse_string; /* original (copy of) parse string */ char *jy_parse_string; /* original (copy of) parse string */
void *jy_lexbuf; /* internal parse buffer from lex */ void *jy_lexbuf; /* internal parse buffer from lex */
@ -49,7 +49,7 @@ struct clixon_json_yacc_arg{ /* XXX: mostly unrelevant */
cxobj **jy_xvec; /* Vector of created top-level nodes (to know which are created) */ cxobj **jy_xvec; /* Vector of created top-level nodes (to know which are created) */
size_t jy_xlen; /* Length of jy_xvec */ size_t jy_xlen; /* Length of jy_xvec */
}; };
typedef struct clixon_json_yacc_arg clixon_json_yacc; typedef struct clixon_json_yacc clixon_json_yacc;
/* /*
* Variables * Variables

View file

@ -119,8 +119,8 @@ static int
api_path_parse(char *api_path, api_path_parse(char *api_path,
clixon_path **cplist) clixon_path **cplist)
{ {
int retval = -1; int retval = -1;
struct clicon_api_path_yacc_arg ay = {0,}; clixon_api_path_yacc ay = {0,};
clicon_debug(1, "%s api_path:%s", __FUNCTION__, api_path); clicon_debug(1, "%s api_path:%s", __FUNCTION__, api_path);
ay.ay_parse_string = api_path; ay.ay_parse_string = api_path;
@ -164,8 +164,8 @@ static int
instance_id_parse(char *path, instance_id_parse(char *path,
clixon_path **cplist) clixon_path **cplist)
{ {
int retval = -1; int retval = -1;
struct clicon_instance_id_yacc_arg iy = {0,}; clixon_instance_id_yacc iy = {0,};
clicon_debug(1, "%s path:%s", __FUNCTION__, path); clicon_debug(1, "%s path:%s", __FUNCTION__, path);
iy.iy_parse_string = path; iy.iy_parse_string = path;

View file

@ -2033,7 +2033,7 @@ _xml_parse(const char *str,
cxobj **xerr) cxobj **xerr)
{ {
int retval = -1; int retval = -1;
clixon_xml_yacc ya = {0,}; clixon_xml_yacc xy = {0,};
cxobj *x; cxobj *x;
int ret; int ret;
int failed = 0; /* yang assignment */ int failed = 0; /* yang assignment */
@ -2046,24 +2046,24 @@ _xml_parse(const char *str,
clicon_err(OE_XML, errno, "Unexpected NULL XML"); clicon_err(OE_XML, errno, "Unexpected NULL XML");
return -1; return -1;
} }
if ((ya.ya_parse_string = strdup(str)) == NULL){ if ((xy.xy_parse_string = strdup(str)) == NULL){
clicon_err(OE_XML, errno, "strdup"); clicon_err(OE_XML, errno, "strdup");
return -1; return -1;
} }
ya.ya_xtop = xt; xy.xy_xtop = xt;
ya.ya_xparent = xt; xy.xy_xparent = xt;
ya.ya_yspec = yspec; xy.xy_yspec = yspec;
if (clixon_xml_parsel_init(&ya) < 0) if (clixon_xml_parsel_init(&xy) < 0)
goto done; goto done;
if (clixon_xml_parseparse(&ya) != 0) /* yacc returns 1 on error */ if (clixon_xml_parseparse(&xy) != 0) /* yacc returns 1 on error */
goto done; goto done;
/* Purge all top-level body objects */ /* Purge all top-level body objects */
x = NULL; x = NULL;
while ((x = xml_find_type(xt, NULL, "body", CX_BODY)) != NULL) while ((x = xml_find_type(xt, NULL, "body", CX_BODY)) != NULL)
xml_purge(x); xml_purge(x);
/* Traverse new objects */ /* Traverse new objects */
for (i = 0; i < ya.ya_xlen; i++) { for (i = 0; i < xy.xy_xlen; i++) {
x = ya.ya_xvec[i]; x = xy.xy_xvec[i];
/* Verify namespaces after parsing */ /* Verify namespaces after parsing */
if (xml_apply0(x, CX_ELMNT, xml_localname_check, NULL) < 0) if (xml_apply0(x, CX_ELMNT, xml_localname_check, NULL) < 0)
goto done; goto done;
@ -2108,11 +2108,11 @@ _xml_parse(const char *str,
goto done; goto done;
retval = (failed==0) ? 1 : 0; retval = (failed==0) ? 1 : 0;
done: done:
clixon_xml_parsel_exit(&ya); clixon_xml_parsel_exit(&xy);
if (ya.ya_parse_string != NULL) if (xy.xy_parse_string != NULL)
free(ya.ya_parse_string); free(xy.xy_parse_string);
if (ya.ya_xvec) if (xy.xy_xvec)
free(ya.ya_xvec); free(xy.xy_xvec);
return retval; return retval;
} }

View file

@ -44,19 +44,19 @@
* Types * Types
*/ */
/*! XML parser yacc handler struct */ /*! XML parser yacc handler struct */
struct xml_parse_yacc_arg{ struct clixon_xml_parse_yacc {
char *ya_parse_string; /* original (copy of) parse string */ char *xy_parse_string; /* original (copy of) parse string */
int ya_linenum; /* Number of \n in parsed buffer */ int xy_linenum; /* Number of \n in parsed buffer */
void *ya_lexbuf; /* internal parse buffer from lex */ void *xy_lexbuf; /* internal parse buffer from lex */
cxobj *ya_xtop; /* cxobj top element (fixed) */ cxobj *xy_xtop; /* cxobj top element (fixed) */
cxobj *ya_xelement; /* cxobj active element (changes with parse context) */ cxobj *xy_xelement; /* cxobj active element (changes with parse context) */
cxobj *ya_xparent; /* cxobj parent element (changes with parse context) */ cxobj *xy_xparent; /* cxobj parent element (changes with parse context) */
yang_stmt *ya_yspec; /* If set, top-level yang-spec */ yang_stmt *xy_yspec; /* If set, top-level yang-spec */
int ya_lex_state; /* lex return state */ int xy_lex_state; /* lex return state */
cxobj **ya_xvec; /* Vector of created top-level nodes (to know which are created) */ cxobj **xy_xvec; /* Vector of created top-level nodes (to know which are created) */
size_t ya_xlen; /* Length of ya_xvec */ size_t xy_xlen; /* Length of xy_xvec */
}; };
typedef struct xml_parse_yacc_arg clixon_xml_yacc; typedef struct clixon_xml_parse_yacc clixon_xml_yacc;
extern char *clixon_xml_parsetext; extern char *clixon_xml_parsetext;

View file

@ -61,14 +61,14 @@
#include "clixon_xml.h" #include "clixon_xml.h"
#include "clixon_xml_parse.h" #include "clixon_xml_parse.h"
/* Redefine main lex function so that you can send arguments to it: _ya is added to arg list */ /* Redefine main lex function so that you can send arguments to it: _xy is added to arg list */
#define YY_DECL int clixon_xml_parselex(void *_ya) #define YY_DECL int clixon_xml_parselex(void *_xy)
/* Dont use input function (use user-buffer) */ /* Dont use input function (use user-buffer) */
#define YY_NO_INPUT #define YY_NO_INPUT
/* typecast macro */ /* typecast macro */
#define _YA ((clixon_xml_yacc *)_ya) #define _XY ((clixon_xml_yacc *)_xy)
#undef clixon_xml_parsewrap #undef clixon_xml_parsewrap
int clixon_xml_parsewrap(void) int clixon_xml_parsewrap(void)
@ -107,7 +107,7 @@ ncname {namestart}{namechar}*
%% %%
<START,TEXTDECL>[ \t] ; <START,TEXTDECL>[ \t] ;
<START,CMNT,TEXTDECL>\n { _YA->ya_linenum++; } <START,CMNT,TEXTDECL>\n { _XY->xy_linenum++; }
<START,CMNT,TEXTDECL>\r <START,CMNT,TEXTDECL>\r
<START>{ncname} { clixon_xml_parselval.string = strdup(yytext); <START>{ncname} { clixon_xml_parselval.string = strdup(yytext);
@ -123,32 +123,32 @@ ncname {namestart}{namechar}*
<START>[/=] return *clixon_xml_parsetext; <START>[/=] return *clixon_xml_parsetext;
<START>\< return *clixon_xml_parsetext; <START>\< return *clixon_xml_parsetext;
<START>\> { BEGIN(STATEA); return *clixon_xml_parsetext; } <START>\> { BEGIN(STATEA); return *clixon_xml_parsetext; }
<START>\" { _YA->ya_lex_state=START;BEGIN(STRDQ); return *clixon_xml_parsetext; } <START>\" { _XY->xy_lex_state=START;BEGIN(STRDQ); return *clixon_xml_parsetext; }
<START>\' { _YA->ya_lex_state=START;BEGIN(STRSQ); return *clixon_xml_parsetext; } <START>\' { _XY->xy_lex_state=START;BEGIN(STRSQ); return *clixon_xml_parsetext; }
<START>. { clixon_xml_parselval.string = yytext; return CHARDATA; /* optimize? */} <START>. { clixon_xml_parselval.string = yytext; return CHARDATA; /* optimize? */}
<STATEA>"</" { BEGIN(START); return BSLASH; } <STATEA>"</" { BEGIN(START); return BSLASH; }
<STATEA><<EOF>> { return MY_EOF; } <STATEA><<EOF>> { return MY_EOF; }
<STATEA>"<!--" { BEGIN(CMNT); return BCOMMENT; } <STATEA>"<!--" { BEGIN(CMNT); return BCOMMENT; }
<STATEA>"<![CDATA[" { BEGIN(CDATA); _YA->ya_lex_state = STATEA; clixon_xml_parselval.string = yytext; return CHARDATA;} <STATEA>"<![CDATA[" { BEGIN(CDATA); _XY->xy_lex_state = STATEA; clixon_xml_parselval.string = yytext; return CHARDATA;}
<STATEA>"<?" { BEGIN(PIDECL); return BQMARK; } <STATEA>"<?" { BEGIN(PIDECL); return BQMARK; }
<STATEA>\< { BEGIN(START); return *clixon_xml_parsetext; } <STATEA>\< { BEGIN(START); return *clixon_xml_parsetext; }
<STATEA>& { _YA->ya_lex_state =STATEA;BEGIN(AMPERSAND);} <STATEA>& { _XY->xy_lex_state =STATEA;BEGIN(AMPERSAND);}
<STATEA>[ \t]+ { clixon_xml_parselval.string = yytext;return WHITESPACE; } <STATEA>[ \t]+ { clixon_xml_parselval.string = yytext;return WHITESPACE; }
<STATEA>\r\n { clixon_xml_parselval.string = "\n"; _YA->ya_linenum++; return WHITESPACE; } <STATEA>\r\n { clixon_xml_parselval.string = "\n"; _XY->xy_linenum++; return WHITESPACE; }
<STATEA>\r { clixon_xml_parselval.string = "\n";return WHITESPACE; } <STATEA>\r { clixon_xml_parselval.string = "\n";return WHITESPACE; }
<STATEA>\n { clixon_xml_parselval.string = "\n"; _YA->ya_linenum++;return WHITESPACE; } <STATEA>\n { clixon_xml_parselval.string = "\n"; _XY->xy_linenum++;return WHITESPACE; }
<STATEA>. { clixon_xml_parselval.string = yytext; return CHARDATA; } <STATEA>. { clixon_xml_parselval.string = yytext; return CHARDATA; }
/* @see xml_chardata_encode */ /* @see xml_chardata_encode */
<AMPERSAND>"amp;" { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = "&"; return CHARDATA;} <AMPERSAND>"amp;" { BEGIN(_XY->xy_lex_state); clixon_xml_parselval.string = "&"; return CHARDATA;}
<AMPERSAND>"lt;" { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = "<"; return CHARDATA;} <AMPERSAND>"lt;" { BEGIN(_XY->xy_lex_state); clixon_xml_parselval.string = "<"; return CHARDATA;}
<AMPERSAND>"gt;" { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = ">"; return CHARDATA;} <AMPERSAND>"gt;" { BEGIN(_XY->xy_lex_state); clixon_xml_parselval.string = ">"; return CHARDATA;}
<AMPERSAND>"apos;" { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = "'"; return CHARDATA;} <AMPERSAND>"apos;" { BEGIN(_XY->xy_lex_state); clixon_xml_parselval.string = "'"; return CHARDATA;}
<AMPERSAND>"quot;" { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = "\""; return CHARDATA;} <AMPERSAND>"quot;" { BEGIN(_XY->xy_lex_state); clixon_xml_parselval.string = "\""; return CHARDATA;}
<CDATA>\n { clixon_xml_parselval.string = yytext;_YA->ya_linenum++; return (CHARDATA);} <CDATA>\n { clixon_xml_parselval.string = yytext;_XY->xy_linenum++; return (CHARDATA);}
<CDATA>"]]>" { BEGIN(_YA->ya_lex_state); clixon_xml_parselval.string = yytext; return CHARDATA;} <CDATA>"]]>" { BEGIN(_XY->xy_lex_state); clixon_xml_parselval.string = yytext; return CHARDATA;}
<CDATA>\] { clixon_xml_parselval.string = yytext; return CHARDATA;} <CDATA>\] { clixon_xml_parselval.string = yytext; return CHARDATA;}
<CDATA>[^]\n]+ { clixon_xml_parselval.string = yytext; return CHARDATA;} <CDATA>[^]\n]+ { clixon_xml_parselval.string = yytext; return CHARDATA;}
@ -159,8 +159,8 @@ ncname {namestart}{namechar}*
<TEXTDECL>standalone return SD; <TEXTDECL>standalone return SD;
<TEXTDECL>"=" { return *clixon_xml_parsetext; } <TEXTDECL>"=" { return *clixon_xml_parsetext; }
<TEXTDECL>"?>" { BEGIN(START);return EQMARK;} <TEXTDECL>"?>" { BEGIN(START);return EQMARK;}
<TEXTDECL>\" { _YA->ya_lex_state =TEXTDECL;BEGIN(STRDQ); return *clixon_xml_parsetext; } <TEXTDECL>\" { _XY->xy_lex_state =TEXTDECL;BEGIN(STRDQ); return *clixon_xml_parsetext; }
<TEXTDECL>\' { _YA->ya_lex_state =TEXTDECL;BEGIN(STRSQ); return *clixon_xml_parsetext; } <TEXTDECL>\' { _XY->xy_lex_state =TEXTDECL;BEGIN(STRSQ); return *clixon_xml_parsetext; }
<TEXTDECL>. { clixon_xml_parselval.string = yytext; return CHARDATA; /* optimize? */} <TEXTDECL>. { clixon_xml_parselval.string = yytext; return CHARDATA; /* optimize? */}
<PIDECL>{ncname} { clixon_xml_parselval.string = strdup(yytext); <PIDECL>{ncname} { clixon_xml_parselval.string = strdup(yytext);
@ -173,21 +173,21 @@ ncname {namestart}{namechar}*
<STRDQ>1\.[0-9]+ { clixon_xml_parselval.string = strdup(yytext); return STRING; } <STRDQ>1\.[0-9]+ { clixon_xml_parselval.string = strdup(yytext); return STRING; }
<STRDQ>[^\"]+ { clixon_xml_parselval.string = strdup(yytext); return STRING; } <STRDQ>[^\"]+ { clixon_xml_parselval.string = strdup(yytext); return STRING; }
<STRDQ>\" { BEGIN(_YA->ya_lex_state); return *clixon_xml_parsetext; } <STRDQ>\" { BEGIN(_XY->xy_lex_state); return *clixon_xml_parsetext; }
<STRSQ>1\.[0-9]+ { clixon_xml_parselval.string = strdup(yytext); return STRING; } <STRSQ>1\.[0-9]+ { clixon_xml_parselval.string = strdup(yytext); return STRING; }
<STRSQ>[^\']+ { clixon_xml_parselval.string = strdup(yytext); return STRING; } <STRSQ>[^\']+ { clixon_xml_parselval.string = strdup(yytext); return STRING; }
<STRSQ>\' { BEGIN(_YA->ya_lex_state); return *clixon_xml_parsetext; } <STRSQ>\' { BEGIN(_XY->xy_lex_state); return *clixon_xml_parsetext; }
%% %%
/*! Initialize XML scanner. /*! Initialize XML scanner.
*/ */
int int
clixon_xml_parsel_init(clixon_xml_yacc *ya) clixon_xml_parsel_init(clixon_xml_yacc *xy)
{ {
BEGIN(START); BEGIN(START);
ya->ya_lexbuf = yy_scan_string (ya->ya_parse_string); xy->xy_lexbuf = yy_scan_string (xy->xy_parse_string);
if (0) if (0)
yyunput(0, ""); /* XXX: just to use unput to avoid warning */ yyunput(0, ""); /* XXX: just to use unput to avoid warning */
return 0; return 0;
@ -195,9 +195,9 @@ clixon_xml_parsel_init(clixon_xml_yacc *ya)
/*! Exit xml scanner */ /*! Exit xml scanner */
int int
clixon_xml_parsel_exit(clixon_xml_yacc *ya) clixon_xml_parsel_exit(clixon_xml_yacc *xy)
{ {
yy_delete_buffer(ya->ya_lexbuf); yy_delete_buffer(xy->xy_lexbuf);
clixon_xml_parselex_destroy(); /* modern */ clixon_xml_parselex_destroy(); /* modern */
return 0; return 0;

View file

@ -54,13 +54,13 @@
%type <string> attvalue %type <string> attvalue
%lex-param {void *_ya} /* Add this argument to parse() and lex() function */ %lex-param {void *_xy} /* Add this argument to parse() and lex() function */
%parse-param {void *_ya} %parse-param {void *_xy}
%{ %{
/* typecast macro */ /* typecast macro */
#define _YA ((clixon_xml_yacc *)_ya) #define _XY ((clixon_xml_yacc *)_xy)
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
@ -84,11 +84,11 @@
#include "clixon_xml_parse.h" #include "clixon_xml_parse.h"
void void
clixon_xml_parseerror(void *_ya, clixon_xml_parseerror(void *_xy,
char *s) char *s)
{ {
clicon_err(OE_XML, XMLPARSE_ERRNO, "xml_parse: line %d: %s: at or before: %s", clicon_err(OE_XML, XMLPARSE_ERRNO, "xml_parse: line %d: %s: at or before: %s",
_YA->ya_linenum, _XY->xy_linenum,
s, s,
clixon_xml_parsetext); clixon_xml_parsetext);
return; return;
@ -99,14 +99,14 @@ clixon_xml_parseerror(void *_ya,
* there may also be some leakage here on NULL return * there may also be some leakage here on NULL return
*/ */
static int static int
xml_parse_content(clixon_xml_yacc *ya, xml_parse_content(clixon_xml_yacc *xy,
char *str) char *str)
{ {
cxobj *xn = ya->ya_xelement; cxobj *xn = xy->xy_xelement;
cxobj *xp = ya->ya_xparent; cxobj *xp = xy->xy_xparent;
int retval = -1; int retval = -1;
ya->ya_xelement = NULL; /* init */ xy->xy_xelement = NULL; /* init */
if (xn == NULL){ if (xn == NULL){
if ((xn = xml_new("body", xp, NULL)) == NULL) if ((xn = xml_new("body", xp, NULL)) == NULL)
goto done; goto done;
@ -114,7 +114,7 @@ xml_parse_content(clixon_xml_yacc *ya,
} }
if (xml_value_append(xn, str) < 0) if (xml_value_append(xn, str) < 0)
goto done; goto done;
ya->ya_xelement = xn; xy->xy_xelement = xn;
retval = 0; retval = 0;
done: done:
return retval; return retval;
@ -125,15 +125,15 @@ xml_parse_content(clixon_xml_yacc *ya,
* But if there is an element, then skip all whitespace. * But if there is an element, then skip all whitespace.
*/ */
static int static int
xml_parse_whitespace(clixon_xml_yacc *ya, xml_parse_whitespace(clixon_xml_yacc *xy,
char *str) char *str)
{ {
cxobj *xn = ya->ya_xelement; cxobj *xn = xy->xy_xelement;
cxobj *xp = ya->ya_xparent; cxobj *xp = xy->xy_xparent;
int retval = -1; int retval = -1;
int i; int i;
ya->ya_xelement = NULL; /* init */ xy->xy_xelement = NULL; /* init */
/* If there is an element already, only add one whitespace child /* If there is an element already, only add one whitespace child
* otherwise, keep all whitespace. See code in xml_parse_bslash * otherwise, keep all whitespace. See code in xml_parse_bslash
*/ */
@ -148,7 +148,7 @@ xml_parse_whitespace(clixon_xml_yacc *ya,
} }
if (xml_value_append(xn, str) < 0) if (xml_value_append(xn, str) < 0)
goto done; goto done;
ya->ya_xelement = xn; xy->xy_xelement = xn;
ok: ok:
retval = 0; retval = 0;
done: done:
@ -156,8 +156,8 @@ xml_parse_whitespace(clixon_xml_yacc *ya,
} }
static int static int
xml_parse_version(clixon_xml_yacc *ya, xml_parse_version(clixon_xml_yacc *xy,
char *ver) char *ver)
{ {
if(strcmp(ver, "1.0")){ if(strcmp(ver, "1.0")){
clicon_err(OE_XML, XMLPARSE_ERRNO, "Wrong XML version %s expected 1.0", ver); clicon_err(OE_XML, XMLPARSE_ERRNO, "Wrong XML version %s expected 1.0", ver);
@ -172,12 +172,12 @@ xml_parse_version(clixon_xml_yacc *ya,
/*! Parse Qualified name -> (Un)PrefixedName /*! Parse Qualified name -> (Un)PrefixedName
* *
* This is where all (parsed) xml elements are created * This is where all (parsed) xml elements are created
* @param[in] ya XML parser yacc handler struct * @param[in] xy XML parser yacc handler struct
* @param[in] prefix Prefix, namespace, or NULL * @param[in] prefix Prefix, namespace, or NULL
* @param[in] localpart Name * @param[in] localpart Name
*/ */
static int static int
xml_parse_prefixed_name(clixon_xml_yacc *ya, xml_parse_prefixed_name(clixon_xml_yacc *xy,
char *prefix, char *prefix,
char *name) char *name)
{ {
@ -185,16 +185,16 @@ xml_parse_prefixed_name(clixon_xml_yacc *ya,
cxobj *x; cxobj *x;
cxobj *xp; /* xml parent */ cxobj *xp; /* xml parent */
xp = ya->ya_xparent; xp = xy->xy_xparent;
if ((x = xml_new(name, xp, NULL)) == NULL) if ((x = xml_new(name, xp, NULL)) == NULL)
goto done; goto done;
xml_type_set(x, CX_ELMNT); xml_type_set(x, CX_ELMNT);
if (prefix && xml_prefix_set(x, prefix) < 0) if (prefix && xml_prefix_set(x, prefix) < 0)
goto done; goto done;
ya->ya_xelement = x; xy->xy_xelement = x;
/* If topmost, add to top-list created list */ /* If topmost, add to top-list created list */
if (xp == ya->ya_xtop){ if (xp == xy->xy_xtop){
if (cxvec_append(x, &ya->ya_xvec, &ya->ya_xlen) < 0) if (cxvec_append(x, &xy->xy_xvec, &xy->xy_xlen) < 0)
goto done; goto done;
} }
retval = 0; retval = 0;
@ -207,28 +207,28 @@ xml_parse_prefixed_name(clixon_xml_yacc *ya,
} }
static int static int
xml_parse_endslash_pre(clixon_xml_yacc *ya) xml_parse_endslash_pre(clixon_xml_yacc *xy)
{ {
ya->ya_xparent = ya->ya_xelement; xy->xy_xparent = xy->xy_xelement;
ya->ya_xelement = NULL; xy->xy_xelement = NULL;
return 0; return 0;
} }
static int static int
xml_parse_endslash_mid(clixon_xml_yacc *ya) xml_parse_endslash_mid(clixon_xml_yacc *xy)
{ {
if (ya->ya_xelement != NULL) if (xy->xy_xelement != NULL)
ya->ya_xelement = xml_parent(ya->ya_xelement); xy->xy_xelement = xml_parent(xy->xy_xelement);
else else
ya->ya_xelement = ya->ya_xparent; xy->xy_xelement = xy->xy_xparent;
ya->ya_xparent = xml_parent(ya->ya_xelement); xy->xy_xparent = xml_parent(xy->xy_xelement);
return 0; return 0;
} }
static int static int
xml_parse_endslash_post(clixon_xml_yacc *ya) xml_parse_endslash_post(clixon_xml_yacc *xy)
{ {
ya->ya_xelement = NULL; xy->xy_xelement = NULL;
return 0; return 0;
} }
@ -237,17 +237,17 @@ xml_parse_endslash_post(clixon_xml_yacc *ya)
* Any whitespace between the subelements to a non-leaf is * Any whitespace between the subelements to a non-leaf is
* insignificant, i.e., an implementation MAY insert whitespace * insignificant, i.e., an implementation MAY insert whitespace
* characters between subelements and are therefore stripped, but see comment in code below. * characters between subelements and are therefore stripped, but see comment in code below.
* @param[in] ya XML parser yacc handler struct * @param[in] xy XML parser yacc handler struct
* @param[in] prefix * @param[in] prefix
* @param[in] name * @param[in] name
*/ */
static int static int
xml_parse_bslash(clixon_xml_yacc *ya, xml_parse_bslash(clixon_xml_yacc *xy,
char *prefix, char *prefix,
char *name) char *name)
{ {
int retval = -1; int retval = -1;
cxobj *x = ya->ya_xelement; cxobj *x = xy->xy_xelement;
cxobj *xc; cxobj *xc;
char *prefix0; char *prefix0;
char *name0; char *name0;
@ -293,16 +293,16 @@ xml_parse_bslash(clixon_xml_yacc *ya,
* - PrefixedAttName: xmlns:NAME * - PrefixedAttName: xmlns:NAME
*/ */
static int static int
xml_parse_attr(clixon_xml_yacc *ya, xml_parse_attr(clixon_xml_yacc *xy,
char *prefix, char *prefix,
char *name, char *name,
char *attval) char *attval)
{ {
int retval = -1; int retval = -1;
cxobj *xa = NULL; cxobj *xa = NULL;
if ((xa = xml_find_type(ya->ya_xelement, prefix, name, CX_ATTR)) == NULL){ if ((xa = xml_find_type(xy->xy_xelement, prefix, name, CX_ATTR)) == NULL){
if ((xa = xml_new(name, ya->ya_xelement, NULL)) == NULL) if ((xa = xml_new(name, xy->xy_xelement, NULL)) == NULL)
goto done; goto done;
xml_type_set(xa, CX_ATTR); xml_type_set(xa, CX_ATTR);
if (prefix && xml_prefix_set(xa, prefix) < 0) if (prefix && xml_prefix_set(xa, prefix) < 0)
@ -352,10 +352,10 @@ xmldcl : BXMLDCL verinfo encodingdecl sddecl EQMARK
; ;
verinfo : VER '=' '\"' STRING '\"' verinfo : VER '=' '\"' STRING '\"'
{ if (xml_parse_version(_YA, $4) <0) YYABORT; { if (xml_parse_version(_XY, $4) <0) YYABORT;
clicon_debug(2, "verinfo->version=\"STRING\"");} clicon_debug(2, "verinfo->version=\"STRING\"");}
| VER '=' '\'' STRING '\'' | VER '=' '\'' STRING '\''
{ if (xml_parse_version(_YA, $4) <0) YYABORT; { if (xml_parse_version(_XY, $4) <0) YYABORT;
clicon_debug(2, "verinfo->version='STRING'");} clicon_debug(2, "verinfo->version='STRING'");}
; ;
@ -373,26 +373,26 @@ element : '<' qname attrs element1
{ clicon_debug(2, "element -> < qname attrs element1"); } { clicon_debug(2, "element -> < qname attrs element1"); }
; ;
qname : NAME { if (xml_parse_prefixed_name(_YA, NULL, $1) < 0) YYABORT; qname : NAME { if (xml_parse_prefixed_name(_XY, NULL, $1) < 0) YYABORT;
clicon_debug(2, "qname -> NAME %s", $1);} clicon_debug(2, "qname -> NAME %s", $1);}
| NAME ':' NAME { if (xml_parse_prefixed_name(_YA, $1, $3) < 0) YYABORT; | NAME ':' NAME { if (xml_parse_prefixed_name(_XY, $1, $3) < 0) YYABORT;
clicon_debug(2, "qname -> NAME : NAME");} clicon_debug(2, "qname -> NAME : NAME");}
; ;
element1 : ESLASH {_YA->ya_xelement = NULL; element1 : ESLASH {_XY->xy_xelement = NULL;
clicon_debug(2, "element1 -> />");} clicon_debug(2, "element1 -> />");}
| '>' { xml_parse_endslash_pre(_YA); } | '>' { xml_parse_endslash_pre(_XY); }
elist { xml_parse_endslash_mid(_YA); } elist { xml_parse_endslash_mid(_XY); }
endtag { xml_parse_endslash_post(_YA); endtag { xml_parse_endslash_post(_XY);
clicon_debug(2, "element1 -> > elist endtag");} clicon_debug(2, "element1 -> > elist endtag");}
; ;
endtag : BSLASH NAME '>' endtag : BSLASH NAME '>'
{ clicon_debug(2, "endtag -> < </ NAME>"); { clicon_debug(2, "endtag -> < </ NAME>");
if (xml_parse_bslash(_YA, NULL, $2) < 0) YYABORT; } if (xml_parse_bslash(_XY, NULL, $2) < 0) YYABORT; }
| BSLASH NAME ':' NAME '>' | BSLASH NAME ':' NAME '>'
{ if (xml_parse_bslash(_YA, $2, $4) < 0) YYABORT; { if (xml_parse_bslash(_XY, $2, $4) < 0) YYABORT;
clicon_debug(2, "endtag -> < </ NAME:NAME >"); } clicon_debug(2, "endtag -> < </ NAME:NAME >"); }
; ;
@ -404,9 +404,9 @@ elist : elist content { clicon_debug(2, "elist -> elist content"); }
content : element { clicon_debug(2, "content -> element"); } content : element { clicon_debug(2, "content -> element"); }
| comment { clicon_debug(2, "content -> comment"); } | comment { clicon_debug(2, "content -> comment"); }
| pi { clicon_debug(2, "content -> pi"); } | pi { clicon_debug(2, "content -> pi"); }
| CHARDATA { if (xml_parse_content(_YA, $1) < 0) YYABORT; | CHARDATA { if (xml_parse_content(_XY, $1) < 0) YYABORT;
clicon_debug(2, "content -> CHARDATA %s", $1); } clicon_debug(2, "content -> CHARDATA %s", $1); }
| WHITESPACE { if (xml_parse_whitespace(_YA, $1) < 0) YYABORT; | WHITESPACE { if (xml_parse_whitespace(_XY, $1) < 0) YYABORT;
clicon_debug(2, "content -> WHITESPACE %s", $1); } clicon_debug(2, "content -> WHITESPACE %s", $1); }
| { clicon_debug(2, "content -> "); } | { clicon_debug(2, "content -> "); }
; ;
@ -424,8 +424,8 @@ attrs : attrs attr
| |
; ;
attr : NAME '=' attvalue { if (xml_parse_attr(_YA, NULL, $1, $3) < 0) YYABORT; } attr : NAME '=' attvalue { if (xml_parse_attr(_XY, NULL, $1, $3) < 0) YYABORT; }
| NAME ':' NAME '=' attvalue { if (xml_parse_attr(_YA, $1, $3, $5) < 0) YYABORT; } | NAME ':' NAME '=' attvalue { if (xml_parse_attr(_XY, $1, $3, $5) < 0) YYABORT; }
; ;
attvalue : '\"' STRING '\"' { $$=$2; /* $2 must be consumed */} attvalue : '\"' STRING '\"' { $$=$2; /* $2 must be consumed */}

View file

@ -486,20 +486,20 @@ int
xpath_parse(char *xpath, xpath_parse(char *xpath,
xpath_tree **xptree) xpath_tree **xptree)
{ {
int retval = -1; int retval = -1;
struct clicon_xpath_yacc_arg xy = {0,}; clixon_xpath_yacc xpy = {0,};
cbuf *cb = NULL; cbuf *cb = NULL;
xy.xy_parse_string = xpath; xpy.xpy_parse_string = xpath;
xy.xy_name = "xpath parser"; xpy.xpy_name = "xpath parser";
xy.xy_linenum = 1; xpy.xpy_linenum = 1;
if (xpath_scan_init(&xy) < 0) if (xpath_scan_init(&xpy) < 0)
goto done; goto done;
if (xpath_parse_init(&xy) < 0) if (xpath_parse_init(&xpy) < 0)
goto done; goto done;
clicon_debug(2,"%s",__FUNCTION__); clicon_debug(2,"%s",__FUNCTION__);
if (clixon_xpath_parseparse(&xy) != 0) { /* yacc returns 1 on error */ if (clixon_xpath_parseparse(&xpy) != 0) { /* yacc returns 1 on error */
clicon_log(LOG_NOTICE, "XPATH error: on line %d", xy.xy_linenum); clicon_log(LOG_NOTICE, "XPATH error: on line %d", xpy.xpy_linenum);
if (clicon_errno == 0) if (clicon_errno == 0)
clicon_err(OE_XML, 0, "XPATH parser error with no error code (should not happen)"); clicon_err(OE_XML, 0, "XPATH parser error with no error code (should not happen)");
goto done; goto done;
@ -509,12 +509,12 @@ xpath_parse(char *xpath,
clicon_err(OE_XML, errno, "cbuf_new"); clicon_err(OE_XML, errno, "cbuf_new");
goto done; goto done;
} }
xpath_tree_print_cb(cb, xy.xy_top); xpath_tree_print_cb(cb, xpy.xpy_top);
clicon_debug(2, "xpath parse tree:\n%s", cbuf_get(cb)); clicon_debug(2, "xpath parse tree:\n%s", cbuf_get(cb));
} }
xpath_parse_exit(&xy); xpath_parse_exit(&xpy);
xpath_scan_exit(&xy); xpath_scan_exit(&xpy);
*xptree = xy.xy_top; *xptree = xpy.xpy_top;
retval = 0; retval = 0;
done: done:
if (cb) if (cb)

View file

@ -39,13 +39,14 @@
/* /*
* Types * Types
*/ */
struct clicon_xpath_yacc_arg{ struct clixon_xpath_yacc{
const char *xy_name; /* Name of syntax (for error string) */ const char *xpy_name; /* Name of syntax (for error string) */
int xy_linenum; /* Number of \n in parsed buffer */ int xpy_linenum; /* Number of \n in parsed buffer */
char *xy_parse_string; /* original (copy of) parse string */ char *xpy_parse_string; /* original (copy of) parse string */
void *xy_lexbuf; /* internal parse buffer from lex */ void *xpy_lexbuf; /* internal parse buffer from lex */
xpath_tree *xy_top; xpath_tree *xpy_top;
}; };
typedef struct clixon_xpath_yacc clixon_xpath_yacc;
/* /*
* Variables * Variables
@ -55,11 +56,11 @@ extern char *clixon_xpath_parsetext;
/* /*
* Prototypes * Prototypes
*/ */
int xpath_scan_init(struct clicon_xpath_yacc_arg *xy); int xpath_scan_init(clixon_xpath_yacc *xy);
int xpath_scan_exit(struct clicon_xpath_yacc_arg *xy); int xpath_scan_exit(clixon_xpath_yacc *xy);
int xpath_parse_init(struct clicon_xpath_yacc_arg *xy); int xpath_parse_init(clixon_xpath_yacc *xy);
int xpath_parse_exit(struct clicon_xpath_yacc_arg *xy); int xpath_parse_exit(clixon_xpath_yacc *xy);
int clixon_xpath_parselex(void *); int clixon_xpath_parselex(void *);
int clixon_xpath_parseparse(void *); int clixon_xpath_parseparse(void *);

View file

@ -66,7 +66,7 @@
#define YY_NO_INPUT #define YY_NO_INPUT
/* typecast macro */ /* typecast macro */
#define _XY ((struct clicon_xpath_yacc_arg *)_yy) #define _XPY ((clixon_xpath_yacc *)_yy)
#define MAXBUF 4*4*64*1024 #define MAXBUF 4*4*64*1024
@ -93,7 +93,7 @@ ncname {namestart}{namechar}*
%% %%
<TOKEN>[ \t] <TOKEN>[ \t]
<TOKEN>\n { _XY->xy_linenum++; } <TOKEN>\n { _XPY->xpy_linenum++; }
<TOKEN>\r { } <TOKEN>\r { }
<TOKEN><<EOF>> { return X_EOF; } <TOKEN><<EOF>> { return X_EOF; }
<TOKEN>".." { return DOUBLEDOT; } <TOKEN>".." { return DOUBLEDOT; }
@ -161,10 +161,10 @@ ncname {namestart}{namechar}*
/*! Initialize scanner. /*! Initialize scanner.
*/ */
int int
xpath_scan_init(struct clicon_xpath_yacc_arg *xy) xpath_scan_init(clixon_xpath_yacc *xpy)
{ {
BEGIN(TOKEN); BEGIN(TOKEN);
xy->xy_lexbuf = yy_scan_string (xy->xy_parse_string); xpy->xpy_lexbuf = yy_scan_string (xpy->xpy_parse_string);
#if 1 /* XXX: just to use unput to avoid warning */ #if 1 /* XXX: just to use unput to avoid warning */
if (0) if (0)
yyunput(0, ""); yyunput(0, "");
@ -178,9 +178,9 @@ xpath_scan_init(struct clicon_xpath_yacc_arg *xy)
* Even within Flex version 2.5 (this is assumed), freeing buffers is different. * Even within Flex version 2.5 (this is assumed), freeing buffers is different.
*/ */
int int
xpath_scan_exit(struct clicon_xpath_yacc_arg *xy) xpath_scan_exit(clixon_xpath_yacc *xpy)
{ {
yy_delete_buffer(xy->xy_lexbuf); yy_delete_buffer(xpy->xpy_lexbuf);
clixon_xpath_parselex_destroy(); /* modern */ clixon_xpath_parselex_destroy(); /* modern */
return 0; return 0;
} }

View file

@ -82,16 +82,16 @@
%type <stack> predicates %type <stack> predicates
%type <stack> primaryexpr %type <stack> primaryexpr
%lex-param {void *_xy} /* Add this argument to parse() and lex() function */ %lex-param {void *_xpy} /* Add this argument to parse() and lex() function */
%parse-param {void *_xy} %parse-param {void *_xpy}
%{ %{
/* Here starts user C-code */ /* Here starts user C-code */
/* typecast macro */ /* typecast macro */
#define _XY ((struct clicon_xpath_yacc_arg *)_xy) #define _XPY ((clixon_xpath_yacc *)_xpy)
#define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_xpath_parsetext, _XY->xy_linenum); YYERROR;} #define _YYERROR(msg) {clicon_err(OE_XML, 0, "YYERROR %s '%s' %d", (msg), clixon_xpath_parsetext, _XPY->xpy_linenum); YYERROR;}
/* add _yy to error parameters */ /* add _yy to error parameters */
#define YY_(msgid) msgid #define YY_(msgid) msgid
@ -131,26 +131,26 @@ extern int clixon_xpath_parseget_lineno (void); /*XXX obsolete ? */
*/ */
void void
clixon_xpath_parseerror(void *_xy, clixon_xpath_parseerror(void *_xpy,
char *s) char *s)
{ {
clicon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'", clicon_err(OE_XML, 0, "%s on line %d: %s at or before: '%s'",
_XY->xy_name, _XPY->xpy_name,
_XY->xy_linenum , _XPY->xpy_linenum ,
s, s,
clixon_xpath_parsetext); clixon_xpath_parsetext);
return; return;
} }
int int
xpath_parse_init(struct clicon_xpath_yacc_arg *xy) xpath_parse_init(clixon_xpath_yacc *xpy)
{ {
// clicon_debug_init(2, NULL); // clicon_debug_init(2, NULL);
return 0; return 0;
} }
int int
xpath_parse_exit(struct clicon_xpath_yacc_arg *xy) xpath_parse_exit(clixon_xpath_yacc *xpy)
{ {
return 0; return 0;
} }
@ -197,8 +197,8 @@ xp_new(enum xp_type type,
/* /*
*/ */
start : expr X_EOF { _XY->xy_top=$1;clicon_debug(2,"start->expr"); YYACCEPT; } start : expr X_EOF { _XPY->xpy_top=$1;clicon_debug(2,"start->expr"); YYACCEPT; }
| locationpath X_EOF { _XY->xy_top=$1;clicon_debug(2,"start->locationpath"); YYACCEPT; } | locationpath X_EOF { _XPY->xpy_top=$1;clicon_debug(2,"start->locationpath"); YYACCEPT; }
; ;
expr : expr LOGOP andexpr { $$=xp_new(XP_EXP,$2,NULL,NULL,NULL,$1, $3);clicon_debug(2,"expr->expr or andexpr"); } expr : expr LOGOP andexpr { $$=xp_new(XP_EXP,$2,NULL,NULL,NULL,$1, $3);clicon_debug(2,"expr->expr or andexpr"); }

View file

@ -50,7 +50,7 @@ struct ys_stack{
yang_stmt *ys_node; yang_stmt *ys_node;
}; };
struct clicon_yang_yacc_arg{ /* XXX: mostly unrelevant */ struct clixon_yang_yacc {
char *yy_name; /* Name of syntax, typically filename char *yy_name; /* Name of syntax, typically filename
(for error string) */ (for error string) */
int yy_linenum; /* Number of \n in parsed buffer */ int yy_linenum; /* Number of \n in parsed buffer */
@ -59,9 +59,9 @@ struct clicon_yang_yacc_arg{ /* XXX: mostly unrelevant */
struct ys_stack *yy_stack; /* Stack of levels: push/pop on () and [] */ struct ys_stack *yy_stack; /* Stack of levels: push/pop on () and [] */
int yy_lex_state; /* lex start condition (ESCAPE/COMMENT) */ int yy_lex_state; /* lex start condition (ESCAPE/COMMENT) */
int yy_lex_string_state; /* lex start condition (STRING) */ int yy_lex_string_state; /* lex start condition (STRING) */
yang_stmt *yy_module; /* top-level (sub)module - return value of yang_stmt *yy_module; /* top-level (sub)module - return value of parser */
parser */
}; };
typedef struct clixon_yang_yacc clixon_yang_yacc;
/* This is a malloced piece of code we attach to cligen objects used as db-specs. /* This is a malloced piece of code we attach to cligen objects used as db-specs.
* So if(when) we translate cg_obj to yang_obj (or something). These are the fields * So if(when) we translate cg_obj to yang_obj (or something). These are the fields
@ -86,17 +86,17 @@ extern char *clixon_yang_parsetext;
/* /*
* Prototypes * Prototypes
*/ */
int yang_scan_init(struct clicon_yang_yacc_arg *ya); int yang_scan_init(clixon_yang_yacc *ya);
int yang_scan_exit(struct clicon_yang_yacc_arg *ya); int yang_scan_exit(clixon_yang_yacc *ya);
int yang_parse_init(struct clicon_yang_yacc_arg *ya); int yang_parse_init(clixon_yang_yacc *ya);
int yang_parse_exit(struct clicon_yang_yacc_arg *ya); int yang_parse_exit(clixon_yang_yacc *ya);
int clixon_yang_parselex(void *_ya); int clixon_yang_parselex(void *_ya);
int clixon_yang_parseparse(void *); int clixon_yang_parseparse(void *);
void clixon_yang_parseerror(void *_ya, char*); void clixon_yang_parseerror(void *_ya, char*);
int ystack_pop(struct clicon_yang_yacc_arg *ya); int ystack_pop(clixon_yang_yacc *ya);
struct ys_stack *ystack_push(struct clicon_yang_yacc_arg *ya, yang_stmt *yn); struct ys_stack *ystack_push(clixon_yang_yacc *ya, yang_stmt *yn);
#endif /* _CLIXON_YANG_PARSE_H_ */ #endif /* _CLIXON_YANG_PARSE_H_ */

View file

@ -64,7 +64,7 @@
#define YY_NO_INPUT #define YY_NO_INPUT
/* typecast macro */ /* typecast macro */
#define _YY ((struct clicon_yang_yacc_arg *)_yy) #define _YY ((clixon_yang_yacc *)_yy)
#define MAXBUF 4*4*64*1024 #define MAXBUF 4*4*64*1024
@ -271,7 +271,7 @@ identifier [A-Za-z_][A-Za-z0-9_\-\.]*
* Initialize scanner. * Initialize scanner.
*/ */
int int
yang_scan_init(struct clicon_yang_yacc_arg *yy) yang_scan_init(clixon_yang_yacc *yy)
{ {
BEGIN(KEYWORD); BEGIN(KEYWORD);
yy->yy_lexbuf = yy_scan_string (yy->yy_parse_string); yy->yy_lexbuf = yy_scan_string (yy->yy_parse_string);
@ -289,7 +289,7 @@ yang_scan_init(struct clicon_yang_yacc_arg *yy)
* Even within Flex version 2.5 (this is assumed), freeing buffers is different. * Even within Flex version 2.5 (this is assumed), freeing buffers is different.
*/ */
int int
yang_scan_exit(struct clicon_yang_yacc_arg *yy) yang_scan_exit(clixon_yang_yacc *yy)
{ {
yy_delete_buffer(yy->yy_lexbuf); yy_delete_buffer(yy->yy_lexbuf);
clixon_yang_parselex_destroy(); /* modern */ clixon_yang_parselex_destroy(); /* modern */

View file

@ -161,7 +161,7 @@
/* Here starts user C-code */ /* Here starts user C-code */
/* typecast macro */ /* typecast macro */
#define _YY ((struct clicon_yang_yacc_arg *)_yy) #define _YY ((clixon_yang_yacc *)_yy)
#define _YYERROR(msg) {clicon_debug(2, "YYERROR %s '%s' %d", (msg), clixon_yang_parsetext, _YY->yy_linenum); YYERROR;} #define _YYERROR(msg) {clicon_debug(2, "YYERROR %s '%s' %d", (msg), clixon_yang_parsetext, _YY->yy_linenum); YYERROR;}
@ -218,14 +218,14 @@ clixon_yang_parseerror(void *_yy,
} }
int int
yang_parse_init(struct clicon_yang_yacc_arg *yy) yang_parse_init(clixon_yang_yacc *yy)
{ {
return 0; return 0;
} }
int int
yang_parse_exit(struct clicon_yang_yacc_arg *yy) yang_parse_exit(clixon_yang_yacc *yy)
{ {
return 0; return 0;
} }
@ -234,7 +234,7 @@ yang_parse_exit(struct clicon_yang_yacc_arg *yy)
* @param[in] yy Yang yacc argument * @param[in] yy Yang yacc argument
*/ */
int int
ystack_pop(struct clicon_yang_yacc_arg *yy) ystack_pop(clixon_yang_yacc *yy)
{ {
struct ys_stack *ystack; struct ys_stack *ystack;
@ -252,8 +252,8 @@ ystack_pop(struct clicon_yang_yacc_arg *yy)
* @param[in] yn Yang node to push * @param[in] yn Yang node to push
*/ */
struct ys_stack * struct ys_stack *
ystack_push(struct clicon_yang_yacc_arg *yy, ystack_push(clixon_yang_yacc *yy,
yang_stmt *yn) yang_stmt *yn)
{ {
struct ys_stack *ystack; struct ys_stack *ystack;
@ -278,10 +278,10 @@ ystack_push(struct clicon_yang_yacc_arg *yy,
* @note consumes 'argument' and 'extra' which assumes it is malloced and not freed by caller * @note consumes 'argument' and 'extra' which assumes it is malloced and not freed by caller
*/ */
static yang_stmt * static yang_stmt *
ysp_add(struct clicon_yang_yacc_arg *yy, ysp_add(clixon_yang_yacc *yy,
enum rfc_6020 keyword, enum rfc_6020 keyword,
char *argument, char *argument,
char *extra) char *extra)
{ {
struct ys_stack *ystack = yy->yy_stack; struct ys_stack *ystack = yy->yy_stack;
yang_stmt *ys = NULL; yang_stmt *ys = NULL;
@ -321,10 +321,10 @@ ysp_add(struct clicon_yang_yacc_arg *yy,
* @param[in] extra Yang extra for cornercases (unknown/extension) * @param[in] extra Yang extra for cornercases (unknown/extension)
*/ */
static yang_stmt * static yang_stmt *
ysp_add_push(struct clicon_yang_yacc_arg *yy, ysp_add_push(clixon_yang_yacc *yy,
enum rfc_6020 keyword, enum rfc_6020 keyword,
char *argument, char *argument,
char *extra) char *extra)
{ {
yang_stmt *ys; yang_stmt *ys;

View file

@ -450,8 +450,8 @@ yang_parse_str(char *str,
const char *name, /* just for errs */ const char *name, /* just for errs */
yang_stmt *yspec) yang_stmt *yspec)
{ {
struct clicon_yang_yacc_arg yy = {0,}; clixon_yang_yacc yy = {0,};
yang_stmt *ymod = NULL; yang_stmt *ymod = NULL;
if (yspec == NULL){ if (yspec == NULL){
clicon_err(OE_YANG, 0, "Yang parse need top level yang spec"); clicon_err(OE_YANG, 0, "Yang parse need top level yang spec");