2 translator-scheme.cc -- implement
4 source file of the GNU LilyPond music typesetter
6 (c) 2002--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "translator.hh"
11 #include "translator-def.hh"
13 #include "translator-group.hh"
14 #include "lily-guile.hh"
16 LY_DEFINE(ly_get_context_property,
17 "ly:get-context-property", 2, 0, 0,
18 (SCM context, SCM name),
19 "retrieve the value of @var{name} from context @var{context}")
21 Translator *t = unsmob_translator (context);
22 Translator_group* tr= dynamic_cast<Translator_group*> (t);
23 SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Translator group");
24 SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
26 return tr->internal_get_property (name);
30 LY_DEFINE(ly_set_context_property,
31 "ly:set-context-property", 3, 0, 0,
32 (SCM context, SCM name, SCM val),
33 "set value of property @var{name} in context @var{context} to @var{val}.")
35 Translator *t = unsmob_translator (context);
36 Translator_group* tr= dynamic_cast<Translator_group*> (t);
38 SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
39 SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
41 tr->internal_set_property (name, val);
43 return SCM_UNSPECIFIED;
47 LY_DEFINE(ly_context_property_where_defined,
48 "ly:context-property-where-defined", 2, 0, 0,
49 (SCM context, SCM name),
50 "Return the context above @var{context} where @var{name} is defined.")
52 Translator *t = unsmob_translator (context);
53 Translator_group* tr = dynamic_cast<Translator_group*> (t);
54 SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
55 SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
57 return tr->where_defined (name)->self_scm();
60 LY_DEFINE(ly_unset_context_property,
61 "ly:unset-context-property", 2, 0, 0,
62 (SCM context, SCM name),
63 "Unset value of property @var{name} in context @var{context}.")
65 Translator *t = unsmob_translator (context);
66 Translator_group* tr = dynamic_cast<Translator_group*> (t);
67 SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
68 SCM_ASSERT_TYPE(gh_symbol_p (name), name, SCM_ARG2, __FUNCTION__, "symbol");
70 tr->unset_property (name);
72 return SCM_UNSPECIFIED;
77 LY_DEFINE(ly_context_parent,
78 "ly:context-parent", 1, 0, 0,
80 "Return the parent of @var{context}, #f if none.")
82 Translator *t = unsmob_translator (context);
83 Translator_group* tr= dynamic_cast<Translator_group*> (t);
85 SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
87 tr = tr->daddy_trans_ ;
89 return tr->self_scm();
96 LY_DEFINE(ly_context_properties,
97 "ly:context-properties", 1, 0, 0,
99 "Return all properties of @var{context} in an alist.")
101 Translator *t = unsmob_translator (context);
102 Translator_group* tr= dynamic_cast<Translator_group*> (t);
104 SCM_ASSERT_TYPE(tr, context, SCM_ARG1, __FUNCTION__, "Context");
106 return tr->properties_as_alist ();
111 LY_DEFINE(ly_translator_name,
112 "ly:translator-name", 1,0,0, (SCM trans),
113 "Return the type name of the translator @var{trans}.")
115 Translator* tr = unsmob_translator (trans);
116 SCM_ASSERT_TYPE(tr, trans, SCM_ARG1, __FUNCTION__, "Context");
118 char const* nm = classname (tr);
119 return scm_makfrom0str (nm);
122 LY_DEFINE(ly_translator_description,
123 "ly:translator-description",
125 "Return an alist of properties of translator @var{me}.")
127 Translator *tr =unsmob_translator (me);
128 SCM_ASSERT_TYPE (tr, me, SCM_ARG1, __FUNCTION__, "Context");
130 return tr->translator_description ();
135 Translator::print_smob (SCM s, SCM port, scm_print_state *)
137 Translator *sc = (Translator *) ly_cdr (s);
139 scm_puts ("#<Translator ", port);
140 if (Translator_def *d=unsmob_translator_def (sc->definition_))
142 scm_display (d->type_name_, port);
145 scm_display (ly_translator_name (s), port);
147 scm_display (sc->simple_trans_list_, port);
150 don't try to print properties, that is too much hassle.
152 scm_puts (" >", port);