+ return name;
+}
+
+/*
+ Given a name of a context that we want to create, finds a list of context
+ definitions such that:
+ - the first element in the list defines a context that is a valid child of
+ the context defined by this Context_def
+ - each subsequent element in the list defines a context that is a valid child
+ of the the context defined by the preceding element in the list
+ - the last element in the list defines a context with the given name
+
+ The ADDITIONAL_ACCEPTS parameter is a list of additional contexts that this
+ specific context def (but not any of the child context defs) should accept.
+*/
+vector<Context_def *>
+Context_def::path_to_acceptable_context (SCM type_sym,
+ Output_def *odef,
+ SCM additional_accepts) const
+{
+ set<const Context_def *> seen;
+ return internal_path_to_acceptable_context (type_sym, odef, additional_accepts, &seen);
+}
+
+/*
+The SEEN parameter is a set which keeps track of visited contexts, allowing
+contexts of the same type to be nested.
+*/
+vector<Context_def*>
+Context_def::internal_path_to_acceptable_context (SCM type_sym,
+ Output_def *odef,
+ SCM additional_accepts,
+ set<const Context_def *> *seen) const
+{
+ assert (scm_is_symbol (type_sym));
+
+ SCM accepted = get_accepted (additional_accepts);
+
+ vector<Context_def*> accepteds;
+ for (SCM s = accepted; scm_is_pair (s); s = scm_cdr (s))
+ if (Context_def *t = unsmob_context_def (find_context_def (odef,
+ scm_car (s))))
+ accepteds.push_back (t);
+
+ vector<Context_def*> best_result;
+ for (vsize i = 0; i < accepteds.size (); i++)