55 m_CurrentLexem.m_Token = eTokenILLEGAL;
56 m_CurrentLexem.m_Position =
SLocation(0, 1, 1);
57 m_CurrentLexem.m_Data.Init();
311 case '1':
case '2':
case '3':
312 case '4':
case '5':
case '6':
313 case '7':
case '8':
case '9':
325 double fl_num = (double)num;
328 fl_num += (
m_StrMacro[pos] -
'0')*pow(10.0, index);
451 if (bSingleMacroMode) {
465 string msg =
"[Parsing error] ";
508 msg +=
"Keyword 'MACRO' expected instead of '";
516 msg +=
"Macro name expected";
557 msg +=
"Identifier name expected";
567 msg +=
"' is already defined";
574 msg +=
"Assignment expected";
641 msg +=
"Definition of '" + var_name +
"' variable is incomplete";
653 msg +=
"Symbol '{' expected instead of '";
682 msg +=
"Comma or '}' expected instead of '";
707 msg +=
"Variable definition expected";
721 msg +=
"Keyword 'FOR EACH' expected instead of '";
729 msg +=
"ASN.1 selector expected instead of '";
753 msg +=
"Named annotation expected instead of '";
776 msg +=
"Keyword 'RANGE' expected instead of '";
789 msg +=
"Sequence range expected instead of '";
796 msg +=
"Symbol '[' expected instead of '";
801 Int8 start = 0, stop = 0;
802 bool found_start =
false, found_stop =
false, found_comma =
false;
815 if (!found_start && !found_comma) {
819 else if (found_comma && !found_stop) {
832 msg +=
"Positive integer number expected instead of '";
841 msg +=
"Comma expected to separate two positive integers instead of '";
850 msg +=
"Symbol ']' expected instead of '";
864 string msg =
"Range was not specified as expected: '[start, stop]'";
868 if (start < 0 || stop < 0) {
869 string msg =
"Start and Stop positions are expected to be positive integers";
874 string msg =
"Start position should be less than or equal to the Stop position";
884 int len =
static_cast<int>(iend - istart);
899 switch (node->GetType()){
904 const string& name = (*iter)->GetValue().GetOrig();
915 const string& name = (*iter)->GetValue().GetOrig();
931 return s_NodeCost(*item1) < s_NodeCost(*item2);
938 switch (node->GetType()) {
942 vector<CQueryParseTree::TNode*> nodes;
947 nodes.push_back(ptr);
951 sort(nodes.begin(), nodes.end(), sorter);
952 ITERATE(vector<CQueryParseTree::TNode*>, iter, nodes) {
970 ap_qparse_tree->Parse(
str.c_str(),
984 ap_qparse_tree.reset(
NULL);
1000 msg +=
"Keyword 'WHERE' expected instead of '";
1006 if (find(end_tokens.begin(), end_tokens.end(),
m_Scanner.
GetToken()) != end_tokens.end()) {
1008 msg +=
"'WHERE' clause expected instead of '";
1018 while (find(end_tokens.begin(), end_tokens.end(),
m_Scanner.
GetToken()) == end_tokens.end()) {
1033 msg +=
"Invalid 'WHERE' clause";
1038 msg +=
"Invalid 'WHERE' clause: ";
1046 string where_clause;
1059 string where_clause;
1076 msg +=
"Keyword 'DO' or keyword 'DO_P' expected instead of '";
1096 msg +=
"Function or object name is expected instead of '";
1108 msg +=
"Assignment to non-modifiable variable '";
1109 msg += ident +
"' in this context";
1124 msg +=
"Unknown function name: '" + ident +
"'";
1128 msg +=
"Assignment operator expected instead of '";
1152 msg +=
"Function name or 'DONE' expected instead of '";
1164 msg +=
"Keyword 'DO_P' expected instead of '";
1172 msg +=
"Symbol '(' expected instead of '";
1183 bool set_automatically =
false;
1204 msg +=
"Positive integer number expected instead of '";
1213 msg +=
"Symbol ')' expected instead of '";
1222 set_automatically =
true;
1234 msg +=
"Symbol ')' expected instead of '";
1239 if (threads <= 0 && !set_automatically) {
1240 string msg =
"Number of threads is expected to be a positive, non-zero integer";
1243 if (set_automatically) {
1254 [&name](
const string& func) { return NStr::EqualNocase(func, name); } );
1262 msg +=
"Function name expected instead of '";
1270 msg +=
"Unknown function name: '" + fname +
"'";
1279 msg +=
"Symbol '(' expected instead of '";
1297 msg +=
"Undefined variable: '" + ident +
"'";
1330 msg +=
"Symbol '\"' expected around the argument of '" + fname +
"'";
1334 msg +=
"Symbol ')' expected instead of '";
1342 msg +=
"Symbol ';' expected";
1356 msg +=
"Keyword 'WHERE' or semicolon expected instead of '";
1380 msg +=
"Variable definition expected";
1396 string msg =
"COMMENT token expected";
1400 const char kKeywords[] =
"#Keywords:";
1403 size_t pos = comment.find(kKeywords);
1404 if (pos == string::npos)
1407 string keywords = comment.substr(pos +
sizeof(kKeywords) - 1);
1412 size_t pos2 = keywords.find(
',', pos);
1413 size_t len = (pos2 == string::npos) ? pos2 : pos2 - pos;
1423 if (pos2 == string::npos)
Class for parsed macro representation.
Query execution environment holds the function registry and the execution context.
Query tree and associated utility methods.
Class for lexical tokens extraction from macro string.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
definition of a Culling tree
iterator_bool insert(const value_type &val)
const_iterator find(const key_type &key) const
const_iterator end() const
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
void x_ParseNumericVarValue(const string &var_name, int sign)
Entry point to parse numeric var value.
void x_ParseFunctionCall(CQueryParseTree::TNode *assignmentNode)
Entry point to parse function call.
static const char * sm_Automatic
void SetName(const string &name)
Set the name of the macro.
const SLexem & GetLexemInfo() const
static const int MAX_STRING_LEXEM_LENGTH
Max buffer size for lexem string info.
bool Parse(bool bSingleMacroMode=true, CQueryExec *exec=NULL)
Parse the macro and build its representation Function throws CMacroException if parsing is unsuccessf...
void x_ParseNumericChoiceValue(int sign)
Parses numeric value of a choice variable.
string x_GetErrorLocation() const
void x_InitForNextLexem()
void SetForEachItem(const string &name)
Set "for each" asn selector.
SLocation GetErrorLocation() const
void x_ParseDo()
Entry point to parse DO-DONE section.
CMacroRep * m_MacroRep
binary representation of macro while parsing
void x_ParseRange()
Entry point to parse range.
void x_UpdateErrorLocation()
void SetVarChoiceString(const string &value)
void SetNamedAnnot(const string &name)
Set named annotation.
bool x_IsFunction(const string &name) const
Checks whether its parameter is a name of the registered functions.
void x_ParseChoice()
Entry point to parse choice section.
void SetAssignmentWhereClause(const string &where_str, CQueryParseTree *where_tree, const CQueryParseNode::SSrcLoc &pos)
Set the function Where clause as a part of an assignment operator.
TFunctionNamesList m_DoFunctionsList
list of functions available for Do clause
void SetFunctionParameterAsIdent(const string &name, const CQueryParseNode::SSrcLoc &pos)
Set the function parameters.
void SetFunctionParameterAsBool(bool value, const CQueryParseNode::SSrcLoc &pos)
void SetVarFloat(const string &name, double value)
void SetVarString(const string &name, const string &value)
CScanner::EToken GetToken()
void x_ParseVariables()
Entry point to parse vars section.
void x_ParseThreadCount()
Entry point to parse number of threads to be used.
void SetFunctionParameterAsString(const string &value, const CQueryParseNode::SSrcLoc &pos)
CQueryParseTree::TFunctionNames TFunctionNamesList
Type for the list of functions in Where/Do clauses.
void x_ParseFunctionWhere()
Entry point to parse where clause in function call.
void SetFunctionNames(const TFunctionNamesList &wh_funcs, const TFunctionNamesList &do_funcs)
initializes lists of known functions that should be recognized by the parser when going through WHERE...
void SetFunctionParameterAsFloat(double value, const CQueryParseNode::SSrcLoc &pos)
void SetVarChoiceBool(bool value)
CScanner::SLocation m_ErrorLocation
error location
string GetStringRepr() const
void SetNewVarBlock()
Set the new variable block.
set< string > m_RTVars
list of run-time variables met in the left side of assignment in DO clause
void x_ParseScript()
Entry point to parse whole script.
bool FindVar(const string &name) const
Look up the variable among the stored ones.
void SetFunction(const string &name, const CQueryParseNode::SSrcLoc &pos, CQueryParseTree::TNode *parentNode=0)
Set function name.
void x_InitParser()
Resets parser to initial state.
void AddMetaKeywords(const string &keyWords)
void SetVarChoiceName(const string &name)
void SetTitle(const string &title)
Set the title of the macro.
CScanner m_Scanner
scanner for extracting tokens and meta info
void SetVarInt(const string &name, Int8 value)
void SetVarChoiceInt(Int8 value)
EParsingErrReportType m_ErrorReportType
Specifies the type of error reporting.
void SetSeqRange(const TSeqRange &range)
Set the sequence range.
void x_GetWhereClause(Int4 istart, Int4 iend, string &result) const
Extracts where clause as a string.
int Next(bool parseComment=false)
void SetVarAsk(const string &name, const string &value)
CQueryParseTree * GetDoTree() const
Return "do" clause.
void SetVarChoiceFloat(double value)
void AttachWhereTree(CQueryParseTree *pWhereTree)
Attach where tree after its constrution in qParser.
void x_SortParseTree(CQueryParseTree::TNode &node) const
Sorts the nodes according to a weight function for faster tree evaluation.
TFunctionNamesList m_WhereFunctionsList
list of functions available for Where clause
void x_ParseNumericParameterValue(int sign, CScanner::SLocation start)
Parses numeric value of a function parameter.
void Reset(const char *sMacroText)
bool HasIdentifier(const string &ident) const
Return true if identifier is in datasource (only works if m_Exec not NULL)
int x_SetCurrentLexem(Int4 &pos, CScanner::EToken token)
void SetFunctionParameterAsInt(Int8 value, const CQueryParseNode::SSrcLoc &pos)
const char * m_StrMacro
string to be parsed
void x_ParseWhere()
Entry point to parse where clause.
void SetVarBool(const string &name, bool value)
CQueryParseTree * x_QParseWhere(const string &str, unsigned line, unsigned linePos) const
Translates Where clause into a tree.
void SetThreadCount(const string &threads)
Set number of threads.
void SetSource(const string &source_text)
Work with macro source text.
char m_Str[MAX_STRING_LEXEM_LENGTH+1]
void x_InternalParseWhere(const CScanner::EToken terminator, string &str, CQueryParseTree *&tree)
Extracts Where clause string and builds Where clause tree; it uses terminator token to determine the ...
void x_ParseBody()
Entry point to parse body section.
@ eErrorLineAndColumn
Report the line and column for the error (default)
@ eTokenKWDONE
Keyword done.
@ eTokenKWVARS
Keyword var or vars.
@ eTokenKWDOPARL
Keyword do_p(arallel)
@ eTokenKWPARLAUTO
Keyword auto used with do_p keyword.
@ eTokenNOTEQUAL
'<>' token
@ eTokenRIGHTPAREN
')' token
@ eTokenCOMMENT
Comment read on request.
@ eTokenEOS
If next token is eos.
@ eTokenKWEACH
Keyword each as a part of for each.
@ eTokenKWCHOICE
Keyword choice.
@ eTokenNOTLESS
'>=' token
@ eTokenASNSELECTOR
ASN selector.
@ eTokenLEFTPAREN
'(' token
@ eTokenKWMACRO
Keyword macro.
@ eTokenBOOLCONST
Boolean const value.
@ eTokenLEFTBRACE
'{' token
@ eTokenLEFTBRACKET
'[' token
@ eTokenFLOATNUMBER
Floating point number.
@ eTokenKWWHERE
Keyword where.
@ eTokenASSIGNMENT
'=' token
@ eTokenNOTGREATER
'<=' token
@ eTokenINTNUMBER
Integer number.
@ eTokenKWFROM
Keyword from for specifying named annotation.
@ eTokenSTRING
String in double quotes.
@ eTokenKWRANGE
Keyword range.
@ eTokenASK
String enclosed in % symbols.
@ eTokenRIGHTBRACE
'}' token
@ eTokenRIGHTBRACKET
']' token
@ eTokenSEMICOLON
';' token
@ eTokenKWFOR
Keyword for as a part of for each.
@ eTokenNAMEDANNOT
Named annotation.
int32_t Int4
4-byte (32-bit) signed integer
int64_t Int8
8-byte (64-bit) signed integer
virtual TNode * CreateNode(const string &value, const string &orig_text, bool isIdent)
Create Identifier node or string node.
const TNode * GetQueryTree() const
void Flatten_ParseTree(CQueryParseTree::TNode &node)
Flatten the AND and the OR subtrees transforming them from binary subtrees to n-ary subtrees.
@ eCaseInsensitive
Case insensitive parsing (AnD)
@ eSyntaxCheck
Best possible check for errors.
CRange< TSeqPos > TSeqRange
typedefs for sequence ranges
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define END_SCOPE(ns)
End the previously defined scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define BEGIN_SCOPE(ns)
Define a new scope.
static string Int8ToString(Int8 value, TNumToStringFlags flags=0, int base=10)
Convert Int8 to string.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
static string TruncateSpaces(const string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string.
@ eNocase
Case insensitive compare.
TNodeList::iterator TNodeList_I
TTreeType * DetachNode(TTreeType *subnode)
Remove the subtree from the tree without destroying it.
unsigned int CountNodes(unsigned int depth=1, TCountNodes how=0) const
Count nodes of the tree of which this node is a root.
TNodeList_CI SubNodeBegin(void) const
Return first const iterator on subnode list.
TNodeList::const_iterator TNodeList_CI
void AddNode(TTreeType *subnode)
Add new subnode.
TNodeList_CI SubNodeEnd(void) const
Return last const iterator on subnode list.
const TValue & GetValue(void) const
Return node's value.
constexpr auto sort(_Init &&init)
static const char * str(char *buf, int n)