2003-12-04 18:20:51 -05:00
|
|
|
%{
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "playlist.h"
|
|
|
|
|
|
|
|
#define YYERROR_VERBOSE 1
|
|
|
|
|
|
|
|
/* Forwards */
|
|
|
|
|
2003-12-07 01:36:06 -05:00
|
|
|
extern PL_NODE *pl_newpredicate(int tag, int op, char *value, int type);
|
2003-12-04 18:20:51 -05:00
|
|
|
extern PL_NODE *pl_newexpr(PL_NODE *arg1, int op, PL_NODE *arg2);
|
|
|
|
extern int pl_addplaylist(char *name, PL_NODE *root);
|
|
|
|
|
2003-12-05 01:00:30 -05:00
|
|
|
/* Globals */
|
|
|
|
|
|
|
|
int pl_number=2;
|
|
|
|
|
2003-12-04 18:20:51 -05:00
|
|
|
%}
|
|
|
|
|
2003-12-05 01:00:30 -05:00
|
|
|
%left OR AND
|
2003-12-04 18:20:51 -05:00
|
|
|
|
|
|
|
%union {
|
|
|
|
unsigned int ival;
|
|
|
|
char *cval;
|
|
|
|
PL_NODE *plval;
|
|
|
|
}
|
|
|
|
|
2003-12-05 01:00:30 -05:00
|
|
|
%token <ival> ARTIST
|
|
|
|
%token <ival> ALBUM
|
|
|
|
%token <ival> GENRE
|
2003-12-04 18:20:51 -05:00
|
|
|
|
2003-12-07 01:36:06 -05:00
|
|
|
%token <ival> EQUALS
|
|
|
|
%token <ival> LESS
|
|
|
|
%token <ival> LESSEQUAL
|
|
|
|
%token <ival> GREATER
|
|
|
|
%token <ival> GREATEREQUAL
|
2003-12-05 01:00:30 -05:00
|
|
|
%token <ival> IS
|
|
|
|
%token <ival> INCLUDES
|
2003-12-04 18:20:51 -05:00
|
|
|
|
2003-12-05 01:00:30 -05:00
|
|
|
%token <ival> OR
|
|
|
|
%token <ival> AND
|
|
|
|
%token <ival> NOT
|
2003-12-04 18:20:51 -05:00
|
|
|
|
2003-12-05 01:00:30 -05:00
|
|
|
%token <cval> ID
|
2003-12-07 01:36:06 -05:00
|
|
|
%token <ival> NUM
|
|
|
|
|
|
|
|
%token <ival> YEAR
|
2003-12-04 18:20:51 -05:00
|
|
|
|
|
|
|
%type <plval> expression
|
|
|
|
%type <plval> predicate
|
2003-12-07 01:36:06 -05:00
|
|
|
%type <ival> strtag
|
|
|
|
%type <ival> inttag
|
|
|
|
%type <ival> strbool
|
|
|
|
%type <ival> intbool
|
2003-12-04 18:20:51 -05:00
|
|
|
%type <ival> playlist
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2003-12-05 01:00:30 -05:00
|
|
|
playlistlist: playlist {}
|
|
|
|
| playlistlist playlist {}
|
2003-12-04 18:20:51 -05:00
|
|
|
;
|
|
|
|
|
2003-12-05 01:00:30 -05:00
|
|
|
playlist: ID '{' expression '}' { $$ = pl_addplaylist($1, $3); }
|
2003-12-04 18:20:51 -05:00
|
|
|
;
|
|
|
|
|
2003-12-05 01:00:30 -05:00
|
|
|
expression: expression AND expression { $$=pl_newexpr($1,$2,$3); }
|
|
|
|
| expression OR expression { $$=pl_newexpr($1,$2,$3); }
|
2003-12-04 18:20:51 -05:00
|
|
|
| '(' expression ')' { $$=$2; }
|
|
|
|
| predicate
|
|
|
|
;
|
|
|
|
|
2003-12-07 01:36:06 -05:00
|
|
|
predicate: strtag strbool ID { $$=pl_newpredicate($1, $2, $3, T_STR); }
|
|
|
|
| inttag intbool NUM { $$=pl_newpredicate($1, $2, $3, T_INT); }
|
|
|
|
;
|
2003-12-04 18:20:51 -05:00
|
|
|
|
2003-12-07 01:36:06 -05:00
|
|
|
inttag: YEAR
|
2003-12-04 18:20:51 -05:00
|
|
|
;
|
|
|
|
|
2003-12-07 01:36:06 -05:00
|
|
|
intbool: EQUALS { $$ = $1; }
|
|
|
|
| LESS { $$ = $1; }
|
|
|
|
| LESSEQUAL { $$ = $1; }
|
|
|
|
| GREATER { $$ = $1; }
|
|
|
|
| GREATEREQUAL { $$ = $1; }
|
|
|
|
| NOT intbool { $$ = $2 | 0x80000000; }
|
2003-12-04 18:20:51 -05:00
|
|
|
;
|
|
|
|
|
2003-12-07 01:36:06 -05:00
|
|
|
strtag: ARTIST
|
|
|
|
| ALBUM
|
|
|
|
| GENRE
|
2003-12-04 18:20:51 -05:00
|
|
|
;
|
|
|
|
|
2003-12-07 01:36:06 -05:00
|
|
|
strbool: IS { $$=$1; }
|
|
|
|
| INCLUDES { $$=$1; }
|
|
|
|
| NOT strbool { $$=$2 | 0x80000000; }
|
|
|
|
;
|
2003-12-04 18:20:51 -05:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
2003-12-07 01:36:06 -05:00
|
|
|
PL_NODE *pl_newpredicate(int tag, int op, char *value, int type) {
|
2003-12-04 18:20:51 -05:00
|
|
|
PL_NODE *pnew;
|
|
|
|
|
|
|
|
pnew=(PL_NODE*)malloc(sizeof(PL_NODE));
|
|
|
|
if(!pnew)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pnew->op=op;
|
2003-12-07 01:36:06 -05:00
|
|
|
pnew->type=type;
|
2003-12-04 18:20:51 -05:00
|
|
|
pnew->arg1.ival=tag;
|
|
|
|
pnew->arg2.cval=value;
|
|
|
|
return pnew;
|
|
|
|
}
|
|
|
|
|
|
|
|
PL_NODE *pl_newexpr(PL_NODE *arg1, int op, PL_NODE *arg2) {
|
|
|
|
PL_NODE *pnew;
|
|
|
|
|
|
|
|
pnew=(PL_NODE*)malloc(sizeof(PL_NODE));
|
|
|
|
if(!pnew)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pnew->op=op;
|
|
|
|
pnew->arg1.plval=arg1;
|
|
|
|
pnew->arg2.plval=arg2;
|
|
|
|
return pnew;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pl_addplaylist(char *name, PL_NODE *root) {
|
|
|
|
SMART_PLAYLIST *pnew;
|
|
|
|
|
|
|
|
pnew=(SMART_PLAYLIST *)malloc(sizeof(SMART_PLAYLIST));
|
|
|
|
if(!pnew)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
pnew->next=pl_smart.next;
|
|
|
|
pnew->name=name;
|
|
|
|
pnew->root=root;
|
2003-12-05 01:00:30 -05:00
|
|
|
pnew->id=pl_number++;
|
2003-12-04 18:20:51 -05:00
|
|
|
pl_smart.next=pnew;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|