%{
#include <u.h>
#include <libc.h>
#include "common.h"
#include "debug.h"
#include "configyacclex.h"
yylex(void); /* matches lex output as of 2008-10-24 */
void yyerror(char *err);
int yywrap(void);
extern int yylineno;
#ifndef YYABORT
#define YYABORT return 1
#endif
#define DEBUG_YACC false
int outfd = 2;
/**
* @todo add ability to have comments
*/
%}
%token TOKEN_WORD TOKEN_SETTING TOKEN_PATH
%token TOKEN_AND TOKEN_OR
%token TOKEN_LPAREN TOKEN_RPAREN
%%
rules:
/* empty */
| rules rule
;
rule:
path
{
NOISE(DEBUG_YACC, "yyparse got path: %s", $1);
config_set_currentpath($1);
}
complexsetting
{
NOISE(DEBUG_YACC, "yyparse completes setting");
config_rule_end();
}
;
complexsetting:
simplesetting
|
complexsetting TOKEN_OR simplesetting
{
NOISE(DEBUG_YACC, "yyparse got || setting");
config_or_setting();
}
simplesetting:
setting
|
simplesetting TOKEN_AND setting
{
NOISE(DEBUG_YACC, "yyparse got && setting");
config_and_setting();
}
setting:
TOKEN_LPAREN complexsetting TOKEN_RPAREN
{
NOISE(DEBUG_YACC, "yyparse got parenthesized rule");
}
|
TOKEN_WORD TOKEN_SETTING
{
NOISE(DEBUG_YACC, "yyparse got rule: %s setting: %s", $1, $2);
config_push_setting($1, $2);
}
path:
TOKEN_WORD
|
TOKEN_PATH
;
%%
void yyerror(char *err)
{
ERROR(DEBUG_YACC, "yyparse %s on line %d", err, yylineno);
}
int yywrap(void)
{
return 1;
}
|