Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Got basic configuration for document_path working

  • Loading branch information...
commit 1d0397ce55a8a24dda257864bcdfa79e99cdf8cb 1 parent 4ad84b2
Andy Wardley authored January 19, 2011
43  TODO
@@ -186,6 +186,9 @@ An incomplete list of things TODO, in no particular order.
186 186
   default to using hemp_element_literal() as a base class, so will need
187 187
   to explicitly clear/reset the parse_fixed() method if they don't already..
188 188
 
  189
+* Fix tokeniser(s) (json is broken, probably others) so that it accepts
  190
+  underscores in unquoted words (hash keys).
  191
+
189 192
 
190 193
 Operators
191 194
 ---------
@@ -308,4 +311,42 @@ list_iter
308 311
 source_vop
309 312
 source_bop
310 313
 view_f
311  
-hemp_view_f
  314
+hemp_view_f
  315
+
  316
+
  317
+"config" branch
  318
+---------------
  319
+
  320
+Working on configuration from a json file.  Define default document 
  321
+configuration (added to Hemp).  Document providers also define their
  322
+own configs, with a parent on the Hemp config.  Then each document gets
  323
+its own config with a parent to the provider's config.
  324
+
  325
+There will be occasions when we want to fetch all values in a config chain.
  326
+e.g. when adding features, we should find all features defines.  Add 
  327
+functions to hash: fetch_all() (returns list of all values found) and 
  328
+fetch_list() (merges them all into a single list, like Badger::Class
  329
+list_vars()).
  330
+
  331
+Need to add value->items method to expand lists to items.  Consider
  332
+document_path.  Might be any of these:
  333
+
  334
+    document_path: '/path/to/docs'
  335
+    document_path: 'file:/path/to/docs'
  336
+    document_path: { type: 'file', path: '/path/to/docs' }
  337
+
  338
+Or could be a list:
  339
+
  340
+    document_path: [
  341
+        '/path/to/docs',
  342
+        { ... },
  343
+    ]
  344
+
  345
+Furthermore we can have chained config hashes.  So the fetch_list() function
  346
+must merge the values it finds into a single list.  However, it's not 
  347
+sufficient to simply test if the value isa list or text, because we also need
  348
+to support extensible data types (e.g. Perl scalar/list/object, Python, etc).
  349
+So the function calls the item->items() method against each item it finds.
  350
+This is like item->values(), except that the existing list object returns a
  351
+scalar reference to itself so that lists don't auto-collapse.  It'll also
  352
+be required for the '@' expansion sigil.
8  include/hemp/defines.h
@@ -81,6 +81,7 @@
81 81
 #define HEMP_CONFIG_MODDIR  "hemp.module_dir"
82 82
 #define HEMP_CONFIG_MODEXT  "hemp.module_ext"
83 83
 #define HEMP_CONFIG_MODPATH "hemp.module_path"
  84
+#define HEMP_CONFIG_DOCPATH "document_path"
84 85
 
85 86
 
86 87
 /* dummy arguments(s) as a fallback for generating error messages */
@@ -138,5 +139,12 @@
138 139
 #define HEMP_BE_EOF         0x80000  /* special marker for end of file/text  */
139 140
 
140 141
 
  142
+/*
  143
+ * Various runtime flags.
  144
+ */
  145
+#define HEMP_OPT_DEBUG      0x0001
  146
+#define HEMP_OPT_VERBOSE    0x0002
  147
+
  148
+
141 149
 #endif /* HEMP_DEFINES_H */
142 150
 
