53 #define _TRACE(arg) ((void)0)
93 while (!line_reader->
AtEOF()) {
101 x_SetError(
string(
"Problem with reading file:") + filename);
106 macro_list.resize(0);
110 while (parser.
Parse(
false)) {
112 macro_list.push_back(mr);
121 macro_list.resize(0);
142 : m_SynFiles(&syn_fnames), m_MacroRep(
ConstRef(¯o_rep)), m_Engine(engine) {}
157 bool found_boolargs =
false;
159 while (subnode != endnode && !found) {
161 auto arg = (*subnode)->GetValue();
163 m_MacroRep->GetNodeValue(arg.GetStrValue(),
value);
168 tmp = arg.GetStrValue();
170 else if (
value.IsString()) {
175 m_SynFiles->push_back(
tmp);
179 m_SynFiles->push_back(
tmp);
183 else if (
value.IsBool()) {
184 found_boolargs =
true;
193 vector<string>* m_SynFiles{
nullptr };
204 CSynFileReader fnc(fnames, macro_rep, engine);
213 bool has_synonym =
false;
215 for (
const auto& macro_it : macro_list) {
222 auto where_tree = macro_it->GetWhereClause();
224 vector<string> fnames;
225 SearchForSynonymFile(*where_tree, *macro_it, fnames,
this);
226 for (
const auto& f_it : fnames) {
233 auto do_where_trees = macro_it->GetAssignmentWhereClauses();
234 for (
const auto& wh_it : do_where_trees) {
235 vector<string> fnames;
236 SearchForSynonymFile(*wh_it, *macro_it, fnames,
this);
237 for (
const auto& f_it : fnames) {
244 if (!found && has_synonym) {
245 LOG_POST(
Info <<
"Synonym file not found for:\n" << macro_it->GetSource());
249 vector<string> file_names(syn_files.
begin(), syn_files.
end());
260 while (!line_reader->
AtEOF()) {
268 x_SetError(
string(
"Problem with reading file:") + filename);
273 vector<CRef<CMacroRep>> parsed_vec;
278 while (parser.
Parse(
false)) {
280 parsed_vec.push_back(mr);
298 lib.reserve(lib.size() + parsed_vec.size());
299 lib.insert(lib.end(), parsed_vec.begin(), parsed_vec.end());
328 if (macro_text.empty()) {
384 m_ErrorMessage =
"Missing FOR EACH statement or incorrect selector specified or incorrect NA provided";
387 if (throw_on_error) {
390 msg =
"Missing FOR EACH statement, or unsupported selector";
393 msg =
"Incorrect NA provided or missing FOR EACH statement or unsupported selector specified";
415 "Wrong type of computed WHERE clause",
tree->GetQueryTree());
445 int nr_nonmatched = 0;
446 const string msg =
m_DataIter->GetUnMatchedTableEntries(nr_nonmatched);
478 _TRACE(
"Resolving identifier: " << identifier);
481 _TRACE(
"Trying to get it as node value (IMacroVar) from m_MacroRep: " <<
m_MacroRep);
487 _TRACE(
"Trying to get it as an RT Var");
490 _TRACE(
"Successfully resolved as node value");
494 _TRACE(
"Trying to get it via ResolveIdentToSimple() from m_DataIter: " <<
m_DataIter);
500 _TRACE(
"Successfully resolved via ResolveIdentToSimple() from m_DataIter");
504 _TRACE(
"All attempts to resolve failed");
508 _TRACE(
"Identifier resolved successfully: " << res);
529 "Function '" + name +
"' not implemented", &qnode);
535 "Function '" + name +
"' used in the wrong DO/WHERE clause scope", &qnode);
553 string message(
"Function ");
555 message +=
" failed";
570 catch (
const std::exception& e) {
590 string name = iter.first;
595 do_funcs.push_back(name);
598 where_funcs.push_back(name);
601 do_funcs.push_back(name);
602 where_funcs.push_back(name);
616 _TRACE(
"Looking for: " << name);
637 _TRACE(
"Looking for (whether it exists) :" << name);
651 _TRACE(
"Looking for: " << name);
675 _TRACE(
"Looking for: " << identifier);
680 string sRTVarRoot, sRTVarFields;
690 _TRACE(
"set reference from node: " << rt_var <<
" to node: " << &v);
699 _TRACE(
"resolved subfields of run-time vars");
702 _TRACE(
"set reference from node: " << rt_var <<
" to node: " << &v);
707 _TRACE(
"set reference from node: " << rt_var <<
" to node: " << &v);
714 _TRACE(
"got value using iterator in form of objects (from tmpObj)");
717 _TRACE(
"got simple value using iterator");
723 _TRACE(
"RT Var not found");
1043 if (lookup_synonym_file) {
1077 if (!report.empty()) {
1090 if (!report.empty() &&
count > 0) {
1116 found = (*it)->Merge(*
log);
1129 string s =
"Macro (";
1131 s +=
") execution started.";
1140 string s =
"Macro (";
1142 s +=
") execution ";
1143 s += ((status) ?
"was successful" :
"failed");
1144 s +=
". Elapsed time - ";
1155 s +=
") error message: '";
Subclass of the IQueryParseUserObject which is held as the user-defined object in each CQueryParseNod...
The following asn-selectors are defined to be used in the FOR EACH statement:
class CMacroExecException
class CMacroExecException
Subclass of CQueryExec that adds: 1) Macro identifiers resolution 2) Where clause evaluation.
Class provides macro language interface for bulk bio-editing.
Class for parsed macro representation.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Query tree and associated utility methods.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
definition of a Culling tree
Base class for any user function that performs editing operations on ASN.1 data.
container_type::iterator iterator
const_iterator begin() const
const_iterator end() const
const_iterator find(const key_type &key) const
iterator_bool insert(const value_type &val)
const_iterator begin() const
const_iterator end() const
static const char * column
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define DIAG_COMPILE_INFO
Make compile time diagnostic information object to use in CNcbiDiag and CException.
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
const string & GetMsg(void) const
Get message string.
string ReportAll(TDiagPostFlags flags=eDPF_Exception) const
Report all exceptions.
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
void Info(CExceptionArgs_Base &args)
static const char * sm_BsrcForSeq
static CTempString GetFuncName()
static const char * sm_Stop
vector< CRef< CMacroRep > > TMacroLibrary
static CTempString GetFuncName()
static const char * sm_Contain
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_Lower
static CTempString GetFuncName()
static CTempString GetFuncName()
bool Parse(bool bSingleMacroMode=true, CQueryExec *exec=NULL)
Parse the macro and build its representation Function throws CMacroException if parsing is unsuccessf...
static const char * sm_BsrcForSeqdesc
void SetName(const string &name)
static const char * sm_PubIssue
static const char * sm_SeqNa
class CMacroFunction_LocationSeqType IS_SEQ_AA(["location"]) - returns true if the sequence identifie...
static CTempString GetFuncName()
EScopeEnum GetFuncScope()
bool GetNodeValue(const string &name, IQueryMacroUserObject &v) const
Function fills in IQueryMacroUserObject-derived node out of stored variable.
void AddToReport(const string &report)
function gradually builds the log report
void GatherUnMatchedTableEntries(const string &report, const int count)
Used when applying a table to the entry: it stores the values and number of table entries that were n...
static CTempString GetFuncName()
static const char * sm_SeqForFeat
static CTempString GetFuncName()
shared_ptr< CISOJTALookupWithCache > m_ISOJTAUpdater
void ThrowCMacroExecException(const CDiagCompileInfo &info, CMacroExecException::EErrCode code, const string &message, const CQueryParseTree::TNode *treeNode, const CException *previous=nullptr)
Throws CMacroExecException with the specified message and error location from the TNode.
void SetSource(const char *sMacroText)
Reset the parser and sets macro text to be parsed.
void x_ResetStatus(void)
Reset status and error related private data.
static CTempString GetFuncName()
static CTempString GetFuncName()
CIRef< IMacroBioDataIter > m_DataIter
static const char * sm_FunctionName
class CMacroFunction_SetPubField SetPub_Date(year, month, day, season, hour, minute,...
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
const string & GetForEachString() const
Return "for each" string.
static CTempString GetFuncName()
static const char * sm_FunctionName
class CMacroFunction_ApplyPublication SetPub_Sub(author_field_name, author_field_value) Apply new pub...
static CTempString GetFuncName()
static CTempString GetFuncName()
void EvaluateTree(CQueryParseTree &Qtree, IResolver &resolver, bool query_tree, bool case_sensitive=false)
Evaluates tree.
static const char * sm_InList
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_PubJournal
void AddDataChanged(bool change)
function to collect whether any data was changed during the execution of the macro
static const char * sm_Equal
static const char * sm_Last
const string & GetErrorReport() const
static const char * sm_SeqForDescr
class CMacroFunction_Sequence_For_Seqdesc SEQUENCE_FOR_SEQDESC(field_name) SEQUENCE_FOR_SEQFEAT(field...
bool m_Status
execution status of most recent command
static CTempString GetFuncName()
virtual CRef< CMQueryNodeValue > GetOrCreateRTVar(const string &name)
Gets or creates run-time vars (used in assignment in Do clause)
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
CMacroRep * DetachMacroRep()
Detach macro representation for futher processing Caller is responsible for deletion of returned obje...
static const char * sm_PartialStart
class CMacroFunction_LocPartialTest - tests whether the location is 5'/3' partial ISPARTIALSTART() - ...
list< SResolvedField > TObs
static CTempString GetFuncName()
static const char * sm_SeqAa
bool x_AppendToLibrary(const string &filename, CMacroLib::TMacroLibrary &lib)
virtual bool GetTmpRTVarObject(const string &name, CObjectInfo &oi)
static CTempString GetFuncName()
static const char * sm_PubSerialNumber
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_MolinfoForFeat
bool GetSimpleTypeValue(CObjectInfo &oi, const string &field_name, CMQueryNodeValue &value)
Get single node data from the node specified by parameter of type CObjectInfo and additionally field ...
static const char * sm_UpperAll
static const char * sm_FuncVolume
class CMacroFunction_SetPubVolIssuePages SetPubVolume(newValue, existing_text, delimiter,...
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
const TObs & GetObjects() const
static const char * sm_PubAuthors
void AppendError(const string &errmsg)
void LogStart(const string ¯o_name)
log start of macro execution
bool ResolveIdentToObjects(const CObjectInfo &oi, const string &identifier, CMQueryNodeValue &v)
Resolve name to the list of objects.
static CTempString GetFuncName()
shared_ptr< objects::edit::CRemoteUpdater > m_RemoteUpdater
static CTempString GetFuncName()
string m_ErrorMessage
error message
void x_SetFunctions(CMacroParser &parser)
Initializes do/where lists of functions in parser.
static CTempString GetFuncName()
TBuiltInFunctionsMap m_BuiltInFunctions
Do section functions.
static const char * sm_FromStart
class CMacroFunction_LocationDistConstraint DISTFROMSTART() [>][=][<] distance DISTFROMSTOP()
static const char * sm_PartialStop
static CTempString GetFuncName()
void SetDataType(EType dt)
const string & GetName() const
shared_ptr< CHugeMacroContext > m_MacroContext
virtual ~CMacroEngine()
class CMacroEngine
unsigned GetColumnNo(void) const
Returns the column number where error occurred.
static CTempString GetFuncName()
static CTempString GetFuncName()
CRef< CMacroCmdComposite > m_CmdComposite
static const char * sm_PunctAll
const CMacroRep * m_MacroRep
temporary data available while Exec is working. It is used by resolver.
static const char * sm_Punct
static const char * sm_Upper
static CTempString GetFuncName()
IEditMacroFunction * x_ResolveFunctionName(const string &name) const
Locates function by name.
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
void LogStop(bool status, const string &err_message)
log end of macro execution this includes time of execution, status, count of changed qualifiers and a...
CQueryParseTree * GetAssignmentWhereClause(int index) const
vector< CRef< IFunctionLog > > m_FunctionsLog
static CTempString GetFuncName()
static CTempString GetFuncName()
EType GetDataType() const
Uint4 m_Column
location of problem in macro text
static CTempString GetFuncName()
static const char * sm_First
CMacroFunction_FirstItem FIRSTOF(objects) - returns the first item from the list of objects LASTOF(ob...
void x_InitStringConstraints(bool lookup_synfile)
Define the list of functions used in string constraints.
CQueryParseTree::TFunctionNames TFunctionNamesList
Type for the list of functions in Where/Do clauses.
static const char * sm_FunctionName
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 BuildReport(const string &rep)
static CTempString GetFuncName()
static CTempString GetFuncName()
const TSeqRange & GetSeqRange() const
Return sequence range.
static const char * sm_BsrcForFeat
const string & GetNamedAnnot() const
Return "from" named annotation.
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_PubVolume
static CTempString GetFuncName()
static CTempString GetFuncName()
const string & GetName() const
Return macro name.
static CTempString GetFuncName()
virtual void ResetTmpRTVarObjects()
static CTempString GetFuncName()
shared_ptr< CDoiLookupWithCache > m_DOIUpdater
void SetRef(CRef< CMQueryNodeValue > node)
bool IsNotSetType() const
Check/get functions result from the top node after calculation.
virtual bool ResolveIdentifier(const string &identifier, CMQueryNodeValue &v, const CQueryParseTree::TNode *parent)
Function resolves identifiers.
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
bool ResolveIdentToSimple(const CObjectInfo &oi, const string &identifier, CMQueryNodeValue &v)
Resolve name to simple types value.
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_FuncPages
bool HasDataChanged() const
bool x_ResolveRTVar(const string &identifier, CMQueryNodeValue &v, const CQueryParseTree::TNode *parent)
Gets the value of RT variable.
static CTempString GetFuncName()
static const char * sm_PubStatus
static CTempString GetFuncName()
void SetNestedState(ENestedFunc type)
const string & GetFuncReport() const
Function extracts statistic from the object.
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
void x_InitSetOfBuiltInFunctions(bool lookup_synfile)
Define the list of functions that is recognized by the engine.
static CTempString GetFuncName()
static const char * sm_PubTitle
class CMacroFunction_PubFields PUB_TITLE(), PUB_ISSUE(), PUB_AFFIL(subfield) - returns a list of CObj...
static const char * sm_PubDOI
static CTempString GetFuncName()
static CTempString GetFuncName()
virtual void AddTmpRTVarObject(const string &name, CObjectInfo &oi)
Temporary run-time variables used in evaluating subqueries in the DO section, used together with the ...
static CTempString GetFuncName()
static CTempString GetFuncName()
void x_SetError(const string &message, Uint4 line=0, Uint4 column=0)
Sets m_Status, error_message and its location.
TTempRTVarsMap m_TempRTVars
static CTempString GetFuncName()
static const char * sm_End
unsigned GetLineNo(void) const
Returns the line number where error occurred.
static CTempString GetFuncName()
static const char * sm_LowerAll
static const char * sm_PubPMID
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_PubDate
virtual bool ExistRTVar(const string &name)
Returns true if the run-time variable, identified by its name, was defined.
static const char * sm_PubAffil
static CTempString GetFuncName()
bool m_EvalDo
Flag indicates if the work should be performed on the Do clause.
CQueryParseTree * GetDoTree() const
Return "do" clause.
static CTempString GetFuncName()
void AddFunctionName(const string &func_name)
function to collect DO function names to be used for processing reporting in huge file mode
static const char * sm_BsrcForMolinfo
class CMacroFunction_GetSeqdesc BIOSOURCE_FOR_MOLINFO(field_name) or BIOSOURCE_FOR_MOLINFO(container,...
static const char * sm_PubCit
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_FromStop
bool ReadAndParseMacros(const string &filename, vector< CRef< CMacroRep >> ¯o_list)
Parses a file containing macros and stores them in a list.
vector< pair< string, int > > m_UnmatchedList
static CTempString GetFuncName()
void Reset()
reset the macro name, qualifier and iteration counts
virtual void CallFunction(const string &name, CQueryParseTree::TNode &qnode)
Function call the function specified by name, passing args as parameters and it can update nv as a re...
static CTempString GetFuncName()
static CTempString GetFuncName()
const CRef< IFunctionLog > & GetFunctionLog() const
static CTempString GetFuncName()
static CTempString GetFuncName()
CRef< CMQueryNodeValue > x_LocateRTVar(const string &identifier)
Gets the pointer to RT variable.
static CTempString GetFuncName()
static const char * sm_Start
static const char * sm_FunctionName
EditRelatedFeatureQual(feat_type, field_name, find_text, repl_text, location, case_sensitive,...
bool GetBoolValue() const
static CTempString GetFuncName()
static const char * sm_PubPages
static CTempString GetFuncName()
vector< string > GetSynonymFilenames(const vector< CRef< CMacroRep >> ¯o_list) const
Extracts synonym files present in the list of macros.
bool m_HugeFileMode
execution will take place in 'huge file mode'
bool AppendToLibrary(const string &filename, CMacroLib::TMacroLibrary &lib)
Parses a file containing macros and appends the results to a map.
static CTempString GetFuncName()
static CTempString GetFuncName()
virtual CQueryParseTree * GetAssignmentWhereClause(int index) const
get one of the "where" sub-clauses which are indentified by an index in the main parsed tree
set< string > m_FuncNames
CQueryParseTree * GetWhereClause() const
Return "where" clause.
static bool s_IsStringMatching(const string &fn_name)
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_FuncIssue
static CTempString GetFuncName()
bool Exec(const CMacroRep ¯o_rep, const CMacroBioData &data, CRef< CMacroCmdComposite > CmdComposite, bool throw_on_error=false, CNcbiOstream *ostream=nullptr)
Executes a macro.
void AddToErrorReport(const string &error)
store encountered errors
void AddFunctionLog(const CRef< IFunctionLog > &log)
static CTempString GetFuncName()
static const char * sm_PubClass
static bool s_IsSynonymFile(const string &str)
static const char * sm_Start
class CMacroFunction_LocEnd Start() and Stop() - return the positional extremes of a location
static CTempString GetFuncName()
CMacroStat m_MacroStat
Most recent executed macro statistics.
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
CMacroRep * Parse(const string ¯o_text)
Parses macro script into its binary representation.
static const char * sm_MolinfoForBsrc
@ eFunctionNotImplemented
CTempString GetCurrentLine(void) const
static CRef< ILineReader > New(const string &filename)
Return a new ILineReader object corresponding to the given filename, taking "-" (but not "....
virtual bool AtEOF(void) const =0
Indicates (negatively) whether there is any more input.
TObjectType * GetNCPointerOrNull(void) const THROWS_NONE
Get pointer value.
CConstRef< C > ConstRef(const C *object)
Template function for conversion of const object pointer to CConstRef.
void Reset(void)
Reset reference object.
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
TObjectType & GetNCObject(void) const
Get object.
uint32_t Uint4
4-byte (32-bit) unsigned integer
unsigned pos
Position in the src line.
unsigned line
Src line number.
const string & GetStrValue() const
@ eString
String ("free text")
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define USING_SCOPE(ns)
Use the specified namespace.
#define END_SCOPE(ns)
End the previously defined scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define BEGIN_SCOPE(ns)
Define a new scope.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
static SIZE_TYPE FindNoCase(const CTempString str, const CTempString pattern, SIZE_TYPE start, SIZE_TYPE end, EOccurrence which=eFirst)
Find the pattern in the specified range of a string using a case insensitive search.
static string LongToString(long value, TNumToStringFlags flags=0, int base=10)
Convert Int to string.
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
static bool SplitInTwo(const CTempString str, const CTempString delim, string &str1, string &str2, TSplitFlags flags=0)
Split a string into two pieces using the specified delimiters.
static void GetCurrentTimeT(time_t *sec, long *nanosec=0)
Get current UTC time in time_t format (with nanoseconds).
Fun TreeDepthFirstTraverse(TTreeNode &tree_node, Fun func)
Depth-first tree traversal algorithm.
ETreeTraverseCode
Tree traverse code returned by the traverse predicate function.
TNodeList_CI SubNodeBegin(void) const
Return first const iterator on subnode list.
TNodeList_CI SubNodeEnd(void) const
Return last const iterator on subnode list.
const TValue & GetValue(void) const
Return node's value.
const TTreeType * GetParent(void) const
Get node's parent.
@ eTreeTraverse
Keep traversal.
@ eTreeTraverseStepOver
Do not traverse current node (pick the next one)
@ ePublication_field_affiliation
@ ePublication_field_pages
@ ePublication_field_pmid
@ ePublication_field_pub_class
@ ePublication_field_issue
@ ePublication_field_date
@ ePublication_field_title
@ ePublication_field_serial_number
@ ePublication_field_authors
@ ePublication_field_volume
@ ePublication_field_journal
@ eSeqtype_constraint_prot
@ eSeqtype_constraint_nuc
@ e_Molinfo
info on the molecule and techniques
@ e_Source
source of materials, includes Org-ref
Lightweight interface for getting lines of data with minimal memory copying.
Macro engine for macro execution.
Functions that resolve field names described in asn format.
Interface class for macro function implementation.
Functions used in the DO/DONE section affecting the top seq-entry.
const GenericPointer< typename T::ValueType > T2 value
Int4 delta(size_t dimension_, const Int4 *score_)
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
Source location (points to the position in the original src) All positions are 0 based.