1 /* Copyright Vladimir Prus 2003. Distributed under the Boost */
2 /* Software License, Version 1.0. (See accompanying */
3 /* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */
6 #include "../timestamp.h"
8 #include "../strings.h"
10 #include "../variable.h"
11 #include "../compile.h"
13 LIST* get_grist(char* f)
15 char* end = strchr(f, '>');
21 string_append_range(s, f, end+1);
22 result = list_new(object_new(s->value));
29 rule create ( raw-properties * )
31 raw-properties = [ sequence.unique
32 [ sequence.insertion-sort $(raw-properties) ] ] ;
34 local key = $(raw-properties:J=-:E=) ;
38 .ps.$(key) = [ new property-set $(raw-properties) ] ;
40 return $(.ps.$(key)) ;
44 LIST *property_set_create( FRAME *frame, int flags )
46 LIST* properties = lol_get( frame->args, 0 );
49 LIST* order_sensitive = 0;
58 /* Sort all properties which are not order sensitive */
59 for(tmp = properties; tmp; tmp = tmp->next) {
60 LIST* g = get_grist(tmp->string);
61 LIST* att = call_rule("feature.attributes", frame, g, 0);
62 if (list_in(att, "order-sensitive")) {
63 order_sensitive = list_new( order_sensitive, copystr(tmp->string));
65 sorted = list_new( sorted, copystr(tmp->string));
70 sorted = list_sort(sorted);
71 sorted = list_append(sorted, order_sensitive);
72 unique = list_unique(sorted);
74 sorted = list_sort(properties);
75 unique = list_unique(sorted);
78 string_append(var, ".ps.");
80 iter = list_begin( unique ), end = list_end( unique );
81 for( ; iter != end; iter = list_next( iter ) ) {
82 string_append(var, object_str( list_item( iter ) ));
83 string_push_back(var, '-');
85 name = object_new(var->value);
86 val = var_get(frame->module, name);
89 OBJECT* rulename = object_new("new");
90 val = call_rule(rulename, frame,
91 list_append(list_new(object_new("property-set")), unique), 0);
92 object_free(rulename);
94 var_set(frame->module, name, list_copy(val), VAR_SET);
104 /* The 'unique' variable is freed in 'call_rule'. */
111 void init_property_set()
114 const char* args[] = { "raw-properties", "*", 0 };
115 declare_native_rule("property-set", "create", args, property_set_create, 1);