mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-14 08:16:17 -04:00
small changes in parser... I'll eventually get there
This commit is contained in:
parent
6dc8b0d29f
commit
edf3885e0b
@ -101,16 +101,38 @@ SP_TOKENS sp_tokenlist[] = {
|
|||||||
{ 0, 0, { NULL } }
|
{ 0, 0, { NULL } }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct tag_parsetree {
|
typedef struct tag_parsetree {
|
||||||
char *term;
|
char *term;
|
||||||
|
char *current;
|
||||||
int token;
|
int token;
|
||||||
int next_token;
|
int next_token;
|
||||||
} PARSESTRUCT, *PARSETREE;
|
} PARSESTRUCT, *PARSETREE;
|
||||||
|
|
||||||
#define SP_TOK_EOF 0
|
#define SP_TOK_BOF 0x0
|
||||||
|
#define SP_TOK_EOF 0x1
|
||||||
|
|
||||||
int sp_scan(PARSETREE tree) {
|
int sp_scan(PARSETREE tree) {
|
||||||
return SP_TOK_EOF;
|
char *tail;
|
||||||
|
int done=0;
|
||||||
|
|
||||||
|
tree->token=tree->next_token;
|
||||||
|
|
||||||
|
if(tree->token == SP_TOK_EOF)
|
||||||
|
return SP_TOK_EOF;
|
||||||
|
|
||||||
|
/* keep advancing until we have a token */
|
||||||
|
while(strchr(" \t\n\r",*current))
|
||||||
|
current++;
|
||||||
|
|
||||||
|
if(!current) {
|
||||||
|
tree->next_token = SP_TOK_EOF;
|
||||||
|
return tree->token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check singletons */
|
||||||
|
|
||||||
|
|
||||||
|
return tree->token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -139,11 +161,15 @@ PARSETREE sp_init(void) {
|
|||||||
*/
|
*/
|
||||||
int sp_parse(PARSETREE tree, char *term) {
|
int sp_parse(PARSETREE tree, char *term) {
|
||||||
tree->term = strdup(term); /* will be destroyed by parsing */
|
tree->term = strdup(term); /* will be destroyed by parsing */
|
||||||
|
tree->current=tree->term;
|
||||||
|
tree->token=SP_TOK_BOF;
|
||||||
|
tree->next_token=SP_TOK_BOF;
|
||||||
while(sp_scan(tree)) {
|
while(sp_scan(tree)) {
|
||||||
if(tree->token == SP_TOK_EOF)
|
if(tree->token == SP_TOK_EOF)
|
||||||
return 1; /* valid tree! */
|
return 1; /* valid tree! */
|
||||||
|
|
||||||
/* otherwise, keep scanning until done or error */
|
/* otherwise, keep scanning until done or error */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user