diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/xsim/xsim.properties.code.tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/xsim/xsim.properties.code.tex | 116 |
1 files changed, 65 insertions, 51 deletions
diff --git a/Master/texmf-dist/tex/latex/xsim/xsim.properties.code.tex b/Master/texmf-dist/tex/latex/xsim/xsim.properties.code.tex index 0bbc972f219..12a6fdf220b 100644 --- a/Master/texmf-dist/tex/latex/xsim/xsim.properties.code.tex +++ b/Master/texmf-dist/tex/latex/xsim/xsim.properties.code.tex @@ -49,13 +49,39 @@ \msg_line_context: . \\ However,~ property~ `#1'~ is~ not~ a~ boolean~ property! } - + +\msg_new:nnn {xsim} {unbalanced-property-list} + { + There~ is~ a~ mis-match~ in~ the~ property~ list: \\ + `#1' \\ + \msg_line_context: + } + \seq_new:N \l__xsim_properties_seq \seq_new:N \l__xsim_boolean_properties_seq \seq_new:N \l__xsim_unique_properties_seq \seq_new:N \l__xsim_noupdate_properties_seq \seq_new:N \l__xsim_given_properties_seq -\prop_new:N \g__xsim_properties_prop + +% #1: type +% #2: id +% #3: property +\cs_new_protected:Npn \__xsim_define_property:nnn #1#2#3 + { \xsim_attribute_new:nn {#1!#2} {#3} } + +% check if property is set: +% #1: type +% #2: id +% #3: property +\prg_new_conditional:Npnn \xsim_if_property_set:nnn #1#2#3 {p,T,F,TF} + { + \xsim_attribute_if_set:nnTF {#1!#2} {#3} + { \prg_return_true: } + { \prg_return_false: } + } +\prg_generate_conditional_variant:Nnn \xsim_if_property_set:nnn + {nx,nnx,xx,nV} + {T,F,TF} % new property: % #1: boolean if unique @@ -88,8 +114,6 @@ \seq_if_in:NnF \l__xsim_unique_properties_seq {#4} { \seq_put_right:Nn \l__xsim_unique_properties_seq {#4} } \seq_new:c {l__xsim_unique_property_#4_values_seq} - \prop_new:c {g__xsim_property_#4_type_prop} - \prop_new:c {g__xsim_property_#4_id_prop} } { \xsim_verbose:n { Declaring~ new~ exercise~ property~ `#4'. } } } @@ -160,27 +184,27 @@ % #4: value \cs_new_protected:Npn \xsim_set_property:nnnn #1#2#3#4 { - \xsim_if_property_exist:nTF {#3} + \xsim_if_property_exist:nTF {#3} % _p { - \xsim_if_property_set:nnnTF {#1} {#2} {#3} + \xsim_if_property_set:nnnTF {#1} {#2} {#3} % _p { - \xsim_if_property_unique_value:nnTF {#3} {#4} + \xsim_if_property_unique_value:nnTF {#3} {#4} %_p { \msg_warning:nnnn {xsim} {property-unique} {#3} {#4} } { - \xsim_if_property_boolean:nTF {#3} + \xsim_if_property_boolean:nTF {#3} % _p { \__xsim_set_boolean_property:nnnn {#1} {#2} {#3} {#4} } { - \xsim_if_property_unique:nTF {#3} + \xsim_if_property_unique:nTF {#3} % _p { \__xsim_set_unique_property:nnnn {#1} {#2} {#3} {#4} } { \__xsim_set_property:nnnn {#1} {#2} {#3} {#4} } } } } { - \xsim_if_property_boolean:nTF {#3} + \xsim_if_property_boolean:nTF {#3} % _p { \__xsim_set_boolean_property:nnnn {#1} {#2} {#3} {#4} } { - \xsim_if_property_unique:nTF {#3} + \xsim_if_property_unique:nTF {#3} % _p { \__xsim_set_unique_property:nnnn {#1} {#2} {#3} {#4} } { \__xsim_set_property:nnnn {#1} {#2} {#3} {#4} } } @@ -218,6 +242,17 @@ % #1: type % #2: id % #3: property +\cs_new_protected:Npn \__xsim_unset_property:nnn #1#2#3 + { + \xsim_verbose:n + { Un-setting~ property~ `#3'~ of~ exercise~ type~ `#1'~ id~ `#2'. } + \__xsim_remove_property_from_list:nnn {#1} {#2} {#3} + \xsim_attribute_unset:nn {#1!#2} {#3} + } + +% #1: type +% #2: id +% #3: property \cs_new_protected:Npn \xsim_unset_property:nnn #1#2#3 { \xsim_if_property_exist:nTF {#3} @@ -237,10 +272,10 @@ Setting~ property~ `#3'~ of~ exercise~ type~ `#1'~ id~ `#2'~ to~ value~ `#4'. } - \__xsim_remove_property_from_list:nnn {#1} {#2} {#3} + \__xsim_remove_property_from_list:nnn {#1} {#2} {#3} % now we can safely add the property to the list: \xsim_add_to_list:nn {#3} {#1-#2=={#4}} - \prop_gput:Nnn \g__xsim_properties_prop {#2!#1!#3} {#4} + \xsim_attribute_set:nnn {#1!#2} {#3} {#4} } \cs_generate_variant:Nn \__xsim_set_property:nnnn {VVnV} @@ -250,19 +285,8 @@ % #4: value \cs_new_protected:Npn \__xsim_set_property_reverse:nnnn #1#2#3#4 { - \prop_gput:cnn {g__xsim_property_#3_type_prop} {#4} {#1} - \prop_gput:cnn {g__xsim_property_#3_id_prop} {#4} {#2} - } - -% #1: type -% #2: id -% #3: property -\cs_new_protected:Npn \__xsim_unset_property:nnn #1#2#3 - { - \xsim_verbose:n - { Un-setting~ property~ `#3'~ of~ exercise~ type~ `#1'~ id~ `#2'. } - \__xsim_remove_property_from_list:nnn {#1} {#2} {#3} - \prop_gremove:Nn \g__xsim_properties_prop {#2!#1!#3} + \xsim_attribute_set:nnn {type:#3} {#4} {#1} + \xsim_attribute_set:nnn {id:#3} {#4} {#2} } \tl_set:Nx \l__xsim_tmpa_tl { \cs_to_str:N \{ } @@ -280,6 +304,9 @@ \str_set:Nn #3 {#6} } +% #1: type +% #2: id +% #3: property \cs_new_protected:Npn \__xsim_remove_property_from_list:nnn #1#2#3 { % make sure we change the entry if it has been recorded previously: @@ -331,6 +358,8 @@ \clist_map_inline:nn {#3} { \seq_set_split:Nnx \l__xsim_tmpa_seq {=} { \tl_trim_spaces:n {##1} } + \int_compare:nNnT { \seq_count:N \l__xsim_tmpa_seq } > {2} + { \msg_error:nnn {xsim} {unbalanced-property-list} {##1} } \xsim_set_property:nnxx {#1} {#2} @@ -343,36 +372,21 @@ } \cs_generate_variant:Nn \xsim_set_properties:nnn {nnx,nxx,nV,nVx} -% check if property is set: -% #1: type -% #2: id -% #3: property -\prg_new_conditional:Npnn \xsim_if_property_set:nnn #1#2#3 {T,F,TF} - { - \prop_if_in:NnTF \g__xsim_properties_prop {#2!#1!#3} - { \prg_return_true: } - { \prg_return_false: } - } -\prg_generate_conditional_variant:Nnn \xsim_if_property_set:nnn - {nx,nnx,xx,nV} - {T,F,TF} - % ---------------------------------------------------------------------------- -\prop_new:N \g__xsim_property_aliases_prop \seq_new:N \g__xsim_property_aliases_seq % #1: property \prg_new_conditional:Npnn \xsim_if_property_alias:n #1 {p,T,F,TF} { - \prop_if_in:NnTF \g__xsim_property_aliases_prop {#1} + \seq_if_in:NnTF \g__xsim_property_aliases_seq {#1} { \prg_return_true: } { \prg_return_false: } } % #1: property \cs_new:Npn \xsim_property_alias:n #1 - { \prop_item:Nn \g__xsim_property_aliases_prop {#1} } + { \xsim_attribute_get:nn {#1} {alias} } % #1: property % #2: alias of @@ -382,8 +396,7 @@ { \xsim_verbose:n { Making~ property~ `#1'~ an~ alias~ of~ property~ `#2'. } - \prop_new:c {g__xsim_property_#1_alias_prop} - \prop_gput:Nnn \g__xsim_property_aliases_prop {#1} {#2} + \xsim_attribute_set:nnn {#1} {alias} {#2} \seq_gput_right:Nn \g__xsim_property_aliases_seq {#1} } } @@ -408,8 +421,7 @@ \xsim_if_property_set:nnxT {#1} {#2} { \xsim_property_alias:n {#3} } { - \prop_gput:cxx {g__xsim_property_#3_alias_prop} - { \xsim_get_property:nnn {#1} {#2} {#3} } + \xsim_attribute_set:nnx {alias:#1!#2} {#3} { \xsim_get_property:nnf {#1} {#2} { \xsim_property_alias:n {#3} } @@ -433,18 +445,18 @@ % #2: id % #3: property \cs_new:Npn \xsim_get_property:nnn #1#2#3 - { \prop_item:Nn \g__xsim_properties_prop { #2 ! #1 ! #3 } } + { \xsim_attribute_get:nn {#1!#2} {#3} } \cs_generate_variant:Nn \xsim_get_property:nnn {nx,ne,xx,oo,no,nnf,nf,oof,nV} % #1: property % #2: value \cs_new:Npn \xsim_get_id_for_property:nn #1#2 - { \prop_item:cn {g__xsim_property_#1_id_prop} {#2} } + { \xsim_attribute_get:nn {id:#1} {#2} } % #1: property % #2: value \cs_new:Npn \xsim_get_type_for_property:nn #1#2 - { \prop_item:cn {g__xsim_property_#1_type_prop} {#2} } + { \xsim_attribute_get:nn {type:#1} {#2} } \cs_generate_variant:Nn \xsim_get_type_for_property:nn {nV} % #1: id or ID @@ -512,7 +524,7 @@ \cs_generate_variant:Nn \xsim_if_boolean_property:nnnF {nV} \cs_new_protected:Npn \xsim_save_property:nnnN #1#2#3#4 - { \prop_get:NnN \g__xsim_properties_prop {#2!#1!#3} #4 } + { \tl_set:No #4 { \cs:w __xsim_property_#2!#1!#3: \cs_end: } } \cs_generate_variant:Nn \xsim_save_property:nnnN {nx,xx} \cs_new_protected:Npn \xsim_gsave_property:nnnN #1#2#3#4 @@ -524,3 +536,5 @@ % ---------------------------------------------------------------------------- \file_input_stop: +2020/03/09 - add meaningful error if a comma is missing in the property list +2020/03/14 - performance optimizations |