Permalink
Browse files

Got basic configuration for document_path working

  • Loading branch information...
1 parent 4ad84b2 commit 1d0397ce55a8a24dda257864bcdfa79e99cdf8cb @abw committed Jan 19, 2011
Showing with 108 additions and 27 deletions.
  1. +42 −1 TODO
  2. +8 −0 include/hemp/defines.h
  3. +1 −0 include/hemp/types.h
  4. +1 −1 library/element/bracket.c
  5. +2 −1 library/grammar.c
  6. +8 −8 library/hemp.c
  7. +42 −15 programs/hemp.c
  8. +4 −1 tests/core/parser.c
View
43 TODO
@@ -186,6 +186,9 @@ An incomplete list of things TODO, in no particular order.
default to using hemp_element_literal() as a base class, so will need
to explicitly clear/reset the parse_fixed() method if they don't already..
+* Fix tokeniser(s) (json is broken, probably others) so that it accepts
+ underscores in unquoted words (hash keys).
+
Operators
---------
@@ -308,4 +311,42 @@ list_iter
source_vop
source_bop
view_f
-hemp_view_f
+hemp_view_f
+
+
+"config" branch
+---------------
+
+Working on configuration from a json file. Define default document
+configuration (added to Hemp). Document providers also define their
+own configs, with a parent on the Hemp config. Then each document gets
+its own config with a parent to the provider's config.
+
+There will be occasions when we want to fetch all values in a config chain.
+e.g. when adding features, we should find all features defines. Add
+functions to hash: fetch_all() (returns list of all values found) and
+fetch_list() (merges them all into a single list, like Badger::Class
+list_vars()).
+
+Need to add value->items method to expand lists to items. Consider
+document_path. Might be any of these:
+
+ document_path: '/path/to/docs'
+ document_path: 'file:/path/to/docs'
+ document_path: { type: 'file', path: '/path/to/docs' }
+
+Or could be a list:
+
+ document_path: [
+ '/path/to/docs',
+ { ... },
+ ]
+
+Furthermore we can have chained config hashes. So the fetch_list() function
+must merge the values it finds into a single list. However, it's not
+sufficient to simply test if the value isa list or text, because we also need
+to support extensible data types (e.g. Perl scalar/list/object, Python, etc).
+So the function calls the item->items() method against each item it finds.
+This is like item->values(), except that the existing list object returns a
+scalar reference to itself so that lists don't auto-collapse. It'll also
+be required for the '@' expansion sigil.
View
8 include/hemp/defines.h
@@ -81,6 +81,7 @@
#define HEMP_CONFIG_MODDIR "hemp.module_dir"
#define HEMP_CONFIG_MODEXT "hemp.module_ext"
#define HEMP_CONFIG_MODPATH "hemp.module_path"
+#define HEMP_CONFIG_DOCPATH "document_path"
/* dummy arguments(s) as a fallback for generating error messages */
@@ -138,5 +139,12 @@
#define HEMP_BE_EOF 0x80000 /* special marker for end of file/text */
+/*
+ * Various runtime flags.
+ */
+#define HEMP_OPT_DEBUG 0x0001
+#define HEMP_OPT_VERBOSE 0x0002
+
+
#endif /* HEMP_DEFINES_H */
View
1 include/hemp/types.h
@@ -101,6 +101,7 @@ typedef struct hemp_viewer * HempViewer;
struct hemp {
HempGlobal global; /* pointer to global data */
HempFactory factory; /* new meta-factory */
+ HempFlags flags; /* runtime options */
HempCache cache; /* cache for compiled documents */
HempHash config; /* configuration items */
View
2 library/element/bracket.c
@@ -203,7 +203,7 @@ HEMP_ELEMENT(hemp_element_hash) {
HEMP_PREFIX(hemp_element_hash_prefix) {
- hemp_debug_msg("hemp_element_hash_prefix() precedence: %d force: %s\n", precedence, force ? "true" : "false");
+ hemp_debug_call("hemp_element_hash_prefix() precedence: %d force: %s\n", precedence, force ? "true" : "false");
// HEMP_PREFIX_PRECEDENCE;
View
3 library/grammar.c
@@ -225,7 +225,8 @@ hemp_grammar_scanner(
else if (isalpha(*src)) {
bareword:
/* word */
- hemp_scan_while(src, isalnum);
+ hemp_scan_ident(src);
+
// TODO: check for ':' following after, e.g. file:/blah/blah
hemp_document_scanned_to(
document, HempElementWord, src
View
16 library/hemp.c
@@ -421,8 +421,8 @@ hemp_context(
void
hemp_configure(
- Hemp hemp,
- HempValue config
+ Hemp hemp,
+ HempValue config
) {
/* ask the config value to yield pairs (x => y) into the config hash */
hemp_call(config, pairs, hemp->context, hemp_hash_val(hemp->config));
@@ -431,10 +431,10 @@ hemp_configure(
void
hemp_configure_from(
- Hemp hemp,
- HempString dialect,
- HempString scheme,
- HempString source
+ Hemp hemp,
+ HempString dialect,
+ HempString scheme,
+ HempString source
) {
HempDocument document = hemp_document(
hemp, dialect, scheme, source
@@ -451,8 +451,8 @@ hemp_configure_from(
HempString
hemp_config_get_string(
- Hemp hemp,
- HempString name
+ Hemp hemp,
+ HempString name
) {
HempValue value = hemp_config_get(hemp, name);
HempString string = NULL;
View
57 programs/hemp.c
@@ -19,9 +19,9 @@ void hemp_warn(char *format, ...);
void hemp_error_report(Hemp);
void hemp_getopt(Hemp hemp, int argc, char **argv);
void hemp_interactive(Hemp hemp);
-HempString hemp_prompt_init();
+HempString hemp_prompt_init();
void hemp_prompt_free();
-HempString hemp_input_read(HempString prompt);
+HempString hemp_input_read(HempString prompt);
void hemp_input_free();
char ** hemp_completion(const char *, int, int);
char * hemp_command_generator(const char *, int);
@@ -77,11 +77,15 @@ hemp_command *hemp_command_lookup(HempString name);
-#define hemp_nl() \
+#define hemp_nl() \
fprintf(stderr, "\n");
-#define hemp_verbose(hemp, format, ...) \
- if (hemp->verbose) hemp_say(format, ##__VA_ARGS__)
+#define hemp_verbose(hemp) \
+ (hemp_has_flag(hemp, HEMP_OPT_VERBOSE))
+
+#define hemp_verbose_msg(hemp, format, ...) \
+ if (hemp_verbose(hemp)) \
+ hemp_say(format, ##__VA_ARGS__)
@@ -95,10 +99,10 @@ int main(
char **argv,
char **env
) {
- Hemp hemp = hemp_new();
- HempString filename;
- HempDocument document;
- HempText input, output;
+ Hemp hemp = hemp_new();
+ HempString filename;
+ HempDocument document;
+ HempText input, output;
int result = 0;
hemp_language(hemp, "tt3");
@@ -108,7 +112,7 @@ int main(
if (! be_quiet)
hemp_banner();
- if (hemp->verbose)
+ if (hemp_verbose(hemp))
hemp_info(hemp);
if (execute) {
@@ -128,7 +132,7 @@ int main(
hemp_text_append_string(input, filename);
hemp_text_append_string(input, " ");
}
- // hemp_verbose(hemp, "loaded text: %s", input->string);
+ hemp_verbose_msg(hemp, "loaded text: %s", input->string);
document = hemp_document(
hemp, HEMP_TT3, HEMP_TEXT, input->string
);
@@ -149,7 +153,7 @@ int main(
else {
while (optind < argc) {
filename = argv[optind++];
- hemp_verbose(hemp, "loading file: %s", filename);
+ hemp_verbose_msg(hemp, "loading file: %s", filename);
document = hemp_document(hemp, HEMP_TT3, HEMP_FILE, filename);
if (! document)
@@ -273,6 +277,7 @@ void hemp_info(
Hemp hemp
) {
HempString dir = hemp_config_get_string(hemp, HEMP_CONFIG_DIR);
+ HempValue doc = hemp_config_get(hemp, HEMP_CONFIG_DOCPATH);
if (! dir)
dir = HEMP_DIR;
@@ -284,6 +289,28 @@ void hemp_info(
dir,
HEMP_ANSI_RESET
);
+
+ if (hemp_is_found(doc)) {
+ if (hemp_is_list(doc)) {
+ hemp_debug_msg("found document_path list\n");
+ }
+ else {
+ hemp_debug_msg("found document_path, not a list: %s\n", hemp_type_name(doc));
+ }
+ }
+ else {
+ hemp_debug_msg("document_path not found\n");
+ }
+
+ HempText text = hemp_hash_dump(hemp->config);
+ fprintf(
+ stderr, "%sconfig: %s%s%s\n",
+ HEMP_ANSI_YELLOW,
+ HEMP_ANSI_CYAN,
+ text->string,
+ HEMP_ANSI_RESET
+ );
+ hemp_text_free(text);
}
@@ -468,7 +495,7 @@ hemp_cmd_expr(
output = NULL;
HEMP_TRY;
- // hemp_verbose(hemp, "loaded text: %s", input->string);
+ hemp_verbose_msg(hemp, "loaded text: %s", input->string);
hemplate = hemp_document(
hemp, HEMP_TT3, HEMP_TEXT, input->string
);
@@ -619,11 +646,11 @@ hemp_getopt(
break;
case 'v':
- hemp->verbose = HEMP_TRUE;
+ hemp_set_flag(hemp, HEMP_OPT_VERBOSE);
break;
case 'd':
- hemp->debug = HEMP_TRUE;
+ hemp_set_flag(hemp, HEMP_OPT_DEBUG);
break;
case 'e':
View
5 tests/core/parser.c
@@ -22,7 +22,10 @@ void test_punctuation() {
HempFragments fragments = hemp_fragments_new(NULL, 0);
ok( fragments, "created fragments" );
- HempElement space, comma, semicolon, terminator;
+ HempElement space = NULL,
+ comma = NULL,
+ semicolon = NULL,
+ terminator = NULL;
HEMP_TRY;
space = hemp_element(hemp, "hemp.space", " ", NULL);

0 comments on commit 1d0397c

Please sign in to comment.