1  include/hemp/types.h
@@ -101,6 +101,7 @@ typedef struct hemp_viewer      * HempViewer;
101 101
 struct hemp {
102 102
     HempGlobal      global;             /* pointer to global data           */
103 103
     HempFactory     factory;            /* new meta-factory                 */
  104
+    HempFlags       flags;              /* runtime options                  */
104 105
 
105 106
     HempCache       cache;              /* cache for compiled documents     */
106 107
     HempHash        config;             /* configuration items              */
2  library/element/bracket.c
@@ -203,7 +203,7 @@ HEMP_ELEMENT(hemp_element_hash) {
203 203
 
204 204
 
205 205
 HEMP_PREFIX(hemp_element_hash_prefix) {
206  
-    hemp_debug_msg("hemp_element_hash_prefix()  precedence: %d  force: %s\n", precedence, force ? "true" : "false");
  206
+    hemp_debug_call("hemp_element_hash_prefix()  precedence: %d  force: %s\n", precedence, force ? "true" : "false");
207 207
 
208 208
 //  HEMP_PREFIX_PRECEDENCE;
209 209
 
3  library/grammar.c
@@ -225,7 +225,8 @@ hemp_grammar_scanner(
225 225
         else if (isalpha(*src)) {
226 226
 bareword:
227 227
             /* word */
228  
-            hemp_scan_while(src, isalnum);
  228
+            hemp_scan_ident(src);
  229
+
229 230
             // TODO: check for ':' following after, e.g. file:/blah/blah
230 231
             hemp_document_scanned_to(
231 232
                 document, HempElementWord, src
16  library/hemp.c
@@ -421,8 +421,8 @@ hemp_context(
421 421
 
422 422
 void
423 423
 hemp_configure(
424  
-    Hemp   hemp,
425  
-    HempValue  config
  424
+    Hemp        hemp,
  425
+    HempValue   config
426 426
 ) {
427 427
     /* ask the config value to yield pairs (x => y) into the config hash */
428 428
     hemp_call(config, pairs, hemp->context, hemp_hash_val(hemp->config));
@@ -431,10 +431,10 @@ hemp_configure(
431 431
 
432 432
 void
433 433
 hemp_configure_from(
434  
-    Hemp   hemp,
435  
-    HempString dialect,
436  
-    HempString scheme,
437  
-    HempString source
  434
+    Hemp        hemp,
  435
+    HempString  dialect,
  436
+    HempString  scheme,
  437
+    HempString  source
438 438
 ) {
439 439
     HempDocument document = hemp_document(
440 440
         hemp, dialect, scheme, source
@@ -451,8 +451,8 @@ hemp_configure_from(
451 451
 
452 452
 HempString
453 453
 hemp_config_get_string(
454  
-    Hemp   hemp,
455  
-    HempString name
  454
+    Hemp        hemp,
  455
+    HempString  name
456 456
 ) {
457 457
     HempValue  value  = hemp_config_get(hemp, name);
458 458
     HempString string = NULL;
57  programs/hemp.c
@@ -19,9 +19,9 @@ void        hemp_warn(char *format, ...);
19 19
 void        hemp_error_report(Hemp);
20 20
 void        hemp_getopt(Hemp hemp, int argc, char **argv);
21 21
 void        hemp_interactive(Hemp hemp);
22  
-HempString hemp_prompt_init();
  22
+HempString  hemp_prompt_init();
23 23
 void        hemp_prompt_free();
24  
-HempString hemp_input_read(HempString prompt);
  24
+HempString  hemp_input_read(HempString prompt);
25 25
 void        hemp_input_free();
26 26
 char **     hemp_completion(const char *, int, int);
27 27
 char *      hemp_command_generator(const char *, int);
@@ -77,11 +77,15 @@ hemp_command *hemp_command_lookup(HempString name);
77 77
 
78 78
 
79 79
 
80  
-#define hemp_nl()                           \
  80
+#define hemp_nl()                               \
81 81
     fprintf(stderr, "\n");
82 82
 
83  
-#define hemp_verbose(hemp, format, ...)     \
84  
-    if (hemp->verbose) hemp_say(format, ##__VA_ARGS__)
  83
+#define hemp_verbose(hemp)                      \
  84
+    (hemp_has_flag(hemp, HEMP_OPT_VERBOSE))
  85
+
  86
+#define hemp_verbose_msg(hemp, format, ...)     \
  87
+    if (hemp_verbose(hemp))                     \
  88
+        hemp_say(format, ##__VA_ARGS__)
85 89
 
86 90
 
87 91
 
@@ -95,10 +99,10 @@ int main(
95 99
     char **argv, 
96 100
     char **env
97 101
 ) {
98  
-    Hemp       hemp = hemp_new();
99  
-    HempString     filename;
100  
-    HempDocument   document;
101  
-    HempText       input, output;
  102
+    Hemp            hemp = hemp_new();
  103
+    HempString      filename;
  104
+    HempDocument    document;
  105
+    HempText        input, output;
102 106
     int             result = 0;
103 107
     
104 108
     hemp_language(hemp, "tt3");
@@ -108,7 +112,7 @@ int main(
108 112
     if (! be_quiet)
109 113
         hemp_banner();
110 114
     
111  
-    if (hemp->verbose)
  115
+    if (hemp_verbose(hemp))
112 116
         hemp_info(hemp);
113 117
 
114 118
     if (execute) {
@@ -128,7 +132,7 @@ int main(
128 132
                 hemp_text_append_string(input, filename);
129 133
                 hemp_text_append_string(input, " ");
130 134
             }
131  
-            // hemp_verbose(hemp, "loaded text: %s", input->string);
  135
+            hemp_verbose_msg(hemp, "loaded text: %s", input->string);
132 136
             document = hemp_document(
133 137
                 hemp, HEMP_TT3, HEMP_TEXT, input->string
134 138
             );
@@ -149,7 +153,7 @@ int main(
149 153
         else {
150 154
             while (optind < argc) {
151 155
                 filename = argv[optind++];
152  
-                hemp_verbose(hemp, "loading file: %s", filename);
  156
+                hemp_verbose_msg(hemp, "loading file: %s", filename);
153 157
 
154 158
                 document = hemp_document(hemp, HEMP_TT3, HEMP_FILE, filename);
155 159
                 if (! document)
@@ -273,6 +277,7 @@ void hemp_info(
273 277
     Hemp hemp
274 278
 ) {
275 279
     HempString dir = hemp_config_get_string(hemp, HEMP_CONFIG_DIR);
  280
+    HempValue  doc = hemp_config_get(hemp, HEMP_CONFIG_DOCPATH);
276 281
     
277 282
     if (! dir)
278 283
         dir = HEMP_DIR;
@@ -284,6 +289,28 @@ void hemp_info(
284 289
         dir,
285 290
         HEMP_ANSI_RESET
286 291
     );
  292
+
  293
+    if (hemp_is_found(doc)) {
  294
+        if (hemp_is_list(doc)) {
  295
+            hemp_debug_msg("found document_path list\n");
  296
+        }
  297
+        else {
  298
+            hemp_debug_msg("found document_path, not a list: %s\n", hemp_type_name(doc));
  299
+        }
  300
+    }
  301
+    else {
  302
+        hemp_debug_msg("document_path not found\n");
  303
+    }
  304
+    
  305
+    HempText text = hemp_hash_dump(hemp->config);
  306
+    fprintf(
  307
+        stderr, "%sconfig: %s%s%s\n",
  308
+        HEMP_ANSI_YELLOW,
  309
+        HEMP_ANSI_CYAN,
  310
+        text->string,
  311
+        HEMP_ANSI_RESET
  312
+    );
  313
+    hemp_text_free(text);
287 314
 }
288 315
 
289 316
 
@@ -468,7 +495,7 @@ hemp_cmd_expr(
468 495
     output   = NULL;
469 496
 
470 497
     HEMP_TRY;
471  
-        // hemp_verbose(hemp, "loaded text: %s", input->string);
  498
+        hemp_verbose_msg(hemp, "loaded text: %s", input->string);
472 499
         hemplate = hemp_document(
473 500
             hemp, HEMP_TT3, HEMP_TEXT, input->string
474 501
         );
@@ -619,11 +646,11 @@ hemp_getopt(
619 646
                 break;
620 647
 
621 648
             case 'v':
622  
-                hemp->verbose = HEMP_TRUE;
  649
+                hemp_set_flag(hemp, HEMP_OPT_VERBOSE);
623 650
                 break;
624 651
 
625 652
             case 'd':
626  
-                hemp->debug = HEMP_TRUE;
  653
+                hemp_set_flag(hemp, HEMP_OPT_DEBUG);
627 654
                 break;
628 655
 
629 656
             case 'e':
5  tests/core/parser.c
@@ -22,7 +22,10 @@ void test_punctuation() {
22 22
     HempFragments fragments = hemp_fragments_new(NULL, 0);
23 23
     ok( fragments, "created fragments" );
24 24
 
25  
-    HempElement space, comma, semicolon, terminator;
  25
+    HempElement space      = NULL, 
  26
+                comma      = NULL, 
  27
+                semicolon  = NULL, 
  28
+                terminator = NULL;
26 29
     
27 30
     HEMP_TRY;
28 31
         space = hemp_element(hemp, "hemp.space", " ", NULL);

0 notes on commit 1d0397c

Please sign in to comment.
Something went wrong with that request. Please try again.