ckpt
This commit is contained in:
parent
c9deaa2d31
commit
c01f4c5a9b
@ -5,10 +5,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "searchdata.h"
|
#include "searchdata.h"
|
||||||
|
#include "wasaparse.h"
|
||||||
|
#include "wasaparse.tab.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int yylex(void);
|
int yylex(yy::parser::semantic_type *);
|
||||||
void yyerror(char const *);
|
void yyerror(char const *);
|
||||||
void logwhere(const char *);
|
void logwhere(const char *);
|
||||||
class Expression;
|
class Expression;
|
||||||
@ -16,8 +18,17 @@ static void qualify(Rcl::SearchDataClauseDist *, const string &);
|
|||||||
|
|
||||||
string stemlang("english");
|
string stemlang("english");
|
||||||
|
|
||||||
|
static void addSubQuery(Rcl::SearchData *sd, Rcl::SearchData *sq)
|
||||||
|
{
|
||||||
|
sd->addClause(new Rcl::SearchDataClauseSub(RefCntr<Rcl::SearchData>(sq)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static Rcl::SearchData *g_result;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
%skeleton "lalr1.cc"
|
||||||
|
%defines
|
||||||
|
|
||||||
%union {
|
%union {
|
||||||
string *str;
|
string *str;
|
||||||
Rcl::SearchDataClauseSimple *cl;
|
Rcl::SearchDataClauseSimple *cl;
|
||||||
@ -48,48 +59,53 @@ string stemlang("english");
|
|||||||
|
|
||||||
query: fieldexpr
|
query: fieldexpr
|
||||||
{
|
{
|
||||||
|
cerr << "q: fieldexpr" << endl;
|
||||||
Rcl::SearchData *sd = new Rcl::SearchData(Rcl::SCLT_AND, stemlang);
|
Rcl::SearchData *sd = new Rcl::SearchData(Rcl::SCLT_AND, stemlang);
|
||||||
sd->addClause($1);
|
sd->addClause($1);
|
||||||
$$ = sd;
|
$$ = sd;
|
||||||
cerr << "q: fieldexpr" << endl;
|
g_result = sd;
|
||||||
}
|
}
|
||||||
| query fieldexpr
|
| query fieldexpr
|
||||||
{
|
{
|
||||||
cerr << "q: query fieldexpr" << endl;
|
cerr << "q: query fieldexpr" << endl;
|
||||||
$1->addClause($2);
|
$1->addClause($2);
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
|
g_result = $$;
|
||||||
}
|
}
|
||||||
| query AND fieldexpr
|
| query AND fieldexpr
|
||||||
{
|
{
|
||||||
cerr << "q: query AND fieldexpr" << endl;
|
cerr << "q: query AND fieldexpr" << endl;
|
||||||
$1->addClause($3);
|
$1->addClause($3);
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
|
g_result = $$;
|
||||||
}
|
}
|
||||||
| query AND orchain
|
| query AND orchain
|
||||||
{
|
{
|
||||||
cerr << "q: query AND orchain";
|
cerr << "q: query AND orchain";
|
||||||
Rcl::SearchDataClauseSub *sub =
|
addSubQuery($1, $3);
|
||||||
new Rcl::SearchDataClauseSub(RefCntr<Rcl::SearchData>($1));
|
|
||||||
$1->addClause(sub);
|
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
|
g_result = $$;
|
||||||
}
|
}
|
||||||
| query orchain
|
| query orchain
|
||||||
{
|
{
|
||||||
cerr << "q: query orchain" << endl;
|
cerr << "q: query orchain" << endl;
|
||||||
Rcl::SearchDataClauseSub *sub =
|
addSubQuery($1, $2);
|
||||||
new Rcl::SearchDataClauseSub(RefCntr<Rcl::SearchData>($1));
|
|
||||||
$1->addClause(sub);
|
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
|
g_result = $$;
|
||||||
}
|
}
|
||||||
| orchain
|
| orchain
|
||||||
{
|
{
|
||||||
cerr << "q: orchain" << endl;
|
cerr << "q: orchain" << endl;
|
||||||
$$ = $1;
|
Rcl::SearchData *sd = new Rcl::SearchData(Rcl::SCLT_AND, stemlang);
|
||||||
|
addSubQuery(sd, $1);
|
||||||
|
$$ = sd;
|
||||||
|
g_result = $$;
|
||||||
}
|
}
|
||||||
| '(' query ')'
|
| '(' query ')'
|
||||||
{
|
{
|
||||||
cerr << "( query )" << endl;
|
cerr << "( query )" << endl;
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
|
g_result = $$;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -284,24 +300,24 @@ static void qualify(Rcl::SearchDataClauseDist *cl, const string& quals)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static stack<int> returns;
|
static stack<int> g_returns;
|
||||||
static string input;
|
static string g_input;
|
||||||
static unsigned int index;
|
static unsigned int g_index;
|
||||||
|
|
||||||
int GETCHAR()
|
int GETCHAR()
|
||||||
{
|
{
|
||||||
if (!returns.empty()) {
|
if (!g_returns.empty()) {
|
||||||
int c = returns.top();
|
int c = g_returns.top();
|
||||||
returns.pop();
|
g_returns.pop();
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
if (index < input.size())
|
if (g_index < g_input.size())
|
||||||
return input[index++];
|
return g_input[g_index++];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static void UNGETCHAR(int c)
|
static void UNGETCHAR(int c)
|
||||||
{
|
{
|
||||||
returns.push(c);
|
g_returns.push(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simpler to let the quoted string reader store qualifiers in there,
|
// Simpler to let the quoted string reader store qualifiers in there,
|
||||||
@ -318,7 +334,7 @@ static string specialinchars(":=<>()");
|
|||||||
static string whites(" \t\n\r");
|
static string whites(" \t\n\r");
|
||||||
|
|
||||||
// Called with the first dquote already read
|
// Called with the first dquote already read
|
||||||
static int parseString()
|
static int parseString(yy::parser::semantic_type *yylval)
|
||||||
{
|
{
|
||||||
string* value = new string();
|
string* value = new string();
|
||||||
qualifiers.clear();
|
qualifiers.clear();
|
||||||
@ -345,19 +361,19 @@ static int parseString()
|
|||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
//cerr << "GOT QUOTED ["<<value<<"] quals [" << qualifiers << "]" << endl;
|
//cerr << "GOT QUOTED ["<<value<<"] quals [" << qualifiers << "]" << endl;
|
||||||
yylval.str = value;
|
yylval->str = value;
|
||||||
return QUOTED;
|
return yy::parser::token::QUOTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int yylex(void)
|
int yylex(yy::parser::semantic_type *yylval)
|
||||||
{
|
{
|
||||||
// cerr << "yylex: input [" << input.substr(index) << "]" << endl;
|
//cerr << "yylex: input [" << g_input.substr(g_index) << "]" << endl;
|
||||||
|
|
||||||
if (!qualifiers.empty()) {
|
if (!qualifiers.empty()) {
|
||||||
yylval.str = new string();
|
yylval->str = new string();
|
||||||
yylval.str->swap(qualifiers);
|
yylval->str->swap(qualifiers);
|
||||||
return QUALIFIERS;
|
return yy::parser::token::QUALIFIERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
@ -376,24 +392,24 @@ int yylex(void)
|
|||||||
|
|
||||||
// field-term relations
|
// field-term relations
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '=': return EQUALS;
|
case '=': return yy::parser::token::EQUALS;
|
||||||
case ':': return CONTAINS;
|
case ':': return yy::parser::token::CONTAINS;
|
||||||
case '<': {
|
case '<': {
|
||||||
int c1 = GETCHAR();
|
int c1 = GETCHAR();
|
||||||
if (c1 == '=') {
|
if (c1 == '=') {
|
||||||
return SMALLEREQ;
|
return yy::parser::token::SMALLEREQ;
|
||||||
} else {
|
} else {
|
||||||
UNGETCHAR(c);
|
UNGETCHAR(c);
|
||||||
return SMALLER;
|
return yy::parser::token::SMALLER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case '>': {
|
case '>': {
|
||||||
int c1 = GETCHAR();
|
int c1 = GETCHAR();
|
||||||
if (c1 == '=') {
|
if (c1 == '=') {
|
||||||
return GREATEREQ;
|
return yy::parser::token::GREATEREQ;
|
||||||
} else {
|
} else {
|
||||||
UNGETCHAR(c);
|
UNGETCHAR(c);
|
||||||
return GREATER;
|
return yy::parser::token::GREATER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case '(': case ')':
|
case '(': case ')':
|
||||||
@ -401,7 +417,7 @@ int yylex(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (c == '"')
|
if (c == '"')
|
||||||
return parseString();
|
return parseString(yylval);
|
||||||
|
|
||||||
UNGETCHAR(c);
|
UNGETCHAR(c);
|
||||||
|
|
||||||
@ -425,29 +441,39 @@ int yylex(void)
|
|||||||
|
|
||||||
if (!word->compare("AND") || !word->compare("&&")) {
|
if (!word->compare("AND") || !word->compare("&&")) {
|
||||||
delete word;
|
delete word;
|
||||||
return AND;
|
return yy::parser::token::AND;
|
||||||
} else if (!word->compare("OR") || !word->compare("||")) {
|
} else if (!word->compare("OR") || !word->compare("||")) {
|
||||||
delete word;
|
delete word;
|
||||||
return OR;
|
return yy::parser::token::OR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cerr << "Got word [" << word << "]" << endl;
|
// cerr << "Got word [" << word << "]" << endl;
|
||||||
yylval.str = word;
|
yylval->str = word;
|
||||||
return WORD;
|
return yy::parser::token::WORD;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, const char *argv[])
|
void yy::parser::error(location_type const&, string const& m)
|
||||||
{
|
{
|
||||||
argc--;argv++;
|
cerr << m << endl;
|
||||||
if (argc == 0)
|
}
|
||||||
return 1;
|
|
||||||
while (argc--) {
|
Rcl::SearchData *wasaparse(const string& in)
|
||||||
input += *argv++;
|
{
|
||||||
input += " ";
|
cerr << "wasaparse(" << in << ")" << endl;
|
||||||
}
|
|
||||||
|
g_index = 0;
|
||||||
index = 0;
|
g_returns = stack<int>();
|
||||||
returns = stack<int>();
|
g_input = in;
|
||||||
|
delete g_result;
|
||||||
return yyparse();
|
g_result = 0;
|
||||||
|
|
||||||
|
yy::parser parser;
|
||||||
|
if (parser.parse() != 0) {
|
||||||
|
// Error
|
||||||
|
cerr << "Parse failed" << endl;
|
||||||
|
delete g_result;
|
||||||
|
g_result = 0;
|
||||||
|
}
|
||||||
|
cerr << "wasaparse: returning " << g_result << endl;
|
||||||
|
return g_result;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user