src/PredFinder/macros/ReadingMacroSet.cpp
/**
 * Contains one set of related macro rules, typically
 * associated with a particular private extraction
 * predicate (i.e. found in P-ELF, valid in the private
 * catalog). Handles shortcut mapping for convenient
 * macro writing.
 *
 * @param sexp The read S-expression.
 *
 * @author nward@bbn.com
 * @date 2010.10.05
 **/
Contains one set of related macro rules, typically
associated with a particular private extraction
predicate . Handles shortcut mapping for convenient
macro writing.

@param sexp The read S-expression.


Contains one set of related macro rules typically associated with a particular private extraction predicate . Handles shortcut mapping for convenient macro writing . @param sexp The read S - expression .
ReadingMacroSet::ReadingMacroSet(Sexp* sexp) {
	std::stringstream error;
	if (sexp->getNumChildren() < 2) {
		error << "Ill-formed reading macro set: need at least 2 top-level nodes; got " << sexp->getNumChildren();
		error << " " << sexp->to_debug_string();
		throw UnexpectedInputException("ReadingMacroSet::ReadingMacroSet(Sexp*)", error.str().c_str());
	}
	_macro_set_name = sexp->getFirstChild()->getValue();
	Sexp* references_sexp = NULL;
	Sexp* macros_sexp = NULL;
	for (int j = 1; j < sexp->getNumChildren(); j++) {
		Sexp* child_sexp = sexp->getNthChild(j);
		if (child_sexp->getFirstChild()->getValue() == Symbol(L"macro-reference")) {
			references_sexp = child_sexp;
		} else if (child_sexp->getFirstChild()->getValue() == Symbol(L"macros")) {
			macros_sexp = child_sexp;
		}
	}
	if (references_sexp != NULL) {
		for (int r = 1; r < references_sexp->getNumChildren(); r++) {
			Sexp* reference_sexp = references_sexp->getNthChild(r);
			ReadingMacroExpression_ptr reference_expression = ReadingMacroExpression::from_s_expression(reference_sexp, _macro_shortcuts);
			if (!reference_expression->is_shortcut()) {
				error << "Ill-formed reading macro set: need shortcut expression in references; got ";
				error << " " << reference_sexp->to_debug_string();
				throw UnexpectedInputException("ReadingMacroSet::ReadingMacroSet(Sexp*)", error.str().c_str());
			}
			_macro_shortcuts.insert(ReadingMacroExpressionShortcutMap::value_type(reference_expression->get_shortcut(), reference_expression));
		}
	}
	if (macros_sexp != NULL) {
		for (int m = 1; m < macros_sexp->getNumChildren(); m++) {
			ReadingMacro_ptr ptr(boost::make_shared<ReadingMacro>(macros_sexp->getNthChild(m), _macro_shortcuts));
			if (_macros.find(ptr) != _macros.end()) {
				error << "Ill-formed reading macro set: id previously encountered: ";
				error << ptr->get_id();
				throw UnexpectedInputException("ReadingMacroSet::ReadingMacroSet(Sexp*)", error.str().c_str());
			}
			else {
				_macros.insert(ptr);
			}
		}
	}
}
ReadingMacroSet :: ReadingMacroSet ( Sexp * sexp ) { std :: stringstream error ; if ( sexp -> getNumChildren ( ) < 2 ) { error << " " << sexp -> getNumChildren ( ) ; error << " " << sexp -> to_debug_string ( ) ; throw UnexpectedInputException ( " " , error . str ( ) . c_str ( ) ) ; } _macro_set_name = sexp -> getFirstChild ( ) -> getValue ( ) ; Sexp * references_sexp = NULL ; Sexp * macros_sexp = NULL ; for ( int j = 1 ; j < sexp -> getNumChildren ( ) ; j ++ ) { Sexp * child_sexp = sexp -> getNthChild ( j ) ; if ( child_sexp -> getFirstChild ( ) -> getValue ( ) == Symbol ( L" " ) ) { references_sexp = child_sexp ; } else if ( child_sexp -> getFirstChild ( ) -> getValue ( ) == Symbol ( L" " ) ) { macros_sexp = child_sexp ; } } if ( references_sexp != NULL ) { for ( int r = 1 ; r < references_sexp -> getNumChildren ( ) ; r ++ ) { Sexp * reference_sexp = references_sexp -> getNthChild ( r ) ; ReadingMacroExpression_ptr reference_expression = ReadingMacroExpression :: from_s_expression ( reference_sexp , _macro_shortcuts ) ; if ( ! reference_expression -> is_shortcut ( ) ) { error << " " ; error << " " << reference_sexp -> to_debug_string ( ) ; throw UnexpectedInputException ( " " , error . str ( ) . c_str ( ) ) ; } _macro_shortcuts . insert ( ReadingMacroExpressionShortcutMap :: value_type ( reference_expression -> get_shortcut ( ) , reference_expression ) ) ; } } if ( macros_sexp != NULL ) { for ( int m = 1 ; m < macros_sexp -> getNumChildren ( ) ; m ++ ) { ReadingMacro_ptr ptr ( boost :: make_shared < ReadingMacro > ( macros_sexp -> getNthChild ( m ) , _macro_shortcuts ) ) ; if ( _macros . find ( ptr ) != _macros . end ( ) ) { error << " " ; error << ptr -> get_id ( ) ; throw UnexpectedInputException ( " " , error . str ( ) . c_str ( ) ) ; } else { _macros . insert ( ptr ) ; } } } }
Contains one set of related macro rules, typically
 associated with a particular private extraction
 predicate (i.e.
Contains one set of related macro rules typically associated with a particular private extraction predicate ( i . e .
// Local error messages
 // Make sure we have an S-expression worth reading
 // Get the macro set name
 // Loop over the child S-expressions, looking for macro-relevant expressions
 //   Allows us to embed macros in pattern files if necessary
 // Check if this child is one we need to read
 // Loop over the macro parameter and operator shortcuts, if any, reading them
 // Determine the type of shortcut
 // Create the appropriate shortcut by type and store it
 // Loop over the macro rules, if any, reading them
