Add #i"pathname" syntax for reading values from modular input files.
This commit is contained in:
parent
ea9b1734fd
commit
6254044280
20
reader.c
20
reader.c
|
|
@ -34,6 +34,8 @@ static value_t read_weak_box(reader_state_t *state);
|
|||
static value_t read_definition(reader_state_t *state);
|
||||
static value_t read_placeholder(reader_state_t *state);
|
||||
|
||||
static value_t read_indirect(value_t path);
|
||||
|
||||
static void next_char(reader_state_t *state);
|
||||
static void skip_whitespace(reader_state_t *state);
|
||||
|
||||
|
|
@ -155,6 +157,10 @@ static value_t read_special(reader_state_t *state)
|
|||
return read_definition(state);
|
||||
case '=':
|
||||
return read_placeholder(state);
|
||||
case 'I':
|
||||
case 'i':
|
||||
next_char(state);
|
||||
return read_indirect(read_string(state));
|
||||
default:
|
||||
release_assert(NOTREACHED("Invalid character in special value."));
|
||||
return UNDEFINED;
|
||||
|
|
@ -432,6 +438,7 @@ static value_t read_string(reader_state_t *state)
|
|||
value_t value;
|
||||
|
||||
release_assert(buffer != NULL);
|
||||
release_assert(state->ch == '"');
|
||||
|
||||
next_char(state);
|
||||
|
||||
|
|
@ -666,6 +673,19 @@ static value_t read_placeholder(reader_state_t *state)
|
|||
}
|
||||
}
|
||||
|
||||
static value_t read_indirect(value_t path)
|
||||
{
|
||||
char *name = value_to_string(path);
|
||||
FILE *f = fopen(name, "r");
|
||||
value_t v;
|
||||
free(name);
|
||||
|
||||
release_assert(f != NULL);
|
||||
v = read_value(f);
|
||||
fclose(f);
|
||||
return v;
|
||||
}
|
||||
|
||||
static bool is_placeholder(reader_state_t *state, value_t value)
|
||||
{
|
||||
for (value_t item = state->ref_alist.value; !is_nil(item); item = _CDDR(item))
|
||||
|
|
|
|||
12
rosella.c
12
rosella.c
|
|
@ -207,15 +207,9 @@ static void test_reader(void)
|
|||
fflush(stdout);
|
||||
|
||||
v = read_value(stdin);
|
||||
if (is_struct(v) && _get_struct(v)->type == lookup_builtin(BI_LAMBDA))
|
||||
{
|
||||
print_value(run_interpreter(v, NIL));
|
||||
}
|
||||
else
|
||||
{
|
||||
print_value(v);
|
||||
}
|
||||
nl(); nl();
|
||||
|
||||
print_value(v); nl();
|
||||
nl();
|
||||
} while (v != NIL);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue