ed8175 | 1999-12-11 | Martin Stjernholm | |
|
950285 | 2000-02-15 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d8769c | 2000-02-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | | #ifdef OBJ_COUNT_DEBUG
# define DECLARE_CNT(count) static int count = ++all_constants()->_obj_count
# define PAREN_CNT(count) ("(" + (count) + ")")
# define COMMA_CNT(count) ("," + (count))
#else
# define DECLARE_CNT(count)
# define PAREN_CNT(count) ""
# define COMMA_CNT(count) ""
#endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | class Tag
{
|
cece9e | 2000-01-11 | Martin Stjernholm | | constant is_RXML_Tag = 1;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
f58572 | 2000-01-18 | Martin Stjernholm | | int flags;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
710b48 | 2000-02-07 | Martin Stjernholm | | mapping(string:Type) req_arg_types = ([]);
mapping(string:Type) opt_arg_types = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
3187d8 | 2000-01-28 | Martin Stjernholm | | Type def_arg_type = t_text (PEnt);
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
3187d8 | 2000-01-28 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | Type content_type = t_same (PXml);
|
590b3c | 2000-02-05 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
590b3c | 2000-02-05 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
590b3c | 2000-02-05 | Martin Stjernholm | | array(Type) result_types = ({t_xml, t_html, t_text});
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
cf3c90 | 2000-02-04 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
cf3c90 | 2000-02-04 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
cf3c90 | 2000-02-04 | Martin Stjernholm | | inline object `() (mapping(string:mixed) args, void|mixed content)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
cf3c90 | 2000-02-04 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
56532d | 1999-12-19 | Martin Stjernholm | | Tag this = this_object();
|
cf3c90 | 2000-02-04 | Martin Stjernholm | | object frame = ([function(:object)] this->Frame)();
|
ed8175 | 1999-12-11 | Martin Stjernholm | | frame->tag = this;
frame->flags = flags;
frame->args = args;
if (!zero_type (content)) frame->content = content;
return frame;
}
|
c159ec | 2000-02-04 | Martin Stjernholm | | int eval_args (mapping(string:mixed) args, void|int dont_throw, void|Context ctx)
{
|
710b48 | 2000-02-07 | Martin Stjernholm | | mapping(string:Type) atypes = args & req_arg_types;
if (sizeof (atypes) < sizeof (req_arg_types))
if (dont_throw) return 0;
else {
array(string) missing = sort (indices (req_arg_types - atypes));
|
5ed013 | 2000-02-13 | Martin Stjernholm | | parse_error ("Required " +
(sizeof (missing) > 1 ?
"arguments " + String.implode_nicely (missing) + " are" :
"argument " + missing[0] + " is") + " missing.\n");
|
710b48 | 2000-02-07 | Martin Stjernholm | | }
atypes += args & opt_arg_types;
|
c159ec | 2000-02-04 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
710b48 | 2000-02-07 | Martin Stjernholm | | if (mixed err = catch {
|
c159ec | 2000-02-04 | Martin Stjernholm | | #endif
|
710b48 | 2000-02-07 | Martin Stjernholm | | foreach (indices (atypes), string arg)
args[arg] = atypes[arg]->eval (args[arg], ctx);
|
c159ec | 2000-02-04 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
710b48 | 2000-02-07 | Martin Stjernholm | | }) {
if (objectp (err) && ([object] err)->thrown_at_unwind)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Can't save parser state when evaluating arguments.\n");
throw_fatal (err);
|
c159ec | 2000-02-04 | Martin Stjernholm | | }
|
710b48 | 2000-02-07 | Martin Stjernholm | | #endif
|
c159ec | 2000-02-04 | Martin Stjernholm | | return 1;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
01e43b | 2000-01-14 | Martin Stjernholm | | array _handle_tag (TagSetParser parser, mapping(string:string) args,
|
c6245b | 1999-12-31 | Martin Stjernholm | | void|string content)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
56532d | 1999-12-19 | Martin Stjernholm | | Context ctx = parser->context;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
9d80e8 | 2000-02-11 | Martin Stjernholm | |
if (string splice_args = args["::"]) {
splice_args = t_text (PEnt)->eval (splice_args, ctx, 0, parser, 1);
m_delete (args, "::");
args += parser->parse_tag_args (splice_args);
}
|
f99720 | 2000-01-18 | Martin Stjernholm | | object frame;
|
56532d | 1999-12-19 | Martin Stjernholm | | if (mapping(string:mixed)|mapping(object:array) ustate = ctx->unwind_state)
|
26ff09 | 2000-01-21 | Martin Stjernholm | | if (ustate[parser]) {
frame = [object] ustate[parser][0];
m_delete (ustate, parser);
if (!sizeof (ustate)) ctx->unwind_state = 0;
}
|
cf3c90 | 2000-02-04 | Martin Stjernholm | | else frame = `() (args, Void);
else frame = `() (args, Void);
|
56532d | 1999-12-19 | Martin Stjernholm | |
mixed err = catch {
frame->_eval (parser, args, content);
|
590b3c | 2000-02-05 | Martin Stjernholm | | mixed res;
if ((res = frame->result) == Void) return ({});
if (frame->result_type->quoting_scheme != parser->type->quoting_scheme)
res = parser->type->quote (res);
return ({res});
|
56532d | 1999-12-19 | Martin Stjernholm | | };
if (objectp (err) && ([object] err)->thrown_at_unwind) {
mapping(string:mixed)|mapping(object:array) ustate = ctx->unwind_state;
if (!ustate) ustate = ctx->unwind_state = ([]);
#ifdef DEBUG
if (err != frame)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Internal error: Unexpected unwind object catched.\n");
|
56532d | 1999-12-19 | Martin Stjernholm | | if (ustate[parser])
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Internal error: Clobbering unwind state for parser.\n");
|
56532d | 1999-12-19 | Martin Stjernholm | | #endif
ustate[parser] = ({err});
|
8cb24d | 2000-02-13 | Martin Stjernholm | | throw (err = parser);
|
56532d | 1999-12-19 | Martin Stjernholm | | }
|
8cb24d | 2000-02-13 | Martin Stjernholm | | else throw_fatal (err);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
26ff09 | 2000-01-21 | Martin Stjernholm | | DECLARE_CNT (__count);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | string _sprintf()
{
|
26ff09 | 2000-01-21 | Martin Stjernholm | | return "RXML.Tag(" + [string] this_object()->name + COMMA_CNT (__count) + ")";
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
}
class TagSet
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
2bd21a | 2000-01-05 | Martin Stjernholm | | string name;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | string prefix;
|
f99720 | 2000-01-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
f99720 | 2000-01-18 | Martin Stjernholm | | int prefix_req;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
array(TagSet) imported = ({});
|
660cb5 | 2000-01-12 | Martin Stjernholm | | function(Context:void) prepare_context;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | int generation = 1;
|
56ffee | 2000-01-12 | Martin Stjernholm | | #define LOW_TAG_TYPE \
string|array| \
function(:int(1..1)|string|array)| \
function(object,mapping(string:string):int(1..1)|string|array)
#define LOW_CONTAINER_TYPE \
string|array| \
function(:int(1..1)|string|array)| \
function(object,mapping(string:string),string:int(1..1)|string|array)
#define LOW_ENTITY_TYPE \
string|array| \
function(:int(1..1)|string|array)| \
function(object:int(1..1)|string|array)
mapping(string:LOW_TAG_TYPE) low_tags;
mapping(string:LOW_CONTAINER_TYPE) low_containers;
mapping(string:LOW_ENTITY_TYPE) low_entities;
|
da54bd | 2000-01-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | | static void create (string _name, void|array(Tag) _tags)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
{
|
2bd21a | 2000-01-05 | Martin Stjernholm | | name = _name;
|
c159ec | 2000-02-04 | Martin Stjernholm | | if (_tags)
foreach (_tags, Tag tag)
if (tag->plugin_name) tags[tag->name + "#" + tag->plugin_name] = tag;
else tags[tag->name] = tag;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
void add_tag (Tag tag)
{
|
c159ec | 2000-02-04 | Martin Stjernholm | | if (tag->plugin_name) tags[tag->name + "#" + tag->plugin_name] = tag;
else tags[tag->name] = tag;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | changed();
}
void add_tags (array(Tag) _tags)
{
|
c159ec | 2000-02-04 | Martin Stjernholm | | foreach (_tags, Tag tag)
if (tag->plugin_name) tags[tag->name + "#" + tag->plugin_name] = tag;
else tags[tag->name] = tag;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | changed();
}
void remove_tag (string|Tag tag)
{
if (stringp (tag))
m_delete (tags, tag);
|
c159ec | 2000-02-04 | Martin Stjernholm | | else
for (string n; !zero_type (n = search (tags, [object(Tag)] tag));)
m_delete (tags, n);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | changed();
}
|
56ffee | 2000-01-12 | Martin Stjernholm | | local Tag|array(LOW_TAG_TYPE|LOW_CONTAINER_TYPE) get_local_tag (string name)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
56ffee | 2000-01-12 | Martin Stjernholm | | if (Tag tag = tags[name]) return tag;
else if (LOW_CONTAINER_TYPE cdef = low_containers && low_containers[name])
return ({0, cdef});
else if (LOW_TAG_TYPE tdef = low_tags && low_tags[name])
return ({tdef, 0});
else return 0;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
array(Tag) get_local_tags()
|
56ffee | 2000-01-12 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
return values (tags);
}
|
56ffee | 2000-01-12 | Martin Stjernholm | | Tag|array(LOW_TAG_TYPE|LOW_CONTAINER_TYPE) get_tag (string name)
|
2bd21a | 2000-01-05 | Martin Stjernholm | | {
|
56ffee | 2000-01-12 | Martin Stjernholm | | if (object(Tag)|array(LOW_TAG_TYPE|LOW_CONTAINER_TYPE) def = get_local_tag (name))
return def;
foreach (imported, TagSet tag_set)
if (object(Tag) tag = [object(Tag)] tag_set->get_tag (name)) return tag;
return 0;
|
da54bd | 2000-01-08 | Martin Stjernholm | | }
|
56ffee | 2000-01-12 | Martin Stjernholm | | Tag|array(LOW_TAG_TYPE|LOW_CONTAINER_TYPE) get_overridden_tag (
Tag|LOW_TAG_TYPE|LOW_CONTAINER_TYPE tagdef, void|string name)
|
da54bd | 2000-01-08 | Martin Stjernholm | | {
|
56ffee | 2000-01-12 | Martin Stjernholm | | if (objectp (tagdef) && ([object] tagdef)->is_RXML_Tag)
name = [string] ([object] tagdef)->name;
#ifdef MODULE_DEBUG
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (!name) fatal_error ("Need tag name.\n");
|
56ffee | 2000-01-12 | Martin Stjernholm | | #endif
if (tags[name] == tagdef ||
(low_containers && low_containers[name] == tagdef) ||
(low_tags && low_tags[name] == tagdef)) {
|
da54bd | 2000-01-08 | Martin Stjernholm | | foreach (imported, TagSet tag_set)
|
56ffee | 2000-01-12 | Martin Stjernholm | | if (object(Tag)|array(LOW_TAG_TYPE|LOW_CONTAINER_TYPE) tagdef =
tag_set->get_tag (name)) return tagdef;
|
da54bd | 2000-01-08 | Martin Stjernholm | | }
else {
int found = 0;
foreach (imported, TagSet tag_set)
|
56ffee | 2000-01-12 | Martin Stjernholm | | if (object(Tag)|array(LOW_TAG_TYPE|LOW_CONTAINER_TYPE) subtag =
tag_set->get_tag (name))
|
da54bd | 2000-01-08 | Martin Stjernholm | | if (found) return subtag;
|
56ffee | 2000-01-12 | Martin Stjernholm | | else if (arrayp (subtag) ?
subtag[0] == tagdef || subtag[1] == tagdef :
subtag == tagdef)
if ((subtag = tag_set->get_overridden_tag (tagdef, name)))
return subtag;
else found = 1;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | }
|
da54bd | 2000-01-08 | Martin Stjernholm | | return 0;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | }
|
56ffee | 2000-01-12 | Martin Stjernholm | | array(Tag|array(LOW_TAG_TYPE|LOW_CONTAINER_TYPE)) get_overridden_tags (string name)
{
if (object(Tag)|array(LOW_TAG_TYPE|LOW_CONTAINER_TYPE) def = get_local_tag (name))
|
3b41cb | 2000-01-21 | Martin Nilsson | | return ({def}) + imported->get_overridden_tags (name) * ({});
else return imported->get_overridden_tags (name) * ({});
|
56ffee | 2000-01-12 | Martin Stjernholm | | }
multiset(string) get_tag_names()
{
multiset(string) res = (multiset) indices (tags);
if (low_tags) res |= (multiset) indices (low_tags);
if (low_containers) res |= (multiset) indices (low_containers);
return `| (res, @imported->get_tag_names());
}
|
c159ec | 2000-02-04 | Martin Stjernholm | | mapping(string:Tag) get_plugins (string name)
{
mapping(string:Tag) res;
if ((res = plugins[name])) return res;
low_get_plugins (name + "#", res = ([]));
return plugins[name] = res;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | mixed `->= (string var, mixed val)
{
switch (var) {
case "imported":
|
49897a | 2000-02-13 | Martin Stjernholm | | if (!val) return val;
filter (imported, "dont_notify", changed);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | imported = [array(TagSet)] val;
imported->do_notify (changed);
break;
default:
::`->= (var, val);
}
changed();
return val;
}
mixed `[]= (string var, mixed val) {return `->= (var, val);}
Parser `() (Type top_level_type, void|RequestID id)
{
|
660cb5 | 2000-01-12 | Martin Stjernholm | | Context ctx = Context (this_object(), id);
if (!prepare_funs) prepare_funs = get_prepare_funs();
|
777ff2 | 2000-02-15 | Martin Stjernholm | | (prepare_funs -= ({0})) (ctx);
|
660cb5 | 2000-01-12 | Martin Stjernholm | | return ctx->new_parser (top_level_type);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
void changed()
{
generation++;
|
660cb5 | 2000-01-12 | Martin Stjernholm | | prepare_funs = 0;
|
301817 | 2000-02-04 | Martin Nilsson | | plugins = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | (notify_funcs -= ({0}))();
set_weak_flag (notify_funcs, 1);
}
void do_notify (function(:void) func)
{
notify_funcs |= ({func});
set_weak_flag (notify_funcs, 1);
}
void dont_notify (function(:void) func)
{
notify_funcs -= ({func});
set_weak_flag (notify_funcs, 1);
}
void destroy()
{
catch (changed());
}
|
c159ec | 2000-02-04 | Martin Stjernholm | | static mapping(string:Tag) tags = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | | static array(function(:void)) notify_funcs = ({});
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | | static array(function(Context:void)) prepare_funs;
|
660cb5 | 2000-01-12 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | | array(function(Context:void)) get_prepare_funs()
|
660cb5 | 2000-01-12 | Martin Stjernholm | | {
if (prepare_funs) return prepare_funs;
array(function(Context:void)) funs = ({});
for (int i = sizeof (imported) - 1; i >= 0; i--)
funs += imported[i]->get_prepare_funs();
if (prepare_context) funs += ({prepare_context});
return funs;
}
|
777ff2 | 2000-02-15 | Martin Stjernholm | | void call_prepare_funs (Context ctx)
{
if (!prepare_funs) prepare_funs = get_prepare_funs();
(prepare_funs -= ({0})) (ctx);
}
|
c159ec | 2000-02-04 | Martin Stjernholm | | static mapping(string:mapping(string:Tag)) plugins = ([]);
void low_get_plugins (string prefix, mapping(string:Tag) res)
{
for (int i = sizeof (imported) - 1; i >= 0; i--)
imported[i]->low_get_plugins (prefix, res);
foreach (indices (tags), string name)
if (name[..sizeof (prefix) - 1] == prefix) {
Tag tag = tags[name];
if (tag->plugin_name) res[[string] tag->plugin_name] = tag;
}
}
|
26ff09 | 2000-01-21 | Martin Stjernholm | | DECLARE_CNT (__count);
|
2bd21a | 2000-01-05 | Martin Stjernholm | | string _sprintf()
{
|
26ff09 | 2000-01-21 | Martin Stjernholm | | return name ? "RXML.TagSet(" + name + COMMA_CNT (__count) + ")" :
"RXML.TagSet" + PAREN_CNT (__count);
|
2bd21a | 2000-01-05 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | TagSet empty_tag_set;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
af06d5 | 2000-01-12 | Martin Stjernholm | | class Value
{
|
a21fcb | 2000-02-08 | Martin Nilsson | | mixed rxml_var_eval (Context ctx, string var, string scope_name, void|Type type)
|
8778dd | 2000-02-05 | Martin Stjernholm | |
|
710b48 | 2000-02-07 | Martin Stjernholm | |
|
a21fcb | 2000-02-08 | Martin Nilsson | | {
mixed val = rxml_const_eval (ctx, var, scope_name, type);
ctx->set_var(var, val, scope_name);
return val;
}
|
9d80e8 | 2000-02-11 | Martin Stjernholm | | mixed rxml_const_eval (Context ctx, string var, string scope_name, void|Type type);
|
a21fcb | 2000-02-08 | Martin Nilsson | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
string _sprintf() {return "RXML.Value";}
|
af06d5 | 2000-01-12 | Martin Stjernholm | | }
class Scope
{
|
01e43b | 2000-01-14 | Martin Stjernholm | | mixed `[] (string var, void|Context ctx, void|string scope_name)
|
5ed013 | 2000-02-13 | Martin Stjernholm | | {parse_error ("Cannot query variable" + _in_the_scope (scope_name) + ".\n");}
|
01e43b | 2000-01-14 | Martin Stjernholm | |
mixed `[]= (string var, mixed val, void|Context ctx, void|string scope_name)
|
5ed013 | 2000-02-13 | Martin Stjernholm | | {parse_error ("Cannot set variable" + _in_the_scope (scope_name) + ".\n");}
|
01e43b | 2000-01-14 | Martin Stjernholm | |
array(string) _indices (void|Context ctx, void|string scope_name)
|
5ed013 | 2000-02-13 | Martin Stjernholm | | {parse_error ("Cannot list variables" + _in_the_scope (scope_name) + ".\n");}
|
01e43b | 2000-01-14 | Martin Stjernholm | |
void m_delete (string var, void|Context ctx, void|string scope_name)
|
5ed013 | 2000-02-13 | Martin Stjernholm | | {parse_error ("Cannot delete variable" + _in_the_scope (scope_name) + ".\n");}
|
01e43b | 2000-01-14 | Martin Stjernholm | |
private string _in_the_scope (string scope_name)
{
if (scope_name)
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (scope_name != "_") return " in the scope " + scope_name;
|
01e43b | 2000-01-14 | Martin Stjernholm | | else return " in the current scope";
else return "";
}
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
string _sprintf() {return "RXML.Scope";}
|
af06d5 | 2000-01-12 | Martin Stjernholm | | }
|
01e43b | 2000-01-14 | Martin Stjernholm | | #define SCOPE_TYPE mapping(string:mixed)|object(Scope)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | class Context
|
db0417 | 2000-01-14 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
{
Frame frame;
RequestID id;
int type_check;
|
db0417 | 2000-01-14 | Martin Stjernholm | | int error_count;
|
01e43b | 2000-01-14 | Martin Stjernholm | |
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | TagSet tag_set;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | int tag_set_is_local;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
9390fe | 2000-01-23 | Martin Nilsson | | array parse_user_var (string var, void|string scope_name)
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
9390fe | 2000-01-23 | Martin Nilsson | | {
if(!var || !sizeof(var)) return ([])[0];
|
291ade | 2000-01-25 | Martin Stjernholm | | array(string) splitted=var/".";
|
9390fe | 2000-01-23 | Martin Nilsson | | if(sizeof(splitted)>2) return ([])[0];
|
b18548 | 2000-01-25 | Martin Nilsson | | if(sizeof(splitted)==2)
scope_name=splitted[0];
else
scope_name = scope_name || "_";
|
9390fe | 2000-01-23 | Martin Nilsson | | return ({ scope_name, splitted[-1] });
}
|
8778dd | 2000-02-05 | Martin Stjernholm | | local mixed get_var (string var, void|string scope_name, void|Type want_type)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8778dd | 2000-02-05 | Martin Stjernholm | |
|
710b48 | 2000-02-07 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (SCOPE_TYPE vars = scopes[scope_name || "_"]) {
|
ed8175 | 1999-12-11 | Martin Stjernholm | | mixed val;
|
570853 | 2000-01-15 | Martin Stjernholm | | if (objectp (vars)) {
|
2591bd | 2000-02-07 | Martin Stjernholm | | if (zero_type (val = ([object(Scope)] vars)->`[] (
var, this_object(), scope_name || "_")) ||
val == Void)
return ([])[0];
|
01e43b | 2000-01-14 | Martin Stjernholm | | }
|
2591bd | 2000-02-07 | Martin Stjernholm | | else
if (zero_type (val = vars[var]))
return ([])[0];
|
a21fcb | 2000-02-08 | Martin Nilsson | | if (objectp (val) && ([object] val)->rxml_var_eval) {
|
8778dd | 2000-02-05 | Martin Stjernholm | | return
zero_type (val = ([object(Value)] val)->rxml_var_eval (
this_object(), var, scope_name || "_", want_type)) ||
val == Void ? ([])[0] : val;
|
a21fcb | 2000-02-08 | Martin Nilsson | | }
|
710b48 | 2000-02-07 | Martin Stjernholm | | else
if (want_type)
return
zero_type (val = want_type->convert (val)) ||
val == Void ? ([])[0] : val;
else
return val;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
5ed013 | 2000-02-13 | Martin Stjernholm | | else if (scope_name) parse_error ("Unknown scope %O.\n", scope_name);
else parse_error ("No current scope.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
8778dd | 2000-02-05 | Martin Stjernholm | | mixed user_get_var (string var, void|string scope_name, void|Type want_type)
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
9390fe | 2000-01-23 | Martin Nilsson | | {
if(!var || !sizeof(var)) return ([])[0];
|
291ade | 2000-01-25 | Martin Stjernholm | | array(string) splitted=var/".";
|
9390fe | 2000-01-23 | Martin Nilsson | | if(sizeof(splitted)>2) return ([])[0];
|
b18548 | 2000-01-25 | Martin Nilsson | | if(sizeof(splitted)==2)
scope_name=splitted[0];
else
scope_name = scope_name || "_";
|
8778dd | 2000-02-05 | Martin Stjernholm | | return get_var(splitted[-1], scope_name, want_type);
|
9390fe | 2000-01-23 | Martin Nilsson | | }
|
291ade | 2000-01-25 | Martin Stjernholm | | local mixed set_var (string var, mixed val, void|string scope_name)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
{
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (SCOPE_TYPE vars = scopes[scope_name || "_"])
|
01e43b | 2000-01-14 | Martin Stjernholm | | if (objectp (vars))
|
3e5934 | 2000-01-18 | Martin Stjernholm | | return ([object(Scope)] vars)->`[]= (var, val, this_object(), scope_name || "_");
|
01e43b | 2000-01-14 | Martin Stjernholm | | else
return vars[var] = val;
|
5ed013 | 2000-02-13 | Martin Stjernholm | | else if (scope_name) parse_error ("Unknown scope %O.\n", scope_name);
else parse_error ("No current scope.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
9390fe | 2000-01-23 | Martin Nilsson | | mixed user_set_var (string var, mixed val, void|string scope_name)
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
9390fe | 2000-01-23 | Martin Nilsson | | {
|
291ade | 2000-01-25 | Martin Stjernholm | | if(!var || !sizeof(var)) return val;
array(string) splitted=var/".";
if(sizeof(splitted)>2) return val;
|
b18548 | 2000-01-25 | Martin Nilsson | | if(sizeof(splitted)==2)
scope_name=splitted[0];
else
scope_name = scope_name || "_";
|
9390fe | 2000-01-23 | Martin Nilsson | | return set_var(splitted[-1], val, scope_name);
}
|
291ade | 2000-01-25 | Martin Stjernholm | | local void delete_var (string var, void|string scope_name)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
{
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (SCOPE_TYPE vars = scopes[scope_name || "_"])
|
01e43b | 2000-01-14 | Martin Stjernholm | | if (objectp (vars))
|
3e5934 | 2000-01-18 | Martin Stjernholm | | ([object(Scope)] vars)->m_delete (var, this_object(), scope_name || "_");
|
01e43b | 2000-01-14 | Martin Stjernholm | | else
m_delete ([mapping(string:mixed)] vars, var);
|
5ed013 | 2000-02-13 | Martin Stjernholm | | else if (scope_name) parse_error ("Unknown scope %O.\n", scope_name);
else parse_error ("No current scope.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
291ade | 2000-01-25 | Martin Stjernholm | | void user_delete_var (string var, void|string scope_name)
|
9390fe | 2000-01-23 | Martin Nilsson | | {
|
291ade | 2000-01-25 | Martin Stjernholm | | if(!var || !sizeof(var)) return;
array(string) splitted=var/".";
if(sizeof(splitted)>2) return;
|
b18548 | 2000-01-25 | Martin Nilsson | | if(sizeof(splitted)==2)
scope_name=splitted[0];
else
scope_name = scope_name || "_";
|
291ade | 2000-01-25 | Martin Stjernholm | | delete_var(splitted[-1], scope_name);
|
9390fe | 2000-01-23 | Martin Nilsson | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | array(string) list_var (void|string scope_name)
{
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (SCOPE_TYPE vars = scopes[scope_name || "_"])
|
01e43b | 2000-01-14 | Martin Stjernholm | | if (objectp (vars))
|
3e5934 | 2000-01-18 | Martin Stjernholm | | return ([object(Scope)] vars)->_indices (this_object(), scope_name || "_");
|
01e43b | 2000-01-14 | Martin Stjernholm | | else
return indices ([mapping(string:mixed)] vars);
|
5ed013 | 2000-02-13 | Martin Stjernholm | | else if (scope_name) parse_error ("Unknown scope %O.\n", scope_name);
else parse_error ("No current scope.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
array(string) list_scopes()
{
|
3e5934 | 2000-01-18 | Martin Stjernholm | | return indices (scopes) - ({"_"});
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
af06d5 | 2000-01-12 | Martin Stjernholm | | int exist_scope (void|string scope_name)
{
|
3e5934 | 2000-01-18 | Martin Stjernholm | | return !!scopes[scope_name || "_"];
|
af06d5 | 2000-01-12 | Martin Stjernholm | | }
void add_scope (string scope_name, SCOPE_TYPE vars)
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
if (scopes[scope_name])
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (scope_name == "_") {
|
291ade | 2000-01-25 | Martin Stjernholm | | array(SCOPE_TYPE) hid;
for (Frame f = frame; f; f = f->up)
if (array(SCOPE_TYPE) h = hidden[f]) hid = h;
if (hid) hid[0] = vars;
else scopes["_"] = vars;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
else {
Frame outermost;
for (Frame f = frame; f; f = f->up)
if (f->scope_name == scope_name) outermost = f;
|
291ade | 2000-01-25 | Martin Stjernholm | | if (outermost) hidden[outermost][1] = vars;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | else scopes[scope_name] = vars;
}
else scopes[scope_name] = vars;
}
|
290c80 | 2000-01-25 | Martin Nilsson | | int extend_scope (string scope_name, SCOPE_TYPE vars)
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
290c80 | 2000-01-25 | Martin Nilsson | |
|
0273b2 | 2000-01-21 | Martin Nilsson | | {
|
291ade | 2000-01-25 | Martin Stjernholm | | if (scopes[scope_name]) {
SCOPE_TYPE oldvars;
if (scope_name == "_") {
array(SCOPE_TYPE) hid;
for (Frame f = frame; f; f = f->up)
if (array(SCOPE_TYPE) h = hidden[f]) hid = h;
if (hid) oldvars = hid[0];
else oldvars = scopes["_"];
}
else {
Frame outermost;
for (Frame f = frame; f; f = f->up)
if (f->scope_name == scope_name) outermost = f;
if (outermost) oldvars = hidden[outermost][1];
else oldvars = scopes[scope_name];
}
#ifdef DEBUG
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (!oldvars) fatal_error ("Internal error: I before e except after c.\n");
|
291ade | 2000-01-25 | Martin Stjernholm | | #endif
if (!mappingp(vars)) {
return 0;
}
foreach (indices(vars), string var)
set_var(var, vars[var], scope_name);
|
f6020c | 2000-01-23 | Martin Nilsson | | }
|
291ade | 2000-01-25 | Martin Stjernholm | | else scopes[scope_name] = vars;
|
290c80 | 2000-01-25 | Martin Nilsson | | return 1;
|
0273b2 | 2000-01-21 | Martin Nilsson | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | void remove_scope (string scope_name)
{
#ifdef MODULE_DEBUG
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (scope_name == "_") fatal_error ("Cannot remove current scope.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
Frame outermost;
for (Frame f = frame; f; f = f->up)
if (f->scope_name == scope_name) outermost = f;
if (outermost) m_delete (hidden, outermost);
else m_delete (scopes, scope_name);
}
string current_scope()
{
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (SCOPE_TYPE vars = scopes["_"]) {
|
ed8175 | 1999-12-11 | Martin Stjernholm | | string scope_name;
while (scope_name = search (scopes, vars, scope_name))
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (scope_name != "_") return scope_name;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
return 0;
}
|
af06d5 | 2000-01-12 | Martin Stjernholm | | void add_runtime_tag (Tag tag)
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
|
af06d5 | 2000-01-12 | Martin Stjernholm | | {
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | if (!new_runtime_tags) new_runtime_tags = NewRuntimeTags();
|
af06d5 | 2000-01-12 | Martin Stjernholm | | new_runtime_tags->add_tags[tag] = 1;
new_runtime_tags->remove_tags[tag] = 0;
new_runtime_tags->remove_tags[tag->name] = 0;
}
void remove_runtime_tag (string|Tag tag)
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
|
af06d5 | 2000-01-12 | Martin Stjernholm | | {
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | if (!new_runtime_tags) new_runtime_tags = NewRuntimeTags();
|
af06d5 | 2000-01-12 | Martin Stjernholm | | new_runtime_tags->remove_tags[tag] = 1;
}
|
18abb3 | 2000-02-15 | Martin Stjernholm | | multiset(Tag) get_runtime_tags()
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | {
|
18abb3 | 2000-02-15 | Martin Stjernholm | | multiset(Tag) tags = runtime_tags;
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | if (new_runtime_tags) {
|
18abb3 | 2000-02-15 | Martin Stjernholm | | tags |= new_runtime_tags->add_tags;
tags -= new_runtime_tags->remove_tags;
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | }
return tags;
}
|
01e43b | 2000-01-14 | Martin Stjernholm | | void handle_exception (mixed err, PCode|Parser evaluator)
|
c757c4 | 2000-01-08 | Martin Stjernholm | | {
|
db0417 | 2000-01-14 | Martin Stjernholm | | error_count++;
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (objectp (err) && err->is_RXML_Backtrace && err->type != "fatal") {
string msg;
for (object(PCode)|object(Parser) e = evaluator->_parent; e; e = e->_parent)
e->error_count++;
|
01e43b | 2000-01-14 | Martin Stjernholm | | if (id && id->conf)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | msg = (err->type == "run" ?
([function(Backtrace,Type:string)]
|
5ed013 | 2000-02-13 | Martin Stjernholm | | ([object] id->conf)->handle_run_error) :
|
8cb24d | 2000-02-13 | Martin Stjernholm | | ([function(Backtrace,Type:string)]
|
5ed013 | 2000-02-13 | Martin Stjernholm | | ([object] id->conf)->handle_parse_error)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | ) ([object(Backtrace)] err, evaluator->type);
|
01e43b | 2000-01-14 | Martin Stjernholm | | else {
|
c757c4 | 2000-01-08 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
01e43b | 2000-01-14 | Martin Stjernholm | | report_notice (describe_backtrace (err));
|
c757c4 | 2000-01-08 | Martin Stjernholm | | #else
|
8cb24d | 2000-02-13 | Martin Stjernholm | | report_notice (err->msg);
|
c757c4 | 2000-01-08 | Martin Stjernholm | | #endif
|
01e43b | 2000-01-14 | Martin Stjernholm | | }
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (msg)
while (evaluator) {
if (evaluator->report_error && evaluator->type->free_text &&
evaluator->report_error (msg))
break;
evaluator = evaluator->_parent;
}
|
c757c4 | 2000-01-08 | Martin Stjernholm | | }
|
8cb24d | 2000-02-13 | Martin Stjernholm | | else throw_fatal (err);
|
c757c4 | 2000-01-08 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
db0417 | 2000-01-14 | Martin Stjernholm | | string current_var;
|
c6245b | 1999-12-31 | Martin Stjernholm | | Parser new_parser (Type top_level_type)
{
#ifdef MODULE_DEBUG
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (in_use || frame) fatal_error ("Context already in use.\n");
|
c6245b | 1999-12-31 | Martin Stjernholm | | #endif
return top_level_type->get_parser (this_object());
}
|
af06d5 | 2000-01-12 | Martin Stjernholm | | mapping(string:SCOPE_TYPE) scopes = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
3e5934 | 2000-01-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | | mapping(Frame:array(SCOPE_TYPE)) hidden = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
void enter_scope (Frame frame)
{
#ifdef DEBUG
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (!frame->vars) fatal_error ("Internal error: Frame has no variables.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
|
b2d01b | 2000-02-15 | Martin Stjernholm | | if (string scope_name = [string] frame->scope_name) {
if (!hidden[frame])
|
291ade | 2000-01-25 | Martin Stjernholm | | hidden[frame] = ({scopes["_"], scopes[scope_name]});
|
b2d01b | 2000-02-15 | Martin Stjernholm | | scopes["_"] = scopes[scope_name] = [SCOPE_TYPE] frame->vars;
}
else {
if (!hidden[frame])
|
291ade | 2000-01-25 | Martin Stjernholm | | hidden[frame] = ({scopes["_"], 0});
|
b2d01b | 2000-02-15 | Martin Stjernholm | | scopes["_"] = [SCOPE_TYPE] frame->vars;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
void leave_scope (Frame frame)
{
|
291ade | 2000-01-25 | Martin Stjernholm | | if (array(SCOPE_TYPE) back = hidden[frame]) {
if (SCOPE_TYPE cur = back[0]) scopes["_"] = cur;
else m_delete (scopes, "_");
if (SCOPE_TYPE named = back[1]) {
#ifdef MODULE_DEBUG
if (!stringp (frame->scope_name))
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Scope named changed to %O during parsing.\n", frame->scope_name);
|
291ade | 2000-01-25 | Martin Stjernholm | | #endif
scopes[[string] frame->scope_name] = named;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
291ade | 2000-01-25 | Martin Stjernholm | | else m_delete (scopes, [string] frame->scope_name);
m_delete (hidden, frame);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
}
#define ENTER_SCOPE(ctx, frame) (frame->vars && ctx->enter_scope (frame))
#define LEAVE_SCOPE(ctx, frame) (frame->vars && ctx->leave_scope (frame))
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | void make_tag_set_local()
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | if (!tag_set_is_local) {
TagSet new_tag_set = TagSet (tag_set->name + " (local)");
new_tag_set->imported = ({tag_set});
tag_set = new_tag_set;
tag_set_is_local = 1;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
}
|
18abb3 | 2000-02-15 | Martin Stjernholm | | multiset(Tag) runtime_tags = (<>);
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
class NewRuntimeTags
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
c6245b | 1999-12-31 | Martin Stjernholm | | multiset(Tag) add_tags = (<>);
|
2bd21a | 2000-01-05 | Martin Stjernholm | | multiset(Tag|string) remove_tags = (<>);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | NewRuntimeTags new_runtime_tags;
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | | void create (TagSet _tag_set, void|RequestID _id)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
{
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | tag_set = _tag_set;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | id = _id;
}
|
56532d | 1999-12-19 | Martin Stjernholm | | mapping(string:mixed)|mapping(object:array) unwind_state;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
56532d | 1999-12-19 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
56532d | 1999-12-19 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | | DECLARE_CNT (__count);
string _sprintf() {return "RXML.Context" + PAREN_CNT (__count);}
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
2d2034 | 2000-02-12 | Martin Stjernholm | | #if constant (thread_create)
Thread.Thread in_use;
#else
|
ed8175 | 1999-12-11 | Martin Stjernholm | | int in_use;
#endif
|
2d2034 | 2000-02-12 | Martin Stjernholm | | #endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
8cb24d | 2000-02-13 | Martin Stjernholm | | class Backtrace
{
constant is_generic_error = 1;
constant is_RXML_Backtrace = 1;
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | string type;
|
8cb24d | 2000-02-13 | Martin Stjernholm | | string msg;
Context context;
Frame frame;
string current_var;
array backtrace;
void create (string _type, string _msg, void|Context _context)
{
type = _type;
msg = _msg;
if (context = _context || get_context()) {
frame = context->frame;
current_var = context->current_var;
}
backtrace = predef::backtrace();
backtrace = backtrace[..sizeof (backtrace) - 2];
}
string describe_rxml_backtrace (void|int no_msg)
{
string txt = no_msg ? "" : "RXML " + type + " error";
if (context) {
if (!no_msg) txt += ": " + (msg || "(no error message)\n");
txt += current_var ? " | &" + current_var + ";\n" : "";
for (Frame f = frame; f; f = f->up) {
if (f->tag) txt += " | <" + f->tag->name;
else if (!f->up) break;
else txt += " | <(unknown tag)";
if (f->args)
foreach (sort (indices (f->args)), string arg) {
mixed val = f->args[arg];
txt += " " + arg + "=";
if (arrayp (val)) txt += map (val, error_print_val) * ",";
else txt += error_print_val (val);
}
else txt += " (no argmap)";
txt += ">\n";
}
}
else
if (!no_msg) txt += " (no context): " + (msg || "(no error message)\n");
return txt;
}
private string error_print_val (mixed val)
{
if (arrayp (val)) return "array";
else if (mappingp (val)) return "mapping";
else if (multisetp (val)) return "multiset";
else return sprintf ("%O", val);
}
string|array `[] (int i)
{
switch (i) {
case 0: return describe_rxml_backtrace();
case 1: return backtrace;
}
}
string _sprintf() {return "RXML.Backtrace(" + type + ")";}
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
#if constant (thread_create)
|
56532d | 1999-12-19 | Martin Stjernholm | | private Thread.Local _context = thread_local();
|
ed8175 | 1999-12-11 | Martin Stjernholm | | inline void set_context (Context ctx) {_context->set (ctx);}
inline Context get_context() {return [object(Context)] _context->get();}
#else
private Context _context;
inline void set_context (Context ctx) {_context = ctx;}
inline Context get_context() {return _context;}
#endif
|
2d2034 | 2000-02-12 | Martin Stjernholm | | #if defined (MODULE_DEBUG) && constant (thread_create)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
#define ENTER_CONTEXT(ctx) \
Context __old_ctx = get_context(); \
set_context (ctx); \
if (ctx) { \
|
2d2034 | 2000-02-12 | Martin Stjernholm | | if (ctx->in_use && ctx->in_use != this_thread()) \
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Attempt to use context asynchronously.\n"); \
|
2d2034 | 2000-02-12 | Martin Stjernholm | | ctx->in_use = this_thread(); \
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
#define LEAVE_CONTEXT() \
if (Context ctx = get_context()) \
if (__old_ctx != ctx) ctx->in_use = 0; \
set_context (__old_ctx);
#else
#define ENTER_CONTEXT(ctx) \
Context __old_ctx = get_context(); \
set_context (ctx);
#define LEAVE_CONTEXT() \
set_context (__old_ctx);
#endif
|
76cbfb | 2000-02-04 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_NONE = 0x00000000;
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_NONCONTAINER = 0x00000001;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_NO_PREFIX = 0x00000002;
|
cece9e | 2000-01-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_SOCKET_TAG = 0x0000004;
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_DONT_PREPARSE = 0x00000040;
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_POSTPARSE = 0x00000080;
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_PARENT_SCOPE = 0x00000100;
|
49897a | 2000-02-13 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_NO_IMPLICIT_ARGS = 0x00000200;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_STREAM_RESULT = 0x00000400;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_STREAM_CONTENT = 0x00000800;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_STREAM = FLAG_STREAM_RESULT | FLAG_STREAM_CONTENT;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_UNPARSED = 0x00001000;
|
49897a | 2000-02-13 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_CACHE_DIFF_ARGS = 0x00010000;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
constant FLAG_CACHE_DIFF_CONTENT = 0x00020000;
constant FLAG_CACHE_DIFF_RESULT_TYPE = 0x00040000;
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_CACHE_DIFF_VARS = 0x00080000;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_CACHE_SAME_STACK = 0x00100000;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
constant FLAG_CACHE_EXECUTE_RESULT = 0x00200000;
class Frame
{
constant is_RXML_Frame = 1;
|
56532d | 1999-12-19 | Martin Stjernholm | | constant thrown_at_unwind = 1;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
Frame up;
Tag tag;
int flags;
mapping(string:mixed) args;
Type content_type;
mixed content = Void;
Type result_type;
mixed result = Void;
|
146e34 | 2000-02-15 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
a21fcb | 2000-02-08 | Martin Nilsson | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
c6245b | 1999-12-31 | Martin Stjernholm | | optional array cached_return (Context ctx, void|mixed piece);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
5ed013 | 2000-02-13 | Martin Stjernholm | | void run_error (string msg, mixed... args)
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
5ed013 | 2000-02-13 | Martin Stjernholm | | _run_error (msg, @args);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
5ed013 | 2000-02-13 | Martin Stjernholm | | void parse_error (string msg, mixed... args)
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | | {
|
5ed013 | 2000-02-13 | Martin Stjernholm | | _parse_error (msg, @args);
|
291ade | 2000-01-25 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | void terminate()
{
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("FIXME\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
void suspend()
{
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("FIXME\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
void resume()
{
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("FIXME\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
cf3c90 | 2000-02-04 | Martin Stjernholm | | mapping(string:Tag) get_plugins()
{
#ifdef MODULE_DEBUG
if (!(flags & FLAG_SOCKET_TAG))
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("This tag is not a socket tag.\n");
|
cf3c90 | 2000-02-04 | Martin Stjernholm | | #endif
return get_context()->tag_set->get_plugins (tag->name);
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
e86f2d | 2000-02-15 | Martin Stjernholm | | mixed _exec_array (TagSetParser parser, array exec, int parent_scope)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
56532d | 1999-12-19 | Martin Stjernholm | | Frame this = this_object();
|
c6245b | 1999-12-31 | Martin Stjernholm | | Context ctx = parser->context;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | int i = 0;
mixed res = Void;
Parser subparser = 0;
mixed err = catch {
|
e86f2d | 2000-02-15 | Martin Stjernholm | | if (parent_scope) LEAVE_SCOPE (ctx, this);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
for (; i < sizeof (exec); i++) {
mixed elem = exec[i], piece = Void;
switch (sprintf ("%t", elem)) {
case "string":
if (result_type->_parser_prog == PNone)
piece = elem;
else {
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | subparser = result_type->get_parser (ctx, 0, parser);
|
56532d | 1999-12-19 | Martin Stjernholm | | subparser->finish ([string] elem);
piece = subparser->eval();
|
ed8175 | 1999-12-11 | Martin Stjernholm | | subparser = 0;
}
break;
case "mapping":
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Header mappings not yet implemented.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | break;
case "multiset":
|
56532d | 1999-12-19 | Martin Stjernholm | | if (sizeof ([multiset] elem) == 1) piece = ((array) elem)[0];
else if (sizeof ([multiset] elem) > 1)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error (sizeof ([multiset] elem) +
" values in multiset in exec array.\n");
else fatal_error ("No value in multiset in exec array.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | break;
default:
|
5a455b | 2000-02-13 | Martin Stjernholm | | if (objectp (elem))
if (([object] elem)->is_RXML_Frame) {
|
a85a95 | 2000-02-13 | Martin Stjernholm | | ([object(Frame)] elem)->_eval (parser);
|
5a455b | 2000-02-13 | Martin Stjernholm | | piece = ([object(Frame)] elem)->result;
}
else if (([object] elem)->is_RXML_Parser) {
([object(Parser)] elem)->finish();
piece = ([object(Parser)] elem)->eval();
}
else
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("File objects not yet implemented.\n");
|
5a455b | 2000-02-13 | Martin Stjernholm | | else
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Invalid type %t in exec array.\n", elem);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
if (result_type->sequential) res += piece;
else if (piece != Void) result = res = piece;
}
if (result_type->sequential) result += res;
|
e86f2d | 2000-02-15 | Martin Stjernholm | | if (parent_scope) ENTER_SCOPE (ctx, this);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | return res;
};
|
e86f2d | 2000-02-15 | Martin Stjernholm | | if (parent_scope) ENTER_SCOPE (ctx, this);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if (result_type->sequential) result += res;
|
56532d | 1999-12-19 | Martin Stjernholm | | if (objectp (err) && ([object] err)->thrown_at_unwind) {
mapping(string:mixed)|mapping(object:array) ustate;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if ((ustate = ctx->unwind_state) && !zero_type (ustate->stream_piece))
|
590b3c | 2000-02-05 | Martin Stjernholm | | if (result_type->quoting_scheme != parser->type->quoting_scheme)
res = parser->type->quote (res);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if (result_type->sequential)
ustate->stream_piece = res + ustate->stream_piece;
else if (ustate->stream_piece == Void)
ustate->stream_piece = res;
ustate->exec_left = exec[i..];
if (subparser)
|
56532d | 1999-12-19 | Martin Stjernholm | |
([array] ustate->exec_left)[0] = subparser;
|
8cb24d | 2000-02-13 | Martin Stjernholm | | throw (err);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
8cb24d | 2000-02-13 | Martin Stjernholm | | throw_fatal (err);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | private void _handle_runtime_tags (Context ctx, TagSetParser parser)
|
2bd21a | 2000-01-05 | Martin Stjernholm | | {
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | multiset(string|Tag) rem_tags = ctx->new_runtime_tags->remove_tags;
multiset(Tag) add_tags = ctx->new_runtime_tags->add_tags - rem_tags;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | if (sizeof (rem_tags))
foreach (indices (add_tags), Tag tag)
if (rem_tags[tag->name]) add_tags[tag] = 0;
array(string|Tag) arr_rem_tags = (array) rem_tags;
array(Tag) arr_add_tags = (array) add_tags;
for (Parser p = parser; p; p = p->_parent)
|
950285 | 2000-02-15 | Martin Stjernholm | | if (p->tag_set_eval && !p->_local_tag_set && p->add_runtime_tag) {
|
2bd21a | 2000-01-05 | Martin Stjernholm | | foreach (arr_add_tags, Tag tag)
([object(TagSetParser)] p)->add_runtime_tag (tag);
foreach (arr_rem_tags, string|object(Tag) tag)
([object(TagSetParser)] p)->remove_runtime_tag (tag);
}
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | ctx->runtime_tags |= add_tags;
ctx->runtime_tags -= rem_tags;
ctx->new_runtime_tags = 0;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | void _eval (TagSetParser parser,
void|mapping(string:string) raw_args,
void|string raw_content)
{
|
56532d | 1999-12-19 | Martin Stjernholm | | Frame this = this_object();
|
ed8175 | 1999-12-11 | Martin Stjernholm | | Context ctx = parser->context;
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | | #define EVSTAT_BEGIN 0
#define EVSTAT_ENTERED 1
#define EVSTAT_LAST_ITER 2
#define EVSTAT_ITER_DONE 3
int eval_state = EVSTAT_BEGIN;
|
291ade | 2000-01-25 | Martin Stjernholm | | int iter;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | Parser subparser;
mixed piece;
array exec;
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | int tags_added;
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | #define PRE_INIT_ERROR(X) (ctx->frame = this, fatal_error (X))
|
2bd21a | 2000-01-05 | Martin Stjernholm | | #ifdef DEBUG
if (ctx != get_context())
PRE_INIT_ERROR ("Internal error: Context not current.\n");
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | if (!parser->tag_set_eval)
|
2bd21a | 2000-01-05 | Martin Stjernholm | | PRE_INIT_ERROR ("Internal error: Calling _eval() with non-tag set parser.\n");
#endif
#ifdef MODULE_DEBUG
if (ctx->new_runtime_tags)
PRE_INIT_ERROR ("Looks like Context.add_runtime_tag() or "
"Context.remove_runtime_tag() was used outside any parser.\n");
#endif
|
76cbfb | 2000-02-04 | Martin Stjernholm | | if (flags & FLAG_UNPARSED) {
#ifdef DEBUG
if (raw_args || raw_content)
PRE_INIT_ERROR ("Internal error: raw_args or raw_content given for "
"unparsed frame.\n");
#endif
raw_args = args, args = 0;
raw_content = content, content = Void;
#ifdef MODULE_DEBUG
if (!stringp (raw_content))
PRE_INIT_ERROR ("Content is not a string in unparsed tag frame.\n");
#endif
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if (array state = ctx->unwind_state && ctx->unwind_state[this]) {
#ifdef DEBUG
if (!up)
PRE_INIT_ERROR ("Internal error: Resuming frame without up pointer.\n");
if (raw_args || raw_content)
PRE_INIT_ERROR ("Internal error: Can't feed new arguments or content "
"when resuming parse.\n");
#endif
|
56532d | 1999-12-19 | Martin Stjernholm | | object ignored;
|
291ade | 2000-01-25 | Martin Stjernholm | | [ignored, eval_state, iter, raw_content, subparser, piece, exec, tags_added,
|
2bd21a | 2000-01-05 | Martin Stjernholm | | ctx->new_runtime_tags] = state;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | m_delete (ctx->unwind_state, this);
if (!sizeof (ctx->unwind_state)) ctx->unwind_state = 0;
}
else {
#ifdef MODULE_DEBUG
if (up && up != ctx->frame)
PRE_INIT_ERROR ("Reuse of frame in different context.\n");
#endif
up = ctx->frame;
piece = Void;
}
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #undef PRE_INIT_ERROR
ctx->frame = this;
if (raw_args) {
|
01e43b | 2000-01-14 | Martin Stjernholm | | args = raw_args;
|
49897a | 2000-02-13 | Martin Stjernholm | | if (sizeof (raw_args)) {
mapping(string:Type) atypes = raw_args & tag->req_arg_types;
if (sizeof (atypes) < sizeof (tag->req_arg_types)) {
array(string) missing = sort (indices (tag->req_arg_types - atypes));
|
5ed013 | 2000-02-13 | Martin Stjernholm | | parse_error ("Required " +
(sizeof (missing) > 1 ?
"arguments " + String.implode_nicely (missing) + " are" :
"argument " + missing[0] + " is") + " missing.\n");
|
49897a | 2000-02-13 | Martin Stjernholm | | }
atypes += raw_args & tag->opt_arg_types;
|
c159ec | 2000-02-04 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
49897a | 2000-02-13 | Martin Stjernholm | | if (mixed err = catch {
|
c159ec | 2000-02-04 | Martin Stjernholm | | #endif
|
49897a | 2000-02-13 | Martin Stjernholm | | foreach (indices (args), string arg)
args[arg] = (atypes[arg] || tag->def_arg_type)->
eval (raw_args[arg], ctx, 0, parser, 1);
|
c159ec | 2000-02-04 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
49897a | 2000-02-13 | Martin Stjernholm | | }) {
if (objectp (err) && ([object] err)->thrown_at_unwind)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Can't save parser state when evaluating arguments.\n");
throw_fatal (err);
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
710b48 | 2000-02-07 | Martin Stjernholm | | #endif
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
49897a | 2000-02-13 | Martin Stjernholm | |
#ifdef MODULE_DEBUG
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (!args) fatal_error ("args not set.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
if (TagSet add_tags = raw_content && [object(TagSet)] this->additional_tags) {
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | if (!ctx->tag_set_is_local) ctx->make_tag_set_local();
if (search (ctx->tag_set->imported, add_tags) < 0) {
ctx->tag_set->imported = ({add_tags}) + ctx->tag_set->imported;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | tags_added = 1;
}
}
if (!result_type) {
|
a85a95 | 2000-02-13 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (!tag) fatal_error ("result_type not set in Frame object %O, "
"and it has no Tag object to use for inferring it.\n",
this_object());
|
a85a95 | 2000-02-13 | Martin Stjernholm | | #endif
|
56532d | 1999-12-19 | Martin Stjernholm | | Type ptype = parser->type;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | foreach (tag->result_types, Type rtype)
|
49897a | 2000-02-13 | Martin Stjernholm | | if (ptype == rtype) {
result_type = rtype;
break;
}
else if (ptype->subtype_of (rtype)) {
result_type = ptype (rtype->_parser_prog);
break;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if (!result_type)
|
5ed013 | 2000-02-13 | Martin Stjernholm | | parse_error (
|
01e43b | 2000-01-14 | Martin Stjernholm | | "Tag returns " +
String.implode_nicely ([array(string)] tag->result_types->name, "or") +
" but " + [string] parser->type->name + " is expected.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
590b3c | 2000-02-05 | Martin Stjernholm | | if (!content_type) {
|
a85a95 | 2000-02-13 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (!tag) fatal_error ("content_type not set in Frame object %O, "
"and it has no Tag object to use for inferring it.\n",
this_object());
|
a85a95 | 2000-02-13 | Martin Stjernholm | | #endif
|
590b3c | 2000-02-05 | Martin Stjernholm | | content_type = tag->content_type;
if (content_type == t_same)
content_type = result_type (content_type->_parser_prog);
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
mixed err = catch {
|
49897a | 2000-02-13 | Martin Stjernholm | | switch (eval_state) {
case EVSTAT_BEGIN:
if (array|function(RequestID,void|mixed:array) do_enter =
[array|function(RequestID,void|mixed:array)] this->do_enter) {
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | if (!exec) {
exec = do_enter (ctx->id);
if (ctx->new_runtime_tags)
_handle_runtime_tags (ctx, parser);
}
|
49897a | 2000-02-13 | Martin Stjernholm | | if (exec) {
|
e86f2d | 2000-02-15 | Martin Stjernholm | | if (!(flags & FLAG_PARENT_SCOPE)) ENTER_SCOPE (ctx, this);
mixed res = _exec_array (parser, exec, 0);
|
49897a | 2000-02-13 | Martin Stjernholm | | if (flags & FLAG_STREAM_RESULT) {
|
291ade | 2000-01-25 | Martin Stjernholm | | #ifdef DEBUG
|
49897a | 2000-02-13 | Martin Stjernholm | | if (ctx->unwind_state)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Internal error: Clobbering unwind_state "
"to do streaming.\n");
|
49897a | 2000-02-13 | Martin Stjernholm | | if (piece != Void)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Internal error: Thanks, we think about how nice it must "
"be to play the harmonica...\n");
|
291ade | 2000-01-25 | Martin Stjernholm | | #endif
|
49897a | 2000-02-13 | Martin Stjernholm | | if (result_type->quoting_scheme != parser->type->quoting_scheme)
res = parser->type->quote (res);
ctx->unwind_state = (["stream_piece": res]);
throw (this);
}
|
e86f2d | 2000-02-15 | Martin Stjernholm | | exec = 0;
|
291ade | 2000-01-25 | Martin Stjernholm | | }
}
|
49897a | 2000-02-13 | Martin Stjernholm | | eval_state = EVSTAT_ENTERED;
|
e86f2d | 2000-02-15 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | | case EVSTAT_ENTERED:
case EVSTAT_LAST_ITER:
do {
if (eval_state != EVSTAT_LAST_ITER) {
int|function(RequestID:int) do_iterate =
[int|function(RequestID:int)] this->do_iterate;
if (intp (do_iterate)) {
iter = [int] do_iterate || 1;
eval_state = EVSTAT_LAST_ITER;
}
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | else {
iter = ( do_iterate) (
ctx->id);
if (ctx->new_runtime_tags)
_handle_runtime_tags (ctx, parser);
if (!iter) eval_state = EVSTAT_LAST_ITER;
}
|
2bd21a | 2000-01-05 | Martin Stjernholm | | }
|
146e34 | 2000-02-15 | Martin Stjernholm | | ENTER_SCOPE (ctx, this);
|
49897a | 2000-02-13 | Martin Stjernholm | |
|
146e34 | 2000-02-15 | Martin Stjernholm | | for (; iter > 0; iter--) {
|
777ff2 | 2000-02-15 | Martin Stjernholm | | if (raw_content && raw_content != "") {
|
49897a | 2000-02-13 | Martin Stjernholm | | int finished = 0;
if (!subparser) {
|
950285 | 2000-02-15 | Martin Stjernholm | | if (this->local_tags) {
subparser = content_type->get_parser (
ctx, [object(TagSet)] this->local_tags, parser);
subparser->_local_tag_set = 1;
}
else
subparser = content_type->get_parser (ctx, 0, parser);
|
49897a | 2000-02-13 | Martin Stjernholm | | subparser->finish (raw_content);
finished = 1;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | | do {
if (flags & FLAG_STREAM_CONTENT && subparser->read) {
mixed res = subparser->read();
if (content_type->sequential) piece = res + piece;
else if (piece == Void) piece = res;
if (piece != Void) {
array|function(RequestID,void|mixed:array) do_return;
if ((do_return =
[array|function(RequestID,void|mixed:array)]
this->do_return) &&
|
e86f2d | 2000-02-15 | Martin Stjernholm | | !arrayp (do_return)) {
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | if (!exec) {
exec = do_return (ctx->id, piece);
if (ctx->new_runtime_tags)
_handle_runtime_tags (ctx, parser);
}
|
49897a | 2000-02-13 | Martin Stjernholm | | if (exec) {
|
146e34 | 2000-02-15 | Martin Stjernholm | | ENTER_SCOPE (ctx, this);
|
e86f2d | 2000-02-15 | Martin Stjernholm | | mixed res = _exec_array (
parser, exec, flags & FLAG_PARENT_SCOPE);
|
49897a | 2000-02-13 | Martin Stjernholm | | if (flags & FLAG_STREAM_RESULT) {
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #ifdef DEBUG
|
49897a | 2000-02-13 | Martin Stjernholm | | if (!zero_type (ctx->unwind_state->stream_piece))
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Internal error: "
"Clobbering unwind_state->stream_piece.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
|
49897a | 2000-02-13 | Martin Stjernholm | | if (result_type->quoting_scheme !=
parser->type->quoting_scheme)
res = parser->type->quote (res);
ctx->unwind_state->stream_piece = res;
throw (this);
}
exec = 0;
}
else if (flags & FLAG_STREAM_RESULT) {
ctx->unwind_state = 0;
piece = Void;
break;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
piece = Void;
|
49897a | 2000-02-13 | Martin Stjernholm | | }
if (finished) break;
}
else {
piece = Void;
if (finished) {
mixed res = subparser->eval();
if (content_type->sequential) content += res;
else if (res != Void) content = res;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | break;
}
}
|
49897a | 2000-02-13 | Martin Stjernholm | | subparser->finish();
finished = 1;
} while (1);
subparser = 0;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | | if (array|function(RequestID,void|mixed:array) do_return =
[array|function(RequestID,void|mixed:array)] this->do_return) {
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | if (!exec) {
|
e86f2d | 2000-02-15 | Martin Stjernholm | | exec = arrayp (do_return) ? [array] do_return :
|
49897a | 2000-02-13 | Martin Stjernholm | | ([function(RequestID,void|mixed:array)] do_return) (
|
e86f2d | 2000-02-15 | Martin Stjernholm | | ctx->id);
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | if (ctx->new_runtime_tags)
_handle_runtime_tags (ctx, parser);
}
|
49897a | 2000-02-13 | Martin Stjernholm | | if (exec) {
|
146e34 | 2000-02-15 | Martin Stjernholm | | ENTER_SCOPE (ctx, this);
|
e86f2d | 2000-02-15 | Martin Stjernholm | | mixed res = _exec_array (
parser, exec, flags & FLAG_PARENT_SCOPE);
|
49897a | 2000-02-13 | Martin Stjernholm | | if (flags & FLAG_STREAM_RESULT) {
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #ifdef DEBUG
|
49897a | 2000-02-13 | Martin Stjernholm | | if (ctx->unwind_state)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Internal error: Clobbering unwind_state "
"to do streaming.\n");
|
49897a | 2000-02-13 | Martin Stjernholm | | if (piece != Void)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Internal error: Thanks, we think about how nice "
"it must be to play the harmonica...\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
|
49897a | 2000-02-13 | Martin Stjernholm | | if (result_type->quoting_scheme != parser->type->quoting_scheme)
res = parser->type->quote (res);
ctx->unwind_state = (["stream_piece": res]);
throw (this);
}
|
e86f2d | 2000-02-15 | Martin Stjernholm | | exec = 0;
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
49897a | 2000-02-13 | Martin Stjernholm | | }
} while (eval_state != EVSTAT_LAST_ITER);
|
e86f2d | 2000-02-15 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | | case EVSTAT_ITER_DONE:
if (!this->do_return && result == Void)
if (result_type->_parser_prog == PNone) {
if (content_type->subtype_of (result_type))
result = content;
}
else
if (stringp (content_type)) {
eval_state = EVSTAT_ITER_DONE;
if (!exec) exec = ({content});
|
e86f2d | 2000-02-15 | Martin Stjernholm | | _exec_array (parser, exec, flags & FLAG_PARENT_SCOPE);
exec = 0;
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
e86f2d | 2000-02-15 | Martin Stjernholm | | LEAVE_SCOPE (ctx, this);
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
f99720 | 2000-01-18 | Martin Stjernholm | |
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | if (ctx->new_runtime_tags)
_handle_runtime_tags (ctx, parser);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | };
if (err) {
|
291ade | 2000-01-25 | Martin Stjernholm | | LEAVE_SCOPE (ctx, this);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | string action;
|
56532d | 1999-12-19 | Martin Stjernholm | | if (objectp (err) && ([object] err)->thrown_at_unwind) {
mapping(string:mixed)|mapping(object:array) ustate = ctx->unwind_state;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if (!ustate) ustate = ctx->unwind_state = ([]);
#ifdef DEBUG
if (ustate[this])
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Internal error: Frame already has an unwind state.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
if (ustate->exec_left) {
exec = [array] ustate->exec_left;
m_delete (ustate, "exec_left");
}
|
56532d | 1999-12-19 | Martin Stjernholm | | if (err == this || exec && sizeof (exec) && err == exec[0])
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
56532d | 1999-12-19 | Martin Stjernholm | | if (parser->unwind_safe) {
if (err == this) err = 0;
if (tags_added) {
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | ctx->tag_set->imported -= ({ this->additional_tags});
|
56532d | 1999-12-19 | Martin Stjernholm | | tags_added = 0;
}
action = "break";
}
else {
m_delete (ustate, "stream_piece");
action = "continue";
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
else if (!zero_type (ustate->stream_piece)) {
piece = ustate->stream_piece;
m_delete (ustate, "stream_piece");
action = "continue";
}
else action = "break";
|
291ade | 2000-01-25 | Martin Stjernholm | | ustate[this] = ({err, eval_state, iter, raw_content, subparser, piece,
exec, tags_added, ctx->new_runtime_tags});
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
01e43b | 2000-01-14 | Martin Stjernholm | | else {
|
8cb24d | 2000-02-13 | Martin Stjernholm | | ctx->handle_exception (err, parser);
|
01e43b | 2000-01-14 | Martin Stjernholm | | action = "return";
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
switch (action) {
case "break":
|
56532d | 1999-12-19 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (!parser->unwind_state)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Trying to unwind inside a parser that isn't unwind safe.\n");
|
56532d | 1999-12-19 | Martin Stjernholm | | #endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | throw (this);
case "continue":
_eval (parser);
return;
|
01e43b | 2000-01-14 | Martin Stjernholm | | case "return":
break;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | default:
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Internal error: Don't you come here and %O on me!\n", action);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
}
|
01e43b | 2000-01-14 | Martin Stjernholm | | if (tags_added)
ctx->tag_set->imported -= ({ this->additional_tags});
ctx->frame = up;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
26ff09 | 2000-01-21 | Martin Stjernholm | | DECLARE_CNT (__count);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | string _sprintf()
{
|
26ff09 | 2000-01-21 | Martin Stjernholm | | return "RXML.Frame(" + (tag && [string] tag->name) + COMMA_CNT (__count) + ")";
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
}
|
49897a | 2000-02-13 | Martin Stjernholm | |
|
5ed013 | 2000-02-13 | Martin Stjernholm | | void run_error (string msg, mixed... args)
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | | {
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (sizeof (args)) msg = sprintf (msg, @args);
throw (Backtrace ("run", msg, get_context()));
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
5ed013 | 2000-02-13 | Martin Stjernholm | | void parse_error (string msg, mixed... args)
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | | {
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (sizeof (args)) msg = sprintf (msg, @args);
throw (Backtrace ("parse", msg, get_context()));
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
8cb24d | 2000-02-13 | Martin Stjernholm | | void fatal_error (string msg, mixed... args)
|
49897a | 2000-02-13 | Martin Stjernholm | | {
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (sizeof (args)) msg = sprintf (msg, @args);
array bt = backtrace();
throw_fatal (({msg, bt[..sizeof (bt) - 2]}));
}
void throw_fatal (mixed err)
{
if (arrayp (err) && sizeof (err) == 2 ||
objectp (err) && !err->is_RXML_Backtrace && err->is_generic_error) {
string msg;
if (catch (msg = err[0])) throw (err);
if (stringp (msg) && !has_value (msg, "\nRXML frame backtrace:\n")) {
|
5ed013 | 2000-02-13 | Martin Stjernholm | | string descr = Backtrace ("fatal", 0)->describe_rxml_backtrace (1);
if (sizeof (descr)) {
if (sizeof (msg) && msg[-1] != '\n') msg += "\n";
msg += "RXML frame backtrace:\n" + descr;
catch (err[0] = msg);
}
|
8cb24d | 2000-02-13 | Martin Stjernholm | | }
}
throw (err);
|
49897a | 2000-02-13 | Martin Stjernholm | | }
Frame make_tag (string name, mapping(string:mixed) args, void|mixed content)
{
TagSet tag_set = get_context()->tag_set;
object(Tag)|array(LOW_TAG_TYPE|LOW_CONTAINER_TYPE) tag = tag_set->get_tag (name);
if (arrayp (tag))
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Getting frames for low level tags are currently not implemented.\n");
|
49897a | 2000-02-13 | Martin Stjernholm | | return tag (args, content);
}
Frame make_unparsed_tag (string name, mapping(string:string) args, void|string content)
{
TagSet tag_set = get_context()->tag_set;
object(Tag)|array(LOW_TAG_TYPE|LOW_CONTAINER_TYPE) tag = tag_set->get_tag (name);
if (arrayp (tag))
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Getting frames for low level tags are currently not implemented.\n");
|
49897a | 2000-02-13 | Martin Stjernholm | | Frame frame = tag (args, content);
frame->flags |= FLAG_UNPARSED;
return frame;
}
class parse_frame
{
inherit Frame;
constant flags = FLAG_UNPARSED;
mapping(string:mixed) args = ([]);
void create (Type type, string to_parse)
{
content_type = type, result_type = type (PNone);
content = to_parse;
}
string _sprintf() {return sprintf ("parse_frame(%O)", content_type);}
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
class Parser
{
constant is_RXML_Parser = 1;
|
56532d | 1999-12-19 | Martin Stjernholm | | constant thrown_at_unwind = 1;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
db0417 | 2000-01-14 | Martin Stjernholm | | int error_count;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | function(Parser:void) data_callback;
int write (string in)
{
int res;
ENTER_CONTEXT (context);
mixed err = catch {
|
56532d | 1999-12-19 | Martin Stjernholm | | if (context && context->unwind_state && context->unwind_state->top) {
|
c6245b | 1999-12-31 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (context->unwind_state->top != this_object())
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("The context got an unwound state from another parser. "
"Can't rewind.\n");
|
c6245b | 1999-12-31 | Martin Stjernholm | | #endif
|
56532d | 1999-12-19 | Martin Stjernholm | | m_delete (context->unwind_state, "top");
if (!sizeof (context->unwind_state)) context->unwind_state = 0;
}
|
b43689 | 2000-01-19 | Martin Stjernholm | | if (feed (in)) res = 1;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if (res && data_callback) data_callback (this_object());
};
LEAVE_CONTEXT();
|
56532d | 1999-12-19 | Martin Stjernholm | | if (err)
if (objectp (err) && ([object] err)->thrown_at_unwind) {
|
c6245b | 1999-12-31 | Martin Stjernholm | | #ifdef DEBUG
if (err != this_object())
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Internal error: Unexpected unwind object catched.\n");
|
c6245b | 1999-12-31 | Martin Stjernholm | | #endif
|
56532d | 1999-12-19 | Martin Stjernholm | | if (!context->unwind_state) context->unwind_state = ([]);
context->unwind_state->top = err;
}
|
01e43b | 2000-01-14 | Martin Stjernholm | | else if (context)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | context->handle_exception (err, this_object());
else throw_fatal (err);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | return res;
}
void write_end (void|string in)
{
int res;
ENTER_CONTEXT (context);
mixed err = catch {
|
56532d | 1999-12-19 | Martin Stjernholm | | if (context && context->unwind_state && context->unwind_state->top) {
|
c6245b | 1999-12-31 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (context->unwind_state->top != this_object())
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("The context got an unwound state from another parser. "
"Can't rewind.\n");
|
c6245b | 1999-12-31 | Martin Stjernholm | | #endif
|
56532d | 1999-12-19 | Martin Stjernholm | | m_delete (context->unwind_state, "top");
if (!sizeof (context->unwind_state)) context->unwind_state = 0;
}
|
b43689 | 2000-01-19 | Martin Stjernholm | | finish (in);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if (data_callback) data_callback (this_object());
};
LEAVE_CONTEXT();
|
56532d | 1999-12-19 | Martin Stjernholm | | if (err)
if (objectp (err) && ([object] err)->thrown_at_unwind) {
|
c6245b | 1999-12-31 | Martin Stjernholm | | #ifdef DEBUG
if (err != this_object())
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("Internal error: Unexpected unwind object catched.\n");
|
c6245b | 1999-12-31 | Martin Stjernholm | | #endif
|
56532d | 1999-12-19 | Martin Stjernholm | | if (!context->unwind_state) context->unwind_state = ([]);
context->unwind_state->top = err;
}
|
01e43b | 2000-01-14 | Martin Stjernholm | | else if (context)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | context->handle_exception (err, this_object());
else throw_fatal (err);
|
01e43b | 2000-01-14 | Martin Stjernholm | | }
array handle_var (string varref)
{
array(string) split = varref / ".";
if (sizeof (split) == 2)
if (mixed err = catch {
|
8778dd | 2000-02-05 | Martin Stjernholm | | sscanf (split[1], "%[^:]:%s", split[1], string encoding);
|
db0417 | 2000-01-14 | Martin Stjernholm | | context->current_var = varref;
|
01e43b | 2000-01-14 | Martin Stjernholm | | mixed val;
|
710b48 | 2000-02-07 | Martin Stjernholm | | if (zero_type (val = context->get_var (
split[1], split[0], encoding ? t_text : type))) {
|
db0417 | 2000-01-14 | Martin Stjernholm | | context->current_var = 0;
|
01e43b | 2000-01-14 | Martin Stjernholm | | return ({});
|
db0417 | 2000-01-14 | Martin Stjernholm | | }
context->current_var = 0;
|
710b48 | 2000-02-07 | Martin Stjernholm | | return encoding ? ({roxen->roxen_encode (val, encoding)}) : ({val});
|
01e43b | 2000-01-14 | Martin Stjernholm | | }) {
|
db0417 | 2000-01-14 | Martin Stjernholm | | context->current_var = 0;
|
01e43b | 2000-01-14 | Martin Stjernholm | | context->handle_exception (err, this_object());
return ({});
}
return type->free_text ? 0 : ({});
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
Context context;
Type type;
int compile;
|
56532d | 1999-12-19 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | mixed feed (string in);
void finish (void|string in);
|
8cb24d | 2000-02-13 | Martin Stjernholm | | optional int report_error (string msg);
|
01e43b | 2000-01-14 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
01e43b | 2000-01-14 | Martin Stjernholm | |
|
c6245b | 1999-12-31 | Martin Stjernholm | | optional mixed read();
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
56532d | 1999-12-19 | Martin Stjernholm | | mixed eval();
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
c6245b | 1999-12-31 | Martin Stjernholm | | optional PCode p_compile();
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
c6245b | 1999-12-31 | Martin Stjernholm | | optional void reset (Context ctx, Type type, mixed... args);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
b2d01b | 2000-02-15 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
c6245b | 1999-12-31 | Martin Stjernholm | | optional Parser clone (Context ctx, Type type, mixed... args);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
b2d01b | 2000-02-15 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | | static void create (Context ctx, Type _type, mixed... args)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
context = ctx;
type = _type;
}
Parser _next_free;
|
c6245b | 1999-12-31 | Martin Stjernholm | |
Parser _parent;
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
01e43b | 2000-01-14 | Martin Stjernholm | | Stdio.File _source_file;
mapping _defines;
|
26ff09 | 2000-01-21 | Martin Stjernholm | | DECLARE_CNT (__count);
string _sprintf() {return "RXML.Parser" + PAREN_CNT (__count);}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
class TagSetParser
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
01e43b | 2000-01-14 | Martin Stjernholm | |
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
inherit Parser;
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | constant tag_set_eval = 1;
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
b43689 | 2000-01-19 | Martin Stjernholm | | mixed eval() {return read();}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | TagSet tag_set;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | optional void reset (Context ctx, Type type, TagSet tag_set, mixed... args);
optional Parser clone (Context ctx, Type type, TagSet tag_set, mixed... args);
static void create (Context ctx, Type type, TagSet _tag_set, mixed... args)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
::create (ctx, type);
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | tag_set = _tag_set;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
2bd21a | 2000-01-05 | Martin Stjernholm | | mixed read();
|
3187d8 | 2000-01-28 | Martin Stjernholm | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
b2d01b | 2000-02-15 | Martin Stjernholm | | optional void add_runtime_tag (Tag tag);
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
b2d01b | 2000-02-15 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
b2d01b | 2000-02-15 | Martin Stjernholm | | optional void remove_runtime_tag (string|Tag tag);
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
950285 | 2000-02-15 | Martin Stjernholm | |
int _local_tag_set;
|
26ff09 | 2000-01-21 | Martin Stjernholm | | string _sprintf() {return "RXML.TagSetParser" + PAREN_CNT (__count);}
|
c6245b | 1999-12-31 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
class PNone
{
inherit Parser;
string data = "";
int evalpos = 0;
int feed (string in)
{
data += in;
return 1;
}
void finish (void|string in)
{
if (in) data += in;
}
string eval()
{
string res = data[evalpos..];
evalpos = sizeof (data);
return res;
}
string byte_compile()
{
return data;
}
string byte_interpret (string byte_code, Context ctx)
{
return byte_code;
}
void reset (Context ctx)
{
context = ctx;
data = "";
evalpos = 0;
}
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | | string _sprintf() {return "RXML.PNone" + PAREN_CNT (__count);}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
mixed simple_parse (string in, void|program parser)
{
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | return t_any (parser || PExpr)->eval (in, Context (empty_tag_set));
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
class Type
{
constant is_RXML_Type = 1;
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
e213f0 | 1999-12-13 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
e213f0 | 1999-12-13 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
void type_check (mixed val);
|
01e43b | 2000-01-14 | Martin Stjernholm | |
|
5ed013 | 2000-02-13 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
590b3c | 2000-02-05 | Martin Stjernholm | |
mixed quote (mixed val)
{
return val;
}
mixed convert (mixed val, void|Type from);
|
8778dd | 2000-02-05 | Martin Stjernholm | |
|
590b3c | 2000-02-05 | Martin Stjernholm | |
|
8778dd | 2000-02-05 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | Type clone()
{
|
56532d | 1999-12-19 | Martin Stjernholm | | Type newtype = object_program (this_object())();
|
ed8175 | 1999-12-11 | Martin Stjernholm | | newtype->_parser_prog = _parser_prog;
|
c757c4 | 2000-01-08 | Martin Stjernholm | | newtype->_parser_args = _parser_args;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | newtype->_t_obj_cache = _t_obj_cache;
return newtype;
}
int `== (mixed other)
{
|
56532d | 1999-12-19 | Martin Stjernholm | | return objectp (other) && ([object] other)->is_RXML_Type &&
([object(Type)] other)->name == this_object()->name;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
int subtype_of (Type other)
{
|
56532d | 1999-12-19 | Martin Stjernholm | | return glob ([string] other->name, [string] this_object()->name);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
2bd21a | 2000-01-05 | Martin Stjernholm | | Type `() (program newparser, mixed... parser_args)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
{
Type newtype;
if (sizeof (parser_args)) {
newtype = clone();
|
c757c4 | 2000-01-08 | Martin Stjernholm | | newtype->_parser_prog = newparser;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | newtype->_parser_args = parser_args;
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | if (newparser->tag_set_eval) newtype->_p_cache = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
else {
if (!_t_obj_cache) _t_obj_cache = ([]);
if (!(newtype = _t_obj_cache[newparser]))
if (newparser == _parser_prog)
|
56532d | 1999-12-19 | Martin Stjernholm | | _t_obj_cache[newparser] = newtype = this_object();
|
ed8175 | 1999-12-11 | Martin Stjernholm | | else {
_t_obj_cache[newparser] = newtype = clone();
newtype->_parser_prog = newparser;
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | if (newparser->tag_set_eval) newtype->_p_cache = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
}
return newtype;
}
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | inline Parser get_parser (Context ctx, void|TagSet tag_set, void|Parser|PCode parent)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
{
Parser p;
if (_p_cache) {
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | TagSet tset = tag_set || ctx->tag_set;
if (parent && parent->is_RXML_Parser &&
tset == ctx->tag_set && sizeof (ctx->runtime_tags) &&
parent->clone && parent->type == this_object()) {
p = parent->clone (ctx, this_object(), tset, @_parser_args);
p->_parent = parent;
return p;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | PCacheObj pco = _p_cache[tset];
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | if (pco && pco->tag_set_gen == tset->generation) {
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if ((p = pco->free_parser)) {
pco->free_parser = p->_next_free;
p->data_callback = p->compile = 0;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | p->reset (ctx, this_object(), tset, @_parser_args);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | else
if (pco->clone_parser)
|
2bd21a | 2000-01-05 | Martin Stjernholm | | p = pco->clone_parser->clone (ctx, this_object(), tset, @_parser_args);
|
26ff09 | 2000-01-21 | Martin Stjernholm | | else if ((p = _parser_prog (0, this_object(), tset, @_parser_args))->clone)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | | p = (pco->clone_parser = p)->clone (ctx, this_object(), tset, @_parser_args);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | else {
pco = PCacheObj();
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | pco->tag_set_gen = tset->generation;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | _p_cache[tset] = pco;
|
26ff09 | 2000-01-21 | Martin Stjernholm | | if ((p = _parser_prog (0, this_object(), tset, @_parser_args))->clone)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | | p = (pco->clone_parser = p)->clone (ctx, this_object(), tset, @_parser_args);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
|
b2d01b | 2000-02-15 | Martin Stjernholm | | if (ctx->tag_set == tset && p->add_runtime_tag && sizeof (ctx->runtime_tags))
|
18abb3 | 2000-02-15 | Martin Stjernholm | | foreach (indices (ctx->runtime_tags), Tag tag)
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | p->add_runtime_tag (tag);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | else {
if ((p = free_parser)) {
free_parser = p->_next_free;
p->data_callback = p->compile = 0;
p->reset (ctx, this_object(), @_parser_args);
}
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | else if (clone_parser)
|
c6245b | 1999-12-31 | Martin Stjernholm | | p = clone_parser->clone (ctx, this_object(), @_parser_args);
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | | else if ((p = _parser_prog (0, this_object(), @_parser_args))->clone)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
c6245b | 1999-12-31 | Martin Stjernholm | | p = (clone_parser = p)->clone (ctx, this_object(), @_parser_args);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
p->_parent = parent;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | return p;
}
|
01e43b | 2000-01-14 | Martin Stjernholm | | mixed eval (string in, void|Context ctx, void|TagSet tag_set,
void|Parser|PCode parent, void|int dont_switch_ctx)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
{
mixed res;
if (!ctx) ctx = get_context();
if (_parser_prog == PNone) res = in;
else {
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | Parser p = get_parser (ctx, tag_set, parent);
|
01e43b | 2000-01-14 | Martin Stjernholm | | p->_parent = parent;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if (dont_switch_ctx) p->finish (in);
else p->write_end (in);
res = p->eval();
if (p->reset)
if (_p_cache) {
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | PCacheObj pco = _p_cache[tag_set || ctx->tag_set];
|
ed8175 | 1999-12-11 | Martin Stjernholm | | p->_next_free = pco->free_parser;
pco->free_parser = p;
}
else {
p->_next_free = free_parser;
free_parser = p;
}
}
if (ctx->type_check) type_check (res);
return res;
}
program _parser_prog = PNone;
|
c757c4 | 2000-01-08 | Martin Stjernholm | | array(mixed) _parser_args = ({});
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
mapping(program:Type) _t_obj_cache;
private Parser clone_parser;
private Parser free_parser;
private class PCacheObj
{
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | int tag_set_gen;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | Parser clone_parser;
Parser free_parser;
}
mapping(TagSet:PCacheObj) _p_cache;
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | | DECLARE_CNT (__count);
string _sprintf() {return "RXML.Type" + PAREN_CNT (__count);}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
26ff09 | 2000-01-21 | Martin Stjernholm | | static class TAny
|
01e43b | 2000-01-14 | Martin Stjernholm | |
{
inherit Type;
constant name = "*";
|
590b3c | 2000-02-05 | Martin Stjernholm | | constant quoting_scheme = "none";
|
8778dd | 2000-02-05 | Martin Stjernholm | |
|
590b3c | 2000-02-05 | Martin Stjernholm | | mixed convert (mixed val) {return val;}
|
8778dd | 2000-02-05 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | | string _sprintf() {return "RXML.t_any" + PAREN_CNT (__count);}
|
01e43b | 2000-01-14 | Martin Stjernholm | | }
|
26ff09 | 2000-01-21 | Martin Stjernholm | | TAny t_any = TAny();
|
01e43b | 2000-01-14 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | | static class TNone
{
inherit Type;
constant name = "none";
constant sequential = 1;
VoidType empty_value = Void;
constant quoting_scheme = "none";
void type_check (mixed val)
{
|
5ed013 | 2000-02-13 | Martin Stjernholm | | if (val != Void) parse_error ("A value is not accepted.\n");
|
49897a | 2000-02-13 | Martin Stjernholm | | }
mixed convert (mixed val)
{
type_check (val);
return Void;
}
string _sprintf() {return "RXML.t_none" + PAREN_CNT (__count);}
}
TNone t_none = TNone();
|
590b3c | 2000-02-05 | Martin Stjernholm | | static class TSame
{
inherit Type;
constant name = "same";
string _sprintf() {return "RXML.t_same" + PAREN_CNT (__count);}
}
TSame t_same = TSame();
|
26ff09 | 2000-01-21 | Martin Stjernholm | | static class TText
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
{
inherit Type;
constant name = "text/*";
constant sequential = 1;
constant empty_value = "";
constant free_text = 1;
|
590b3c | 2000-02-05 | Martin Stjernholm | | constant quoting_scheme = "none";
|
8778dd | 2000-02-05 | Martin Stjernholm | |
|
590b3c | 2000-02-05 | Martin Stjernholm | | string convert (mixed val)
|
8778dd | 2000-02-05 | Martin Stjernholm | | {
if (mixed err = catch {return (string) val;})
|
5ed013 | 2000-02-13 | Martin Stjernholm | | parse_error ("Couldn't convert value to text: " + describe_error (err));
|
8778dd | 2000-02-05 | Martin Stjernholm | | }
|
26ff09 | 2000-01-21 | Martin Stjernholm | | string _sprintf() {return "RXML.t_text" + PAREN_CNT (__count);}
|
01e43b | 2000-01-14 | Martin Stjernholm | | }
|
26ff09 | 2000-01-21 | Martin Stjernholm | | TText t_text = TText();
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8778dd | 2000-02-05 | Martin Stjernholm | | static class TXml
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
26ff09 | 2000-01-21 | Martin Stjernholm | | inherit TText;
|
8778dd | 2000-02-05 | Martin Stjernholm | | constant name = "text/xml";
|
590b3c | 2000-02-05 | Martin Stjernholm | | constant quoting_scheme = "xml";
|
8778dd | 2000-02-05 | Martin Stjernholm | |
|
590b3c | 2000-02-05 | Martin Stjernholm | | string quote (string val)
|
8778dd | 2000-02-05 | Martin Stjernholm | | {
return replace (
|
590b3c | 2000-02-05 | Martin Stjernholm | | val,
|
8778dd | 2000-02-05 | Martin Stjernholm | |
({"&", "<", ">", "\"", "\'",
"\000", "\001", "\002", "\003", "\004", "\005", "\006", "\007",
"\010", "\013", "\014", "\016", "\017",
"\020", "\021", "\022", "\023", "\024", "\025", "\026", "\027",
"\030", "\031", "\032", "\033", "\034", "\035", "\036", "\037",
}),
({"&", "<", ">", """, "'",
"�", "", "", "", "", "", "", "",
"", "", "", "", "",
"", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "",
}));
}
|
590b3c | 2000-02-05 | Martin Stjernholm | | string convert (mixed val, void|Type from)
{
if (mixed err = catch {val = (string) val;})
|
5ed013 | 2000-02-13 | Martin Stjernholm | | parse_error ("Couldn't convert value to text: " + describe_error (err));
|
710b48 | 2000-02-07 | Martin Stjernholm | | if (!from || from->quoting_scheme != quoting_scheme)
|
d8769c | 2000-02-08 | Martin Stjernholm | | val = quote ([string] val);
|
590b3c | 2000-02-05 | Martin Stjernholm | | return val;
}
|
8778dd | 2000-02-05 | Martin Stjernholm | | string _sprintf() {return "RXML.t_xml" + PAREN_CNT (__count);}
}
THtml t_xml = TXml();
static class THtml
{
inherit TXml;
|
01e43b | 2000-01-14 | Martin Stjernholm | | constant name = "text/html";
|
26ff09 | 2000-01-21 | Martin Stjernholm | | string _sprintf() {return "RXML.t_html" + PAREN_CNT (__count);}
|
01e43b | 2000-01-14 | Martin Stjernholm | | }
|
26ff09 | 2000-01-21 | Martin Stjernholm | | THtml t_html = THtml();
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
class VarRef
{
constant is_RXML_VarRef = 1;
string scope, var;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | static void create (string _scope, string _var) {scope = _scope, var = _var;}
|
af06d5 | 2000-01-12 | Martin Stjernholm | | int valid (Context ctx) {return ctx->exist_scope (scope);}
mixed get (Context ctx) {return ctx->get_var (var, scope);}
mixed set (Context ctx, mixed val) {return ctx->set_var (var, val, scope);}
void delete (Context ctx) {ctx->delete_var (var, scope);}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | string name() {return scope + "." + var;}
|
26ff09 | 2000-01-21 | Martin Stjernholm | | DECLARE_CNT (__count);
string _sprintf()
{return "RXML.VarRef(" + scope + "." + var + COMMA_CNT (__count) + ")";}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
class PCode
{
constant is_RXML_PCode = 1;
|
56532d | 1999-12-19 | Martin Stjernholm | | constant thrown_at_unwind = 1;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
array p_code = ({});
|
db0417 | 2000-01-14 | Martin Stjernholm | | int error_count;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | mixed eval (Context ctx)
{
}
|
56532d | 1999-12-19 | Martin Stjernholm | | function(Context:mixed) compile();
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
01e43b | 2000-01-14 | Martin Stjernholm | |
void report_error (string msg)
{
}
PCode|Parser _parent;
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
DECLARE_CNT (__count);
string _sprintf() {return "RXML.PCode" + PAREN_CNT (__count);}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
static class VoidType
{
mixed `+ (mixed... vals) {return sizeof (vals) ? predef::`+ (@vals) : this_object();}
mixed ``+ (mixed val) {return val;}
int `!() {return 1;}
|
2bd21a | 2000-01-05 | Martin Stjernholm | | string _sprintf() {return "RXML.Void";}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | };
VoidType Void = VoidType();
class ScanStream
{
private class Link
{
array data;
Link next;
}
private Link head = Link();
private Link tail = head;
private int next_token = 0;
private string end = "";
private int fin = 0;
array scan (string in, int finished);
void feed (string in)
{
#ifdef MODULE_DEBUG
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (fin) fatal_error ("Cannot feed data to a finished stream.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
array tokens = scan (end + in, 0);
end = [string] tokens[-1];
if (sizeof (tokens) > 1) {
tail->data = tokens[..sizeof (tokens) - 2];
tail = tail->next = Link();
}
}
void finish (void|string in)
{
if (in || !fin && sizeof (end)) {
#ifdef MODULE_DEBUG
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (in && fin) fatal_error ("Cannot feed data to a finished stream.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
fin = 1;
if (in) end += in;
tail->data = scan (end, 1);
tail = tail->next = Link();
}
}
void reset()
{
head = Link();
tail = head;
next_token = 0;
end = "";
fin = 0;
}
mixed read()
{
while (head->next)
if (next_token >= sizeof (head->data)) {
next_token = 0;
head = head->next;
}
else return head->data[next_token++];
return Void;
}
void unread (mixed... put_back)
{
int i = sizeof (put_back);
while (i) head->data[--next_token] = put_back[--i];
if (i) {
Link l = Link();
l->next = head, head = l;
|
56532d | 1999-12-19 | Martin Stjernholm | | l->data = allocate (next_token = max (i - 32, 0)) + put_back[..--i];
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
}
array read_all()
{
array data;
if (next_token) {
data = head->data[next_token..];
head = head->next;
next_token = 0;
}
else data = ({});
while (head->next) {
data += head->data;
head = head->next;
}
return data;
}
int finished()
{
return fin;
}
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | | DECLARE_CNT (__count);
string _sprintf() {return "RXML.ScanStream" + PAREN_CNT (__count);}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
5ed013 | 2000-02-13 | Martin Stjernholm | | static function(string,mixed...:void) _run_error = run_error;
static function(string,mixed...:void) _parse_error = parse_error;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | static program PXml;
|
3187d8 | 2000-01-28 | Martin Stjernholm | | static program PEnt;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | static program PExpr;
void _fix_module_ref (string name, mixed val)
{
mixed err = catch {
switch (name) {
|
8cb24d | 2000-02-13 | Martin Stjernholm | | case "PXml": PXml = [program] val; break;
|
3187d8 | 2000-01-28 | Martin Stjernholm | | case "PEnt": PEnt = [program] val; break;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | case "PExpr": PExpr = [program] val; break;
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | case "empty_tag_set": empty_tag_set = [object(TagSet)] val; break;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | default: error ("Herk\n");
}
};
if (err) werror (describe_backtrace (err));
}
|