a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
6c902e | 2000-03-17 | Martin Stjernholm | | static object Roxen;
|
4becf2 | 2000-03-19 | Martin Nilsson | | class RequestID { };
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
689dc6 | 2000-08-31 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
689dc6 | 2000-08-31 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d8769c | 2000-02-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
cd7d5f | 2000-02-16 | Martin Stjernholm | | #include <config.h>
|
e8dffa | 2001-05-14 | Per Hedbor | |
|
b48338 | 2000-06-30 | Martin Stjernholm | | #include <request_trace.h>
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #define MAGIC_HELP_ARG
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
e8dffa | 2001-05-14 | Per Hedbor | |
|
ec027c | 2000-03-16 | Martin Stjernholm | | #ifdef RXML_OBJ_DEBUG
|
f02d00 | 2000-03-18 | Martin Stjernholm | | # define MARK_OBJECT \
Debug.ObjectMarker __object_marker = Debug.ObjectMarker (this_object())
# define MARK_OBJECT_ONLY \
Debug.ObjectMarker __object_marker = Debug.ObjectMarker (0)
|
ec027c | 2000-03-16 | Martin Stjernholm | | #else
|
f02d00 | 2000-03-18 | Martin Stjernholm | | # define MARK_OBJECT
# define MARK_OBJECT_ONLY
|
ec027c | 2000-03-16 | Martin Stjernholm | | #endif
|
26ff09 | 2000-01-21 | Martin Stjernholm | | #ifdef OBJ_COUNT_DEBUG
|
f02d00 | 2000-03-18 | Martin Stjernholm | | # ifndef RXML_OBJ_DEBUG
# undef MARK_OBJECT
# undef MARK_OBJECT_ONLY
# define MARK_OBJECT \
mapping __object_marker = (["count": ++all_constants()->_obj_count])
# define MARK_OBJECT_ONLY \
mapping __object_marker = (["count": ++all_constants()->_obj_count])
# endif
# define OBJ_COUNT (__object_marker ? "[" + __object_marker->count + "]" : "")
|
26ff09 | 2000-01-21 | Martin Stjernholm | | #else
|
f02d00 | 2000-03-18 | Martin Stjernholm | | # define OBJ_COUNT ""
|
26ff09 | 2000-01-21 | Martin Stjernholm | | #endif
|
429307 | 2001-05-08 | Martin Stjernholm | | #ifdef PROFILE_PARSER
#define PROFILE_ENTER(ctx, what) do { \
ctx->profile[what] -= gethrtime(); \
/* if (what == "rxml internal") trace (1); */ \
} while (0)
#define PROFILE_LEAVE(ctx, what) do { \
/* if (what == "rxml internal") trace (0); */ \
ctx->profile[what] += gethrtime(); \
} while (0)
#define PROFILE_SWITCH(ctx, from, to) do { \
/* if (from == "rxml internal") trace (0); */ \
int now = gethrtime(); \
ctx->profile[from] += now; \
ctx->profile[to] -= now; \
/* if (to == "rxml internal") trace (1); */ \
} while (0)
#else
# define PROFILE_ENTER(ctx, what) do ; while (0)
# define PROFILE_LEAVE(ctx, what) do ; while (0)
# define PROFILE_SWITCH(ctx, from, to) do ; while (0)
#endif
|
d52f8f | 2001-05-19 | Martin Stjernholm | | #ifdef RXML_VERBOSE
# define TAG_DEBUG_TEST(flags) 1
#elif defined (DEBUG)
# define TAG_DEBUG_TEST(flags) ((flags) & FLAG_DEBUG)
#else
# define TAG_DEBUG_TEST(flags) 0
#endif
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #ifdef DEBUG
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | # define TAG_DEBUG(frame, msg, args...) \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | (TAG_DEBUG_TEST(frame->flags) && report_debug ("%O: " + (msg), (frame), args), 0)
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | # define DO_IF_DEBUG(code...) code
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #else
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | # define TAG_DEBUG(frame, msg, args...) 0
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | # define DO_IF_DEBUG(code...)
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #endif
|
d52f8f | 2001-05-19 | Martin Stjernholm | | #ifdef MODULE_DEBUG
# define DO_IF_MODULE_DEBUG(code...) code
#else
# define DO_IF_MODULE_DEBUG(code...)
#endif
|
f02d00 | 2000-03-18 | Martin Stjernholm | | #define HASH_INT2(m, n) (n < 65536 ? (m << 16) + n : sprintf ("%x,%x", m, n))
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
#define SCOPE_TYPE mapping(string:mixed)|object(Scope)
|
d4768a | 2001-05-18 | Martin Stjernholm | | #define UNWIND_STATE mapping(string|object:mixed|array)
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #define EVAL_ARGS_FUNC function(Context:mapping(string:mixed))
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
|
23a088 | 2000-08-12 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | class Tag
{
|
cece9e | 2000-01-11 | Martin Stjernholm | | constant is_RXML_Tag = 1;
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
f58572 | 2000-01-18 | Martin Stjernholm | | int flags;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
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 | |
|
f55a01 | 2001-03-14 | Martin Stjernholm | | Type def_arg_type = t_text (PEnt);
|
3187d8 | 2000-01-28 | Martin Stjernholm | |
|
429307 | 2001-05-08 | 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 | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
f55a01 | 2001-03-14 | Martin Stjernholm | |
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
f55a01 | 2001-03-14 | Martin Stjernholm | | array(Type) result_types = ({t_xml, t_html, t_text});
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
91c898 | 2000-03-11 | Martin Stjernholm | |
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
91c898 | 2000-03-11 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
938bfd | 2000-11-04 | Martin Stjernholm | | inline final object `() (mapping(string:mixed) args, void|mixed content)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
cf3c90 | 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;
|
23a088 | 2000-08-12 | Martin Stjernholm | | frame->content = zero_type (content) ? nil : content;
frame->result = nil;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | return frame;
}
|
c159ec | 2000-02-04 | Martin Stjernholm | | int eval_args (mapping(string:mixed) args, void|int dont_throw, void|Context ctx)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | | {
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
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
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | foreach (indices (args), string arg)
args[arg] = (atypes[arg] || def_arg_type)->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;
}
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #define MAKE_FRAME(_frame, _ctx, _parser, _args) \
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | make_new_frame: do { \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (UNWIND_STATE ustate = _ctx->unwind_state) \
if (ustate[_parser]) { \
_frame = [object/*(Frame)HMM*/] ustate[_parser][0]; \
m_delete (ustate, _parser); \
if (!sizeof (ustate)) _ctx->unwind_state = 0; \
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | break make_new_frame; \
} \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | _frame = `() (0, nil); \
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | DO_IF_DEBUG( \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (_args && ([mapping] (mixed) _args)["-debug-tag-"]) { \
_frame->flags |= FLAG_DEBUG; \
m_delete (_args, "-debug-tag-"); \
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | } \
); \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | TAG_DEBUG (_frame, "New frame\n"); \
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | } while (0)
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #define EVAL_FRAME(_frame, _ctx, _parser, _type, _args, _content, _res) \
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | eval_frame: do { \
mixed err = catch { \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | EVAL_ARGS_FUNC argfunc; \
if (!_frame->args) \
argfunc = _frame->_prepare (_ctx, _type, _args); \
_res = _frame->_eval (_ctx, _parser, _type, _content || ""); \
if (_parser->p_code) { \
_frame->args = argfunc; \
_parser->p_code->add (_frame); \
} \
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | break eval_frame; \
}; \
\
if (objectp (err) && ([object] err)->thrown_at_unwind) { \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | UNWIND_STATE ustate = _ctx->unwind_state; \
if (!ustate) ustate = _ctx->unwind_state = ([]); \
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | DO_IF_DEBUG ( \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (err != _frame) \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Unexpected unwind object catched.\n"); \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (ustate[_parser]) \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Clobbering unwind state for parser.\n"); \
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | ); \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | ustate[_parser] = ({_frame}); \
throw (_parser); \
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | } \
else { \
/* Will rethrow unknown errors. */ \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | _ctx->handle_exception (err, _parser); \
_res = nil; \
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | } \
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | } while (0)
final mixed handle_tag (TagSetParser parser, mapping(string:string) args,
void|string content)
{
Context ctx = parser->context;
object frame;
MAKE_FRAME (frame, ctx, parser, args);
if (!zero_type (frame->raw_tag_text))
frame->raw_tag_text = parser->raw_tag_text();
mixed result;
EVAL_FRAME (frame, ctx, parser, parser->type, args, content, result);
return result;
}
final array _p_xml_handle_tag (object parser, mapping(string:string) args,
void|string content)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | Type type = parser->type;
if (type->handle_literals) parser->handle_literal();
|
d4768a | 2001-05-18 | Martin Stjernholm | | else if (parser->p_code) parser->p_code_literal();
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
56532d | 1999-12-19 | Martin Stjernholm | | Context ctx = parser->context;
|
9d80e8 | 2000-02-11 | Martin Stjernholm | |
|
f99720 | 2000-01-18 | Martin Stjernholm | | object frame;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | MAKE_FRAME (frame, ctx, parser, args);
|
56532d | 1999-12-19 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (!zero_type (frame->raw_tag_text))
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | frame->raw_tag_text = parser->current_input();
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | mixed result;
EVAL_FRAME (frame, ctx, parser, type, args, content, result);
|
56532d | 1999-12-19 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (result != nil) {
if (type->free_text && !parser->p_code) return ({result});
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | parser->add_value (result);
|
f0ce41 | 2000-03-06 | Martin Stjernholm | | }
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | return ({});
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | final array _p_xml_handle_pi_tag (object parser, string content)
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | {
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | Type type = parser->type;
if (type->handle_literals) parser->handle_literal();
|
d4768a | 2001-05-18 | Martin Stjernholm | | else if (parser->p_code) parser->p_code_literal();
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | | sscanf (content, "%[ \t\n\r]%s", string ws, string rest);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (ws == "" && rest != "") {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (!type->free_text)
return utils->unknown_pi_tag_error (parser, content);
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | return 0;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | Context ctx = parser->context;
|
87fb7e | 2000-03-25 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | object frame;
MAKE_FRAME (frame, ctx, parser, 0);
if (!zero_type (frame->raw_tag_text))
frame->raw_tag_text = parser->current_input();
mixed result;
EVAL_FRAME (frame, ctx, parser, type, 0, content, result);
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (result != nil) {
if (type->free_text && !parser->p_code) return ({result});
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | parser->add_value (result);
}
return ({});
|
87fb7e | 2000-03-25 | Martin Stjernholm | | }
|
f02d00 | 2000-03-18 | Martin Stjernholm | | MARK_OBJECT;
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | string _sprintf()
{
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | return "RXML.Tag(" + [string] this_object()->name +
(this_object()->plugin_name ? "#" + [string] this_object()->plugin_name : "") +
([int] this_object()->flags & FLAG_PROC_INSTR ? " [PI]" : "") + ")" +
OBJ_COUNT;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
}
class TagSet
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | 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 | |
|
429307 | 2001-05-08 | 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;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
660cb5 | 2000-01-12 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | int generation = 1;
|
f02d00 | 2000-03-18 | Martin Stjernholm | | int id_number;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | static void create (string _name, void|array(Tag) _tags)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
{
|
f02d00 | 2000-03-18 | Martin Stjernholm | | id_number = ++tag_set_count;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | name = _name;
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (_tags) add_tags (_tags);
|
f02d00 | 2000-03-18 | Martin Stjernholm | | #ifdef RXML_OBJ_DEBUG
__object_marker->create (this_object());
#endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
void add_tag (Tag tag)
{
|
e82104 | 2000-08-17 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (!stringp (tag->name))
error ("Trying to register a tag %O without a name.\n", tag);
|
055e93 | 2001-04-09 | Per Hedbor | | if (!callablep (tag->Frame) && !tag->plugin_name)
|
e82104 | 2000-08-17 | Martin Stjernholm | | error ("Trying to register a tag %O without a Frame class or function.\n", tag);
|
1a65d9 | 2000-08-30 | Martin Stjernholm | | if (tag->name[..3] != "!--#" &&
replace (tag->name, "#<>& \t\n\r" / "", ({""}) * 8) != tag->name)
error ("Invalid character(s) in name for tag %O.\n", tag);
|
e82104 | 2000-08-17 | Martin Stjernholm | | #endif
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (tag->flags & FLAG_PROC_INSTR) {
if (!proc_instrs) proc_instrs = ([]);
if (tag->plugin_name) proc_instrs[tag->name + "#" + tag->plugin_name] = tag;
else proc_instrs[tag->name] = tag;
}
else
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)
{
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | foreach (_tags, Tag tag) {
|
e82104 | 2000-08-17 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (!stringp (tag->name))
error ("Trying to register a tag %O without a name.\n", tag);
|
055e93 | 2001-04-09 | Per Hedbor | | if (!callablep (tag->Frame)&& !tag->plugin_name)
|
e82104 | 2000-08-17 | Martin Stjernholm | | error ("Trying to register a tag %O without a Frame class or function.\n", tag);
|
1a65d9 | 2000-08-30 | Martin Stjernholm | | if (tag->name[..3] != "!--#" &&
replace (tag->name, "#<>& \t\n\r" / "", ({""}) * 8) != tag->name)
error ("Invalid character(s) in name for tag %O.\n", tag);
|
e82104 | 2000-08-17 | Martin Stjernholm | | #endif
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (tag->flags & FLAG_PROC_INSTR) {
if (!proc_instrs) proc_instrs = ([]);
if (tag->plugin_name) proc_instrs[tag->name + "#" + tag->plugin_name] = tag;
else proc_instrs[tag->name] = tag;
}
else
if (tag->plugin_name) tags[tag->name + "#" + tag->plugin_name] = tag;
else tags[tag->name] = tag;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | changed();
}
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | void remove_tag (string|Tag tag, void|int proc_instr)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
if (stringp (tag))
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (proc_instr) {
if (proc_instrs) m_delete (proc_instrs, tag);
}
else
m_delete (tags, tag);
else {
string n;
if (tag->flags & FLAG_PROC_INSTR) {
if (proc_instrs && !zero_type (n = search (tags, [object(Tag)] tag)))
m_delete (proc_instrs, n);
}
else
if (!zero_type (n = search (tags, [object(Tag)] tag)))
m_delete (tags, n);
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | changed();
}
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | local Tag get_local_tag (string name, void|int proc_instr)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | return proc_instr ? proc_instrs && proc_instrs[name] : tags[name];
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local array(Tag) get_local_tags()
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | array(Tag) res = values (tags);
if (proc_instrs) res += values (proc_instrs);
return res;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local Tag get_tag (string name, void|int proc_instr)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | | {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (object(Tag) def = get_local_tag (name, proc_instr))
|
56ffee | 2000-01-12 | Martin Stjernholm | | return def;
foreach (imported, TagSet tag_set)
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (object(Tag) tag = [object(Tag)] tag_set->get_tag (name, proc_instr))
return tag;
|
56ffee | 2000-01-12 | Martin Stjernholm | | return 0;
|
da54bd | 2000-01-08 | Martin Stjernholm | | }
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local int has_tag (Tag tag)
{
return !!get_tag (tag->name, tag->flags & FLAG_PROC_INSTR);
}
local multiset(string) get_tag_names()
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
{
return `| ((multiset) indices (tags), @imported->get_tag_names());
}
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local multiset(string) get_proc_instr_names()
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
{
return `| (proc_instrs ? (multiset) indices (proc_instrs) : (<>),
@imported->get_proc_instr_names());
}
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local Tag get_overridden_tag (Tag overrider)
|
56ffee | 2000-01-12 | Martin Stjernholm | |
|
2e0a6d | 2000-07-06 | Martin Stjernholm | |
|
da54bd | 2000-01-08 | Martin Stjernholm | | {
|
51f88b | 2000-06-23 | Martin Stjernholm | | if (!mappingp (overridden_tag_lookup))
overridden_tag_lookup = set_weak_flag (([]), 1);
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | Tag tag;
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if (zero_type (tag = overridden_tag_lookup[overrider])) {
string overrider_name = overrider->plugin_name ?
overrider->plugin_name + "#" + overrider->name : overrider->name;
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | tag = overridden_tag_lookup[overrider] =
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | overrider->flags & FLAG_PROC_INSTR ?
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | find_overridden_proc_instr (overrider, overrider_name) :
find_overridden_tag (overrider, overrider_name);
}
|
51f88b | 2000-06-23 | Martin Stjernholm | | return tag;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | }
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local array(Tag) get_overridden_tags (string name, void|int proc_instr)
|
56ffee | 2000-01-12 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
56ffee | 2000-01-12 | Martin Stjernholm | | {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (object(Tag) def = get_local_tag (name, proc_instr))
return ({def}) + imported->get_overridden_tags (name, proc_instr) * ({});
else
return imported->get_overridden_tags (name, proc_instr) * ({});
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | }
void add_string_entities (mapping(string:string) entities)
|
fe628d | 2001-03-01 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | {
if (string_entities) string_entities |= entities;
else string_entities = entities + ([]);
changed();
}
void clear_string_entities()
{
string_entities = 0;
changed();
}
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local mapping(string:string) get_string_entities()
|
2e0a6d | 2000-07-06 | Martin Stjernholm | |
{
if (string_entities)
return `+(@imported->get_string_entities(), string_entities);
else
return `+(@imported->get_string_entities(), ([]));
|
56ffee | 2000-01-12 | Martin Stjernholm | | }
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local mapping(string:Tag) get_plugins (string name, void|int proc_instr)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | | {
mapping(string:Tag) res;
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (proc_instr) {
if (!pi_plugins) pi_plugins = ([]);
if ((res = pi_plugins[name])) return res;
low_get_pi_plugins (name + "#", res = ([]));
return pi_plugins[name] = res;
}
else {
if (!plugins) plugins = ([]);
if ((res = plugins[name])) return res;
low_get_plugins (name + "#", res = ([]));
return plugins[name] = res;
}
|
c159ec | 2000-02-04 | Martin Stjernholm | | }
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local int has_effective_tags (TagSet tset)
|
87fb7e | 2000-03-25 | Martin Stjernholm | |
{
return tset == top_tag_set && !got_local_tags;
}
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local mixed `->= (string var, mixed val)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
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);
|
87fb7e | 2000-03-25 | Martin Stjernholm | | top_tag_set = sizeof (imported) && imported[0];
|
ed8175 | 1999-12-11 | Martin Stjernholm | | break;
default:
::`->= (var, val);
}
changed();
return val;
}
|
689dc6 | 2000-08-31 | Martin Stjernholm | | local mixed `[]= (string var, mixed val) {return `->= (var, val);}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
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;
|
51f88b | 2000-06-23 | Martin Stjernholm | | overridden_tag_lookup = 0;
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | plugins = pi_plugins = 0;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | (notify_funcs -= ({0}))();
set_weak_flag (notify_funcs, 1);
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | got_local_tags = sizeof (tags) || (proc_instrs && sizeof (proc_instrs));
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
308357 | 2001-04-24 | Martin Nilsson | | function(Backtrace,Type:string) handle_run_error =
lambda (Backtrace err, Type type)
|
f5bd9e | 2001-04-25 | Martin Nilsson | |
|
308357 | 2001-04-24 | Martin Nilsson | | {
|
f5bd9e | 2001-04-25 | Martin Nilsson | | string result;
foreach(imported, TagSet tag_set) {
result = tag_set->handle_run_error(err, type);
if(result) return result;
}
return 0;
|
308357 | 2001-04-24 | Martin Nilsson | | };
function(Backtrace,Type:string) handle_parse_error =
lambda (Backtrace err, Type type)
|
f5bd9e | 2001-04-25 | Martin Nilsson | |
|
308357 | 2001-04-24 | Martin Nilsson | | {
|
f5bd9e | 2001-04-25 | Martin Nilsson | | string result;
foreach(imported, TagSet tag_set) {
result = tag_set->handle_parse_error(err, type);
if(result) return result;
}
return 0;
|
308357 | 2001-04-24 | Martin Nilsson | | };
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
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());
}
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | static mapping(string:Tag) tags = ([]), proc_instrs;
|
2e0a6d | 2000-07-06 | Martin Stjernholm | |
static mapping(string:string) string_entities;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
87fb7e | 2000-03-25 | Martin Stjernholm | | static TagSet top_tag_set;
static int got_local_tags;
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
87fb7e | 2000-03-25 | 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;
}
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | static mapping(Tag:Tag) overridden_tag_lookup;
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | Tag find_overridden_tag (Tag overrider, string overrider_name)
|
51f88b | 2000-06-23 | Martin Stjernholm | | {
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if (tags[overrider_name] == overrider) {
|
51f88b | 2000-06-23 | Martin Stjernholm | | foreach (imported, TagSet tag_set)
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if (object(Tag) overrider = tag_set->get_tag (overrider_name))
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | return overrider;
|
51f88b | 2000-06-23 | Martin Stjernholm | | }
else {
int found = 0;
foreach (imported, TagSet tag_set)
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if (object(Tag) subtag = tag_set->get_tag (overrider_name))
|
51f88b | 2000-06-23 | Martin Stjernholm | | if (found) return subtag;
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | else if (subtag == overrider)
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if ((subtag = tag_set->find_overridden_tag (
overrider, overrider_name)))
|
51f88b | 2000-06-23 | Martin Stjernholm | | return subtag;
else found = 1;
}
return 0;
}
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | Tag find_overridden_proc_instr (Tag overrider, string overrider_name)
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | {
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if (proc_instrs && proc_instrs[overrider_name] == overrider) {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | foreach (imported, TagSet tag_set)
|
429307 | 2001-05-08 | Martin Stjernholm | | if (object(Tag) overrider = tag_set->get_tag (overrider_name, 1))
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | return overrider;
}
else {
int found = 0;
foreach (imported, TagSet tag_set)
|
429307 | 2001-05-08 | Martin Stjernholm | | if (object(Tag) subtag = tag_set->get_tag (overrider_name, 1))
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (found) return subtag;
else if (subtag == overrider)
|
09b6c5 | 2001-01-24 | Martin Stjernholm | | if ((subtag = tag_set->find_overridden_proc_instr (
overrider, overrider_name)))
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | return subtag;
else found = 1;
}
return 0;
}
|
777ff2 | 2000-02-15 | Martin Stjernholm | | void call_prepare_funs (Context ctx)
{
if (!prepare_funs) prepare_funs = get_prepare_funs();
(prepare_funs -= ({0})) (ctx);
}
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | static mapping(string:mapping(string:Tag)) plugins, pi_plugins;
|
c159ec | 2000-02-04 | Martin Stjernholm | |
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;
}
}
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | void low_get_pi_plugins (string prefix, mapping(string:Tag) res)
{
for (int i = sizeof (imported) - 1; i >= 0; i--)
imported[i]->low_get_pi_plugins (prefix, res);
if (proc_instrs)
foreach (indices (proc_instrs), string name)
if (name[..sizeof (prefix) - 1] == prefix) {
Tag tag = proc_instrs[name];
if (tag->plugin_name) res[[string] tag->plugin_name] = tag;
}
}
|
2bd21a | 2000-01-05 | Martin Stjernholm | | string _sprintf()
{
|
f02d00 | 2000-03-18 | Martin Stjernholm | | return sprintf ("RXML.TagSet(%O,%d)%s", name, id_number, OBJ_COUNT);
|
2bd21a | 2000-01-05 | Martin Stjernholm | | }
|
ec027c | 2000-03-16 | Martin Stjernholm | |
|
f02d00 | 2000-03-18 | Martin Stjernholm | | MARK_OBJECT_ONLY;
|
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)
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
710b48 | 2000-02-07 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
ec860d | 2001-03-13 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
f55a01 | 2001-03-14 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
f55a01 | 2001-03-14 | Martin Stjernholm | |
|
fe628d | 2001-03-01 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
2b5f47 | 2001-02-11 | 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);
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
string _sprintf() {return "RXML.Value";}
|
af06d5 | 2000-01-12 | Martin Stjernholm | | }
class Scope
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
af06d5 | 2000-01-12 | Martin Stjernholm | | {
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | mixed `[] (string var, void|Context ctx,
void|string scope_name, void|Type type)
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
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)
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
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)
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
|
5ed013 | 2000-02-13 | Martin Stjernholm | | {parse_error ("Cannot list variables" + _in_the_scope (scope_name) + ".\n");}
|
01e43b | 2000-01-14 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | void _m_delete (string var, void|Context ctx, void|string scope_name)
{
if (m_delete != local::m_delete)
m_delete (var, ctx, scope_name);
else
parse_error ("Cannot delete variable" + _in_the_scope (scope_name) + ".\n");
}
|
01e43b | 2000-01-14 | Martin Stjernholm | | void m_delete (string var, void|Context ctx, void|string scope_name)
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
{_m_delete (var, ctx, scope_name);}
|
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 | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | class Context
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
Frame frame;
|
ffa693 | 2000-02-20 | Martin Stjernholm | | int frame_depth;
int max_frame_depth = 100;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | 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 | |
|
c8021c | 2000-02-15 | Martin Nilsson | | #ifdef OLD_RXML_COMPAT
int compatible_scope = 0;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
#endif
#ifdef PROFILE_PARSER
mapping(string:int) profile = ([]);
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | #endif
|
8abef5 | 2001-02-11 | Martin Stjernholm | | array(string|int) parse_user_var (string var, void|string|int scope_name)
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
9390fe | 2000-01-23 | Martin Nilsson | | {
|
c8021c | 2000-02-15 | Martin Nilsson | | #ifdef OLD_RXML_COMPAT
|
2cab1b | 2001-03-05 | Martin Nilsson | | if (compatible_scope && !intp(scope_name))
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | return ({scope_name || "form", var});
|
c8021c | 2000-02-15 | Martin Nilsson | | #endif
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
1766fe | 2001-02-11 | Martin Nilsson | | array(string|int) splitted;
|
0aa54b | 2001-02-11 | Martin Stjernholm | | if(has_value(var, "..")) {
|
6ec8cc | 2001-02-11 | Martin Stjernholm | |
|
0aa54b | 2001-02-11 | Martin Stjernholm | | string coded = replace (var, "\0", "\0\0");
if (coded != var)
splitted = map (replace (coded, "..", "\0p") / ".",
replace, ({"\0p", "\0\0"}), ({".", "\0"}));
else
splitted = map (replace (var, "..", "\0") / ".", replace, "\0", ".");
}
|
1766fe | 2001-02-11 | Martin Nilsson | | else
splitted = var / ".";
|
8abef5 | 2001-02-11 | Martin Stjernholm | | if (stringp (scope_name))
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | splitted = ({scope_name}) + splitted;
|
8abef5 | 2001-02-11 | Martin Stjernholm | | else if (sizeof (splitted) == 1)
splitted = ({scope_name || "_"}) + splitted;
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
for (int i = 2; i < sizeof (splitted); i++)
if (sscanf (splitted[i], "%d%*c", int d) == 1) splitted[i] = d;
return splitted;
|
9390fe | 2000-01-23 | Martin Nilsson | | }
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | local mixed get_var (string|array(string|int) var, void|string scope_name,
void|Type want_type)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
8778dd | 2000-02-05 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | {
#ifdef MODULE_DEBUG
if (arrayp (var) ? !sizeof (var) : !stringp (var))
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Invalid variable specifier.\n");
|
0ddf4e | 2000-09-15 | Martin Nilsson | | #endif
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | if (!scope_name) scope_name = "_";
if (SCOPE_TYPE vars = scopes[scope_name])
return rxml_index (vars, var, scope_name, this_object(), want_type);
else if (scope_name == "_") parse_error ("No current scope.\n");
else parse_error ("Unknown scope %O.\n", scope_name);
|
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)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
9390fe | 2000-01-23 | Martin Nilsson | | {
if(!var || !sizeof(var)) return ([])[0];
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | array(string|int) splitted = parse_user_var (var, scope_name);
return get_var (splitted[1..], splitted[0], want_type);
|
9390fe | 2000-01-23 | Martin Nilsson | | }
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | local mixed set_var (string|array(string|int) var, mixed val, void|string scope_name)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (arrayp (var) ? !sizeof (var) : !stringp (var))
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Invalid variable specifier.\n");
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | #endif
if (!scope_name) scope_name = "_";
if (SCOPE_TYPE vars = scopes[scope_name]) {
string|int index;
if (arrayp (var))
if (sizeof (var) > 1) {
index = var[-1];
var = var[..sizeof (var) - 1];
vars = rxml_index (vars, var, scope_name, this_object());
scope_name += "." + (array(string)) var * ".";
}
else index = var[0];
else index = var;
if (objectp (vars) && vars->`[]=)
return ([object(Scope)] vars)->`[]= (index, val, this_object(), scope_name);
else if (mappingp (vars) || multisetp (vars))
return vars[index] = val;
else if (arrayp (vars))
if (intp (index) && index)
if ((index < 0 ? -index : index) > sizeof (vars))
parse_error( "Index %d out of range for array of size %d in %s.\n",
index, sizeof (val), scope_name );
else if (index < 0)
return vars[index] = val;
else
return vars[index - 1] = val;
else
parse_error( "Cannot index the array in %s with %O.\n", scope_name, index );
|
01e43b | 2000-01-14 | Martin Stjernholm | | else
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | parse_error ("%s is %O which cannot be indexed with %O.\n",
scope_name, vars, index);
}
else if (scope_name == "_") parse_error ("No current scope.\n");
else parse_error ("Unknown scope %O.\n", scope_name);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
9390fe | 2000-01-23 | Martin Nilsson | | mixed user_set_var (string var, mixed val, void|string scope_name)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
9390fe | 2000-01-23 | Martin Nilsson | | {
|
c8021c | 2000-02-15 | Martin Nilsson | | if(!var || !sizeof(var)) parse_error ("No variable specified.\n");
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | array(string|int) splitted = parse_user_var (var, scope_name);
return set_var(splitted[1..], val, splitted[0]);
|
9390fe | 2000-01-23 | Martin Nilsson | | }
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | local void delete_var (string|array(string|int) var, void|string scope_name)
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (arrayp (var) ? !sizeof (var) : !stringp (var))
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Invalid variable specifier.\n");
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | #endif
if (!scope_name) scope_name = "_";
if (SCOPE_TYPE vars = scopes[scope_name]) {
if (arrayp (var))
if (sizeof (var) > 1) {
string|int last = var[-1];
var = var[..sizeof (var) - 1];
vars = rxml_index (vars, var, scope_name, this_object());
scope_name += "." + (array(string)) var * ".";
var = last;
}
else var = var[0];
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | if (objectp (vars) && vars->_m_delete)
([object(Scope)] vars)->_m_delete (var, this_object(), scope_name);
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | else if (mappingp (vars))
|
01e43b | 2000-01-14 | Martin Stjernholm | | m_delete ([mapping(string:mixed)] vars, var);
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | else if (multisetp (vars))
vars[var] = 0;
else
parse_error ("Cannot remove the index %O from the %t in %s.\n",
var, vars, scope_name);
}
else if (scope_name == "_") parse_error ("No current scope.\n");
|
9290ad | 2000-02-20 | Martin Stjernholm | | else parse_error ("Unknown scope %O.\n", scope_name);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
291ade | 2000-01-25 | Martin Stjernholm | | void user_delete_var (string var, void|string scope_name)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
9390fe | 2000-01-23 | Martin Nilsson | | {
|
291ade | 2000-01-25 | Martin Stjernholm | | if(!var || !sizeof(var)) return;
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | array(string|int) splitted = parse_user_var (var, scope_name);
delete_var(splitted[1..], splitted[0]);
|
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);
|
9290ad | 2000-02-20 | Martin Stjernholm | | else if ((<0, "_">)[scope_name]) parse_error ("No current scope.\n");
else parse_error ("Unknown scope %O.\n", scope_name);
|
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)
|
429307 | 2001-05-08 | 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
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (!oldvars) fatal_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["_"]) {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | string scope_name = search (scopes, vars);
do
|
3e5934 | 2000-01-18 | Martin Stjernholm | | if (scope_name != "_") return scope_name;
|
d52f8f | 2001-05-19 | Martin Stjernholm | | while ((scope_name = search (scopes, vars, 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 | | {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (tag->plugin_name)
fatal_error ("Can't currently handle adding of plugin tags at runtime.\n");
#endif
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | if (!new_runtime_tags) new_runtime_tags = NewRuntimeTags();
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | new_runtime_tags->add_tag (tag);
|
af06d5 | 2000-01-12 | Martin Stjernholm | | }
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | void remove_runtime_tag (string|Tag tag, void|int proc_instr)
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
af06d5 | 2000-01-12 | Martin Stjernholm | | {
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | if (!new_runtime_tags) new_runtime_tags = NewRuntimeTags();
|
87fb7e | 2000-03-25 | Martin Stjernholm | | if (objectp (tag)) tag = tag->name;
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | new_runtime_tags->remove_tag (tag);
|
af06d5 | 2000-01-12 | Martin Stjernholm | | }
|
18abb3 | 2000-02-15 | Martin Stjernholm | | multiset(Tag) get_runtime_tags()
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | {
|
87fb7e | 2000-03-25 | Martin Stjernholm | | mapping(string:Tag) tags = runtime_tags;
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (new_runtime_tags) tags = new_runtime_tags->filter_tags (tags);
|
87fb7e | 2000-03-25 | Martin Stjernholm | | return mkmultiset (values (tags));
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | }
|
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++;
|
c64acf | 2000-02-17 | Martin Stjernholm | | if (objectp (err) && err->is_RXML_Backtrace) {
|
140f36 | 2000-10-19 | Martin Stjernholm | | evaluator->error_count++;
if (evaluator->report_error && evaluator->recover_errors &&
evaluator->type->free_text) {
string msg;
|
f5bd9e | 2001-04-25 | Martin Nilsson | | if (id && id->conf) {
|
140f36 | 2000-10-19 | Martin Stjernholm | | msg = err->type == "help" ? err->msg :
(err->type == "run" ?
([function(Backtrace,Type:string)]
|
308357 | 2001-04-24 | Martin Nilsson | | tag_set->handle_run_error) :
|
140f36 | 2000-10-19 | Martin Stjernholm | | ([function(Backtrace,Type:string)]
|
308357 | 2001-04-24 | Martin Nilsson | | tag_set->handle_parse_error)
|
140f36 | 2000-10-19 | Martin Stjernholm | | ) ([object(Backtrace)] err, evaluator->type);
|
f5bd9e | 2001-04-25 | Martin Nilsson | | if(!msg)
msg = describe_error(err);
}
|
140f36 | 2000-10-19 | Martin Stjernholm | | else
msg = err->msg;
if (evaluator->report_error (msg))
return;
|
01e43b | 2000-01-14 | Martin Stjernholm | | }
|
140f36 | 2000-10-19 | Martin Stjernholm | | throw (err);
|
c757c4 | 2000-01-08 | Martin Stjernholm | | }
|
8cb24d | 2000-02-13 | Martin Stjernholm | | else throw_fatal (err);
|
c757c4 | 2000-01-08 | Martin Stjernholm | | }
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
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
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (!frame->vars) fatal_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 | | }
}
|
d52f8f | 2001-05-19 | Martin Stjernholm | | #define ENTER_SCOPE(ctx, frame) \
(frame->vars && frame->vars != ctx->scopes["_"] && ctx->enter_scope (frame))
#define LEAVE_SCOPE(ctx, frame) \
(frame->vars && ctx->leave_scope (frame))
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
87fb7e | 2000-03-25 | Martin Stjernholm | | mapping(string:Tag) runtime_tags = ([]);
|
24f9e8 | 2000-08-05 | 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;
|
f02d00 | 2000-03-18 | Martin Stjernholm | | #ifdef RXML_OBJ_DEBUG
__object_marker->create (this_object());
#endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | UNWIND_STATE 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 | |
|
91c898 | 2000-03-11 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
f02d00 | 2000-03-18 | Martin Stjernholm | | MARK_OBJECT_ONLY;
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
f02d00 | 2000-03-18 | Martin Stjernholm | | string _sprintf() {return "RXML.Context" + OBJ_COUNT;}
|
ec027c | 2000-03-16 | 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 | | }
|
ec027c | 2000-03-16 | Martin Stjernholm | | static class NewRuntimeTags
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
ec027c | 2000-03-16 | Martin Stjernholm | | {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | static mapping(string:Tag) add_tags;
static mapping(string:int|string) remove_tags;
void add_tag (Tag tag)
{
if (!add_tags) add_tags = ([]);
if (tag->flags & FLAG_PROC_INSTR) {
add_tags["?" + tag->name] = tag;
if (remove_tags) m_delete (remove_tags, "?" + tag->name);
}
else {
add_tags[tag->name] = tag;
if (remove_tags) m_delete (remove_tags, tag->name);
}
}
void remove_tag (string name, int proc_instr)
{
if (!remove_tags) remove_tags = ([]);
if (proc_instr) remove_tags["?" + name] = name;
else remove_tags[name] = 1;
}
array(Tag) added_tags()
{
if (!add_tags) return ({});
if (remove_tags) return values (add_tags - remove_tags);
return values (add_tags);
}
array(string) removed_tags()
{
return remove_tags ? indices (filter (remove_tags, intp)) : ({});
}
array(string) removed_pi_tags()
{
return remove_tags ? values (remove_tags) - ({1}) : ({});
}
mapping(string:Tag) filter_tags (mapping(string:Tag) tags)
{
if (add_tags) tags |= add_tags;
if (remove_tags) tags -= remove_tags;
return tags;
}
|
ec027c | 2000-03-16 | 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;
|
51f88b | 2000-06-23 | Martin Stjernholm | | void create (void|string _type, void|string _msg, void|Context _context,
void|array _backtrace)
|
8cb24d | 2000-02-13 | Martin Stjernholm | | {
type = _type;
msg = _msg;
if (context = _context || get_context()) {
frame = context->frame;
current_var = context->current_var;
}
|
51f88b | 2000-06-23 | Martin Stjernholm | | if (_backtrace) backtrace = _backtrace;
else {
backtrace = predef::backtrace();
backtrace = backtrace[..sizeof (backtrace) - 2];
}
|
8cb24d | 2000-02-13 | Martin Stjernholm | | }
string describe_rxml_backtrace (void|int no_msg)
{
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | String.Buffer txt = String.Buffer();
txt->add (no_msg ? "" : "RXML" + (type ? " " + type : "") + " error");
|
8cb24d | 2000-02-13 | Martin Stjernholm | | if (context) {
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (!no_msg) txt->add (": " + (msg || "(no error message)\n"));
if (current_var) txt->add (" | &" + current_var + ";\n");
|
8cb24d | 2000-02-13 | Martin Stjernholm | | for (Frame f = frame; f; f = f->up) {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | string name;
if (f->tag) name = f->tag->name;
|
8cb24d | 2000-02-13 | Martin Stjernholm | | else if (!f->up) break;
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | else name = "(unknown)";
if (f->flags & FLAG_PROC_INSTR)
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | txt->add (" | <?" + name + "?>\n");
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | else {
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | txt->add (" | <" + name);
if (mappingp (f->args))
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | foreach (sort (indices (f->args)), string arg) {
mixed val = f->args[arg];
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | txt->add (" " + arg + "=");
if (arrayp (val)) txt->add (map (val, error_print_val) * ",");
else txt->add (error_print_val (val));
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | else txt->add (" (no argmap)");
txt->add (">\n");
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | }
|
8cb24d | 2000-02-13 | Martin Stjernholm | | }
}
else
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (!no_msg) txt->add (" (no context): " + (msg || "(no error message)\n"));
return txt->get();
|
8cb24d | 2000-02-13 | Martin Stjernholm | | }
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;
}
}
|
1c73f6 | 2000-03-04 | Martin Stjernholm | | string _sprintf() {return "RXML.Backtrace(" + (type || "") + ")";}
|
8cb24d | 2000-02-13 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
#if constant (thread_create)
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | private Thread.Local _context = Thread.Local();
|
5ad529 | 2000-03-09 | Martin Stjernholm | | local void set_context (Context ctx) {_context->set (ctx);}
local Context get_context() {return [object(Context)] _context->get();}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #else
private Context _context;
|
5ad529 | 2000-03-09 | Martin Stjernholm | | local void set_context (Context ctx) {_context = ctx;}
local Context get_context() {return _context;}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #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(); \
|
429307 | 2001-05-08 | Martin Stjernholm | | } \
PROFILE_ENTER (ctx, "rxml internal");
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
#define LEAVE_CONTEXT() \
|
429307 | 2001-05-08 | Martin Stjernholm | | PROFILE_LEAVE (get_context(), "rxml internal"); \
|
ed8175 | 1999-12-11 | Martin Stjernholm | | 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(); \
|
429307 | 2001-05-08 | Martin Stjernholm | | set_context (ctx); \
PROFILE_ENTER (ctx, "rxml internal");
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
#define LEAVE_CONTEXT() \
|
429307 | 2001-05-08 | Martin Stjernholm | | PROFILE_LEAVE (get_context(), "rxml internal"); \
|
ed8175 | 1999-12-11 | Martin Stjernholm | | set_context (__old_ctx);
#endif
|
76cbfb | 2000-02-04 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_NONE = 0x00000000;
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
ac6977 | 2000-09-08 | Martin Stjernholm | | constant FLAG_DEBUG = 0x40000000;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | constant FLAG_PROC_INSTR = 0x00000010;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | | constant FLAG_COMPAT_PARSE = 0x00000002;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | |
constant FLAG_NO_PREFIX = 0x00000004;
|
cece9e | 2000-01-11 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | | constant FLAG_SOCKET_TAG = 0x00000008;
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_DONT_PREPARSE = 0x00000040;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_POSTPARSE = 0x00000080;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
c159ec | 2000-02-04 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | | constant FLAG_EMPTY_ELEMENT = 0x00000001;
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_PARENT_SCOPE = 0x00000100;
|
91c898 | 2000-03-11 | 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;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_STREAM_CONTENT = 0x00000800;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
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;
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | |
|
140f36 | 2000-10-19 | Martin Stjernholm | | constant FLAG_DONT_RECOVER = 0x00002000;
|
4d62ba | 2000-08-15 | Martin Stjernholm | |
|
140f36 | 2000-10-19 | Martin Stjernholm | |
|
4d62ba | 2000-08-15 | Martin Stjernholm | |
|
140f36 | 2000-10-19 | Martin Stjernholm | |
|
4d62ba | 2000-08-15 | Martin Stjernholm | |
|
140f36 | 2000-10-19 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
140f36 | 2000-10-19 | Martin Stjernholm | |
constant FLAG_DONT_REPORT_ERRORS = FLAG_DONT_RECOVER;
|
4d62ba | 2000-08-15 | Martin Stjernholm | |
constant FLAG_RAW_ARGS = 0x00004000;
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
9a3806 | 2000-08-04 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_CACHE_DIFF_ARGS = 0x00010000;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
constant FLAG_CACHE_DIFF_CONTENT = 0x00020000;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
constant FLAG_CACHE_DIFF_RESULT_TYPE = 0x00040000;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
8cb24d | 2000-02-13 | Martin Stjernholm | | constant FLAG_CACHE_DIFF_VARS = 0x00080000;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | | constant FLAG_CACHE_DIFF_TAG_INSTANCE = 0x00100000;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
constant FLAG_CACHE_EXECUTE_RESULT = 0x00200000;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
class Frame
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
constant is_RXML_Frame = 1;
|
56532d | 1999-12-19 | Martin Stjernholm | | constant thrown_at_unwind = 1;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
Frame up;
|
91c898 | 2000-03-11 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
Tag tag;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
int flags;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | mapping(string:mixed)|EVAL_ARGS_FUNC args;
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
24f9e8 | 2000-08-05 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
Type content_type;
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | mixed|PCode content = nil;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
Type result_type;
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
0f998b | 2000-08-15 | Martin Stjernholm | | mixed result = nil;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
689dc6 | 2000-08-31 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
689dc6 | 2000-08-31 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
947739 | 2000-03-20 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
947739 | 2000-03-20 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
91c898 | 2000-03-11 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | 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 | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
938bfd | 2000-11-04 | Martin Stjernholm | | final mixed get_var (string var, void|string scope_name, void|Type want_type)
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ffa693 | 2000-02-20 | Martin Stjernholm | | {
return get_context()->get_var (var, scope_name, want_type);
}
|
938bfd | 2000-11-04 | Martin Stjernholm | | final mixed set_var (string var, mixed val, void|string scope_name)
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ffa693 | 2000-02-20 | Martin Stjernholm | | {
return get_context()->set_var (var, val, scope_name);
}
|
938bfd | 2000-11-04 | Martin Stjernholm | | final void delete_var (string var, void|string scope_name)
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ffa693 | 2000-02-20 | Martin Stjernholm | | {
get_context()->delete_var (var, scope_name);
}
|
bca67e | 2000-10-18 | Martin Stjernholm | | void run_error (string msg, mixed... args)
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
5ed013 | 2000-02-13 | Martin Stjernholm | | _run_error (msg, @args);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
bca67e | 2000-10-18 | Martin Stjernholm | | void parse_error (string msg, mixed... args)
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
291ade | 2000-01-25 | Martin Stjernholm | | {
|
5ed013 | 2000-02-13 | Martin Stjernholm | | _parse_error (msg, @args);
|
291ade | 2000-01-25 | Martin Stjernholm | | }
|
bca67e | 2000-10-18 | Martin Stjernholm | | void tag_debug (string msg, mixed... args)
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ac6977 | 2000-09-08 | Martin Stjernholm | | {
|
2cab1b | 2001-03-05 | Martin Nilsson | | if (flags & FLAG_DEBUG) report_debug (msg, @args);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
bca67e | 2000-10-18 | Martin Stjernholm | | void terminate()
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
{
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("FIXME\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
bca67e | 2000-10-18 | Martin Stjernholm | | void suspend()
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
91c898 | 2000-03-11 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("FIXME\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
bca67e | 2000-10-18 | Martin Stjernholm | | void resume()
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
8cb24d | 2000-02-13 | Martin Stjernholm | | fatal_error ("FIXME\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
bca67e | 2000-10-18 | Martin Stjernholm | | mapping(string:Tag) get_plugins()
|
cf3c90 | 2000-02-04 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
cf3c90 | 2000-02-04 | Martin Stjernholm | | {
#ifdef MODULE_DEBUG
|
bca67e | 2000-10-18 | Martin Stjernholm | | if (!(tag->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
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | return get_context()->tag_set->get_plugins (tag->name, tag->flags & FLAG_PROC_INSTR);
|
cf3c90 | 2000-02-04 | Martin Stjernholm | | }
|
938bfd | 2000-11-04 | Martin Stjernholm | | final Tag get_overridden_tag()
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
641d3c | 2000-10-12 | Martin Stjernholm | | {
return get_context()->tag_set->get_overridden_tag (tag);
}
|
bca67e | 2000-10-18 | Martin Stjernholm | | Frame|string propagate_tag (void|mapping(string:string) args, void|string content)
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | | {
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | Frame this = this_object();
|
429307 | 2001-05-08 | Martin Stjernholm | | #ifdef MODULE_DEBUG
#define CHECK_RAW_TEXT \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (zero_type (this->raw_tag_text)) \
|
429307 | 2001-05-08 | Martin Stjernholm | | fatal_error ("The variable raw_tag_text must be defined.\n"); \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (!stringp (this->raw_tag_text)) \
|
429307 | 2001-05-08 | Martin Stjernholm | | fatal_error ("raw_tag_text must have a string value.\n");
#else
#define CHECK_RAW_TEXT
#endif
|
641d3c | 2000-10-12 | Martin Stjernholm | | if (object(Tag) overridden = get_overridden_tag()) {
|
51f88b | 2000-06-23 | Martin Stjernholm | | Frame frame;
|
429307 | 2001-05-08 | Martin Stjernholm | | if (flags & FLAG_PROC_INSTR) {
if (!content) {
CHECK_RAW_TEXT;
if (mixed err = catch {
Parser_HTML()->add_quote_tag (
"?",
lambda (object p, string c) {
sscanf (c, "%*[^ \t\n\r]%s", content);
throw (0);
},
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | "?")->finish (this->raw_tag_text);
|
429307 | 2001-05-08 | Martin Stjernholm | | }) throw (err);
#ifdef DEBUG
if (!stringp (content))
fatal_error ("Failed to parse PI tag content for <?%s?> from %O.\n",
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | tag->name, this->raw_tag_text);
|
51f88b | 2000-06-23 | Martin Stjernholm | | #endif
|
429307 | 2001-05-08 | Martin Stjernholm | | }
}
else if (!args || !content && !(flags & FLAG_EMPTY_ELEMENT)) {
CHECK_RAW_TEXT;
|
b56de0 | 2001-03-26 | Martin Stjernholm | | if (mixed err = catch {
|
429307 | 2001-05-08 | Martin Stjernholm | | Parser_HTML()->_set_tag_callback (
lambda (object p, string s) {
if (!args) args = p->tag_args();
if (content || flags & FLAG_EMPTY_ELEMENT) throw (0);
else {
p->_set_tag_callback (0);
p->add_container (p->tag_name(),
lambda (object p, mapping a, string c) {
content = c;
throw (0);
});
return 1;
}
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | })->finish (this->raw_tag_text);
|
b56de0 | 2001-03-26 | Martin Stjernholm | | }) throw (err);
|
4c0ed6 | 2001-01-18 | Martin Stjernholm | | #ifdef DEBUG
|
429307 | 2001-05-08 | Martin Stjernholm | | if (!mappingp (args))
fatal_error ("Failed to parse tag args for <%s> from %O.\n",
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | tag->name, this->raw_tag_text);
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | if (!stringp (content) && !(flags & FLAG_EMPTY_ELEMENT))
|
429307 | 2001-05-08 | Martin Stjernholm | | fatal_error ("Failed to parse tag content for <%s> from %O.\n",
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | tag->name, this->raw_tag_text);
|
4c0ed6 | 2001-01-18 | Martin Stjernholm | | #endif
|
51f88b | 2000-06-23 | Martin Stjernholm | | }
|
429307 | 2001-05-08 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | | frame = overridden (args, content || "");
frame->flags |= FLAG_UNPARSED;
return frame;
}
|
429307 | 2001-05-08 | Martin Stjernholm | | else {
if (flags & FLAG_PROC_INSTR) {
if (content)
return result_type->format_tag (tag, 0, content);
else {
CHECK_RAW_TEXT;
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | return this->raw_tag_text;
|
429307 | 2001-05-08 | Martin Stjernholm | | }
}
else {
if (args && (content || flags & FLAG_EMPTY_ELEMENT))
return result_type->format_tag (tag, args, content);
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | else {
|
429307 | 2001-05-08 | Martin Stjernholm | | CHECK_RAW_TEXT;
string s;
|
51f88b | 2000-06-23 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | if (mixed err = catch {
|
51f88b | 2000-06-23 | Martin Stjernholm | | #endif
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | s = t_xml (PEnt)->eval (this->raw_tag_text,
|
429307 | 2001-05-08 | Martin Stjernholm | | get_context(), empty_tag_set);
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | #ifdef MODULE_DEBUG
}) {
if (objectp (err) && ([object] err)->thrown_at_unwind)
fatal_error ("Can't save parser state when evaluating arguments.\n");
throw_fatal (err);
}
#endif
|
429307 | 2001-05-08 | Martin Stjernholm | | if (!args && !content) return s;
if (mixed err = catch {
Parser_HTML()->_set_tag_callback (
lambda (object p, string s) {
if (!args) args = p->tag_args();
if (content || flags & FLAG_EMPTY_ELEMENT) throw (0);
else {
p->_set_tag_callback (0);
p->add_container (p->tag_name(),
lambda (object p, mapping a, string c) {
content = c;
throw (0);
});
return 1;
}
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | })->finish (this->raw_tag_text);
|
429307 | 2001-05-08 | Martin Stjernholm | | }) throw (err);
#ifdef DEBUG
if (!mappingp (args))
fatal_error ("Failed to parse tag args for <%s> from %O.\n",
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | tag->name, this->raw_tag_text);
|
429307 | 2001-05-08 | Martin Stjernholm | | if (!stringp (content))
fatal_error ("Failed to parse tag content for <%s> from %O.\n",
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | tag->name, this->raw_tag_text);
|
429307 | 2001-05-08 | Martin Stjernholm | | #endif
return result_type->format_tag (tag, args, content);
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | }
|
51f88b | 2000-06-23 | Martin Stjernholm | | }
|
429307 | 2001-05-08 | Martin Stjernholm | | }
#undef CHECK_RAW_TEXT
|
51f88b | 2000-06-23 | Martin Stjernholm | | }
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #ifdef DEBUG
|
d52f8f | 2001-05-19 | Martin Stjernholm | | # define THIS_TAG_TOP_DEBUG(msg, args...) \
(TAG_DEBUG_TEST (flags) && report_debug ("%O: " + (msg), this_object(), args), 0)
# define THIS_TAG_DEBUG(msg, args...) \
(TAG_DEBUG_TEST (flags) && report_debug ("%O: " + (msg), this_object(), args), 0)
# define THIS_TAG_DEBUG_ENTER_SCOPE(ctx, this) \
if (this->vars && ctx->scopes["_"] != this->vars) \
THIS_TAG_DEBUG ("(Re)entering scope %O\n", this->scope_name)
# define THIS_TAG_DEBUG_LEAVE_SCOPE(ctx, this) \
if (this->vars && ctx->scopes["_"] == this->vars) \
THIS_TAG_DEBUG ("Leaving scope %O\n", this->scope_name)
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #else
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | # define THIS_TAG_TOP_DEBUG(msg, args...) 0
# define THIS_TAG_DEBUG(msg, args...) 0
|
d52f8f | 2001-05-19 | Martin Stjernholm | | # define THIS_TAG_DEBUG_ENTER_SCOPE(ctx, this) 0
# define THIS_TAG_DEBUG_LEAVE_SCOPE(ctx, this) 0
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #endif
|
d52f8f | 2001-05-19 | Martin Stjernholm | | #define SET_SEQUENTIAL(from, to, desc) \
do { \
THIS_TAG_DEBUG ("Adding %s to " desc "\n", \
utils->format_short (from)); \
to += from; \
} while (0)
#define SET_NONSEQUENTIAL(from, to, to_type, desc) \
do { \
if (from != nil) { \
if (to != nil) \
parse_error ( \
"Cannot append another value %s to non-sequential " desc \
" of type %s.\n", utils->format_short (from), \
to_type->name); \
THIS_TAG_DEBUG ("Setting " desc " to %s\n", \
utils->format_short (from)); \
to = from; \
} \
} while (0)
#define CONV_RESULT(from, from_type, to, to_type) \
do { \
if (from_type->name != to_type->name) { \
THIS_TAG_DEBUG ("Converting result from %s to %s of " \
"surrounding content\n", \
from_type->name, to_type->name); \
to = to_type->encode (from, from_type); \
} \
else to = from; \
} while (0)
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | private void _exec_array_fatal (string where, int pos, mixed elem,
string msg, mixed... args)
{
if (sizeof (args)) msg = sprintf (msg, args);
fatal_error ("Position %d in exec array from %s is %s: %s", pos, where, elem, msg);
};
mixed _exec_array (Context ctx, TagSetParser|PCode evaler, array exec, string where)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
56532d | 1999-12-19 | Martin Stjernholm | | Frame this = this_object();
|
d52f8f | 2001-05-19 | Martin Stjernholm | | int i = 0, parent_scope = flags & FLAG_PARENT_SCOPE;
|
46c68f | 2000-08-12 | Martin Stjernholm | | mixed res = nil;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | Parser subparser = 0;
mixed err = catch {
|
ac6977 | 2000-09-08 | Martin Stjernholm | | if (parent_scope) {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | THIS_TAG_DEBUG_LEAVE_SCOPE (ctx, this);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | LEAVE_SCOPE (ctx, this);
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
for (; i < sizeof (exec); i++) {
|
46c68f | 2000-08-12 | Martin Stjernholm | | mixed elem = exec[i], piece = nil;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
switch (sprintf ("%t", elem)) {
case "string":
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (result_type->parser_prog == PNone) {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | THIS_TAG_DEBUG ("Exec[%d]: String %s\n", i, utils->format_short (elem));
|
ed8175 | 1999-12-11 | Martin Stjernholm | | piece = elem;
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | else {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | subparser = result_type->get_parser (ctx, 0, evaler);
if (evaler->recover_errors && !(flags & FLAG_DONT_RECOVER))
|
140f36 | 2000-10-19 | Martin Stjernholm | | subparser->recover_errors = 1;
|
d52f8f | 2001-05-19 | Martin Stjernholm | | THIS_TAG_DEBUG ("Exec[%d]: Parsing string %s with %O\n", i,
utils->format_short (elem), subparser);
|
56532d | 1999-12-19 | Martin Stjernholm | | subparser->finish ([string] elem);
piece = subparser->eval();
|
ed8175 | 1999-12-11 | Martin Stjernholm | | subparser = 0;
}
break;
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | case "mapping":
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | THIS_TAG_DEBUG ("Exec[%d]: Response mapping\n", i);
_exec_array_fatal (where, i, elem,
"Response mappings not yet implemented.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | break;
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | case "multiset":
|
ac6977 | 2000-09-08 | Martin Stjernholm | | if (sizeof ([multiset] elem) == 1) {
piece = ((array) elem)[0];
|
d52f8f | 2001-05-19 | Martin Stjernholm | | THIS_TAG_DEBUG ("Exec[%d]: Verbatim value %s\n", i,
utils->format_short (piece));
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | else
_exec_array_fatal (where, i, elem,
"Not exactly one value in multiset.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | break;
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | default:
|
5a455b | 2000-02-13 | Martin Stjernholm | | if (objectp (elem))
if (([object] elem)->is_RXML_Frame) {
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | THIS_TAG_DEBUG ("Exec[%d]: Evaluating frame %O\n", i, ([object] elem));
piece = ([object(Frame)] elem)->_eval (
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | ctx, evaler, result_type);
break;
|
5a455b | 2000-02-13 | Martin Stjernholm | | }
else if (([object] elem)->is_RXML_Parser) {
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | THIS_TAG_DEBUG ("Exec[%d]: Continuing eval of frame %O\n",
i, ([object] elem));
|
5a455b | 2000-02-13 | Martin Stjernholm | | ([object(Parser)] elem)->finish();
piece = ([object(Parser)] elem)->eval();
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | break;
|
5a455b | 2000-02-13 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | _exec_array_fatal (where, i, elem, "Not a valid type.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (result_type->sequential) SET_SEQUENTIAL (piece, res, "result");
else SET_NONSEQUENTIAL (piece, result, result_type, "result");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
if (result_type->sequential) result += res;
|
d52f8f | 2001-05-19 | Martin Stjernholm | | else res = result;
|
ac6977 | 2000-09-08 | Martin Stjernholm | | if (parent_scope) {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | THIS_TAG_DEBUG_ENTER_SCOPE (ctx, this);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | ENTER_SCOPE (ctx, this);
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | return res;
};
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (result_type->sequential) result += res;
|
ac6977 | 2000-09-08 | Martin Stjernholm | | if (parent_scope) {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | THIS_TAG_DEBUG_ENTER_SCOPE (ctx, this);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | ENTER_SCOPE (ctx, this);
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
56532d | 1999-12-19 | Martin Stjernholm | | if (objectp (err) && ([object] err)->thrown_at_unwind) {
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | THIS_TAG_DEBUG ("Exec: Interrupted at position %d\n", i);
|
d4768a | 2001-05-18 | Martin Stjernholm | | UNWIND_STATE ustate;
|
33712a | 2000-03-13 | Martin Stjernholm | | if ((ustate = ctx->unwind_state) && !zero_type (ustate->stream_piece)) {
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (result_type->name != evaler->type->name)
res = evaler->type->encode (res, result_type);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | if (result_type->sequential)
|
d52f8f | 2001-05-19 | Martin Stjernholm | | SET_SEQUENTIAL (ustate->stream_piece, res, "stream piece");
else
SET_NONSEQUENTIAL (ustate->stream_piece, res, result_type, "stream piece");
ustate->stream_piece = res;
|
33712a | 2000-03-13 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | 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 | | {
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | array(Tag) arr_add_tags = ctx->new_runtime_tags->added_tags();
array(string) arr_rem_tags = ctx->new_runtime_tags->removed_tags();
array(string) arr_rem_pi_tags = ctx->new_runtime_tags->removed_pi_tags();
|
2bd21a | 2000-01-05 | Martin Stjernholm | | 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) {
|
ac6977 | 2000-09-08 | Martin Stjernholm | | foreach (arr_add_tags, Tag tag) {
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | THIS_TAG_DEBUG ("Adding runtime tag %O\n", tag);
|
2bd21a | 2000-01-05 | Martin Stjernholm | | ([object(TagSetParser)] p)->add_runtime_tag (tag);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
foreach (arr_rem_tags, string tag) {
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | THIS_TAG_DEBUG ("Removing runtime tag %s\n", tag);
|
2bd21a | 2000-01-05 | Martin Stjernholm | | ([object(TagSetParser)] p)->remove_runtime_tag (tag);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
foreach (arr_rem_pi_tags, string tag) {
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | THIS_TAG_DEBUG ("Removing runtime tag %s\n", tag);
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | ([object(TagSetParser)] p)->remove_runtime_tag (tag, 1);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
2bd21a | 2000-01-05 | Martin Stjernholm | | }
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | ctx->runtime_tags = ctx->new_runtime_tags->filter_tags (ctx->runtime_tags);
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | ctx->new_runtime_tags = 0;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | }
|
d52f8f | 2001-05-19 | Martin Stjernholm | | #define LOW_CALL_CALLBACK(res, cb, args...) \
do { \
THIS_TAG_DEBUG ("Calling " #cb "\n"); \
PROFILE_SWITCH (ctx, "rxml internal", "tag:" + tag->name); \
COND_PROF_ENTER(tag,tag->name,"tag"); \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | res = (cb) (args); /* Might unwind. */ \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | COND_PROF_LEAVE(tag,tag->name,"tag"); \
PROFILE_SWITCH (ctx, "tag:" + tag->name, "rxml internal"); \
} while (0)
#define EXEC_CALLBACK(ctx, evaler, exec, cb, args...) \
do { \
if (!exec) \
if (arrayp (cb)) { \
THIS_TAG_DEBUG ("Getting exec array from " #cb "\n"); \
exec = [array] cb; \
} \
else { \
LOW_CALL_CALLBACK (exec, cb, args); \
THIS_TAG_DEBUG ((exec ? "Exec array of length " + \
sizeof (exec) : "Zero") + \
" returned from " #cb "\n"); \
THIS_TAG_DEBUG_ENTER_SCOPE (ctx, this); \
ENTER_SCOPE (ctx, this); \
if (evaler->is_RXML_Parser && ctx->new_runtime_tags) \
/* FIXME: When the evaler is a PCode object we should have a \
* debug check here that ensures that the same runtime tag \
* changes are done as in the first eval. */ \
_handle_runtime_tags (ctx, evaler); \
} \
} while (0)
#define EXEC_ARRAY(ctx, evaler, exec, cb) \
do { \
if (exec) { \
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | mixed res = \
_exec_array (ctx, evaler, exec, #cb); /* Might unwind. */ \
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (flags & FLAG_STREAM_RESULT) { \
DO_IF_DEBUG ( \
if (ctx->unwind_state) \
fatal_error ("Clobbering unwind_state to do streaming.\n"); \
if (piece != nil) \
fatal_error ("Thanks, we think about how nice it must be " \
"to play the harmonica...\n"); \
); \
CONV_RESULT (res, result_type, res, type); \
ctx->unwind_state = (["stream_piece": res]); \
THIS_TAG_DEBUG ("Streaming %s from " #cb "\n", \
utils->format_short (res)); \
throw (this); \
} \
exec = 0; \
} \
} while (0)
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | private mapping(string:mixed) _eval_args (Context ctx,
mapping(string:string) raw_args,
mapping(string:Type) my_req_args)
{
mapping(string:Type) atypes =
raw_args & (tag->req_arg_types | tag->opt_arg_types);
if (my_req_args) {
mapping(string:Type) missing = my_req_args - atypes;
if (sizeof (missing))
parse_error ("Required " +
(sizeof (missing) > 1 ?
"arguments " + String.implode_nicely (
sort (indices (missing))) + " are" :
"argument " + indices (missing)[0] + " is") + " missing.\n");
}
#ifdef MODULE_DEBUG
if (mixed err = catch {
#endif
foreach (indices (raw_args), string arg) {
Type t = atypes[arg] || tag->def_arg_type;
if (t->parser_prog != PNone) {
Parser parser = t->get_parser (ctx, 0, 0);
THIS_TAG_DEBUG ("Evaluating argument value %s with %O\n",
utils->format_short (raw_args[arg]), parser);
parser->finish (raw_args[arg]);
raw_args[arg] = parser->eval();
THIS_TAG_DEBUG ("Setting dynamic argument %s to %s\n",
utils->format_short (arg),
utils->format_short (raw_args[arg]));
t->give_back (parser);
}
}
#ifdef MODULE_DEBUG
}) {
if (objectp (err) && ([object] err)->thrown_at_unwind)
fatal_error ("Can't save parser state when evaluating dynamic arguments.\n");
throw_fatal (err);
}
#endif
return raw_args;
}
EVAL_ARGS_FUNC _prepare (Context ctx, Type type,
mapping(string:string) raw_args)
{
Frame this = this_object();
mixed err = catch {
#ifdef DEBUG
if (!up)
#endif
up = ctx->frame;
ctx->frame = this;
if (++ctx->frame_depth >= ctx->max_frame_depth) {
ctx->frame_depth--;
_run_error ("Too deep recursion -- exceeding %d nested tags.\n",
ctx->max_frame_depth);
}
EVAL_ARGS_FUNC func;
if (raw_args) {
#ifdef MODULE_DEBUG
if (flags & FLAG_PROC_INSTR)
fatal_error ("Can't pass arguments to a processing instruction tag.\n");
#endif
#ifdef MAGIC_HELP_ARG
if (raw_args->help) {
func = utils->return_help_arg;
args = raw_args;
}
else
#endif
if (sizeof (raw_args)) {
string splice_arg = raw_args["::"];
if (splice_arg && type->entity_syntax)
m_delete (raw_args, "::");
else splice_arg = 0;
mapping(string:Type) splice_req_types;
mapping(string:Type) atypes = raw_args & tag->req_arg_types;
if (sizeof (atypes) < sizeof (tag->req_arg_types))
if (splice_arg)
splice_req_types = tag->req_arg_types - atypes;
else {
array(string) missing = sort (indices (tag->req_arg_types - atypes));
parse_error ("Required " +
(sizeof (missing) > 1 ?
"arguments " + String.implode_nicely (missing) + " are" :
"argument " + missing[0] + " is") + " missing.\n");
}
atypes += raw_args & tag->opt_arg_types;
PikeCompile comp = PikeCompile();
String.Buffer fn_text = String.Buffer();
if (splice_arg) {
Parser p = splice_arg_type->get_pcode_parser (ctx, 0, 0);
THIS_TAG_DEBUG ("Evaluating splice argument %s\n",
utils->format_short (splice_arg));
#ifdef MODULE_DEBUG
if (mixed err = catch {
#endif
p->finish (splice_arg);
splice_arg = p->eval();
#ifdef MODULE_DEBUG
}) {
if (objectp (err) && ([object] err)->thrown_at_unwind)
fatal_error ("Can't save parser state when "
"evaluating splice argument.\n");
throw_fatal (err);
}
#endif
string expr =
sprintf ("%s (context, %s->parse_tag_args ((%s) || \"\"), %s)",
comp->bind (_eval_args),
comp->bind (xml_splice_arg_parser),
p->p_code->_compile_text (comp),
comp->bind (splice_req_types));
p->p_code = 0;
splice_arg_type->give_back (p);
args = _eval_args (
ctx, xml_splice_arg_parser->parse_tag_args (splice_arg || ""),
splice_req_types);
if (!zero_type (this->raw_tag_text)) {
}
fn_text->add ("return ");
fn_text->add (expr);
fn_text->add (" + ([\n");
}
else {
args = raw_args;
fn_text->add ("return ([\n");
}
#ifdef MODULE_DEBUG
if (mixed err = catch {
#endif
foreach (indices (raw_args), string arg) {
Type t = atypes[arg] || tag->def_arg_type;
if (t->parser_prog != PNone) {
Parser parser = t->get_pcode_parser (ctx, 0, 0);
THIS_TAG_DEBUG ("Evaluating argument value %s with %O\n",
utils->format_short (raw_args[arg]), parser);
parser->finish (raw_args[arg]);
args[arg] = parser->eval();
THIS_TAG_DEBUG ("Setting argument %s to %s\n",
utils->format_short (arg),
utils->format_short (args[arg]));
fn_text->add (sprintf ("%O: %s,\n", arg,
parser->p_code->_compile_text (comp)));
parser->p_code = 0;
t->give_back (parser);
}
else {
args[arg] = raw_args[arg];
fn_text->add (sprintf ("%O: %s,\n", arg, comp->bind (raw_args[arg])));
}
}
#ifdef MODULE_DEBUG
}) {
if (objectp (err) && ([object] err)->thrown_at_unwind)
fatal_error ("Can't save parser state when evaluating arguments.\n");
throw_fatal (err);
}
#endif
fn_text->add ("]);\n");
string fn = comp->decl_func (
"mapping(string:mixed)", "RXML.Context context", fn_text->get());
func = comp->compile()()[fn];
}
else {
func = utils->return_empty_mapping;
args = raw_args;
}
}
else
func = utils->return_zero;
if (!zero_type (this->parent_frame))
if (up->local_tags && up->local_tags->has_tag (tag)) {
THIS_TAG_DEBUG ("Setting parent_frame to %O from local_tags\n", up);
this->parent_frame = up;
}
else {
int nest = 1;
Frame frame = up;
for (; frame; frame = frame->up)
if (frame->additional_tags && frame->additional_tags->has_tag (tag)) {
if (!--nest) break;
}
else if (frame->tag == tag) nest++;
THIS_TAG_DEBUG ("Setting parent_frame to %O from additional_tags\n", frame);
this->parent_frame = frame;
break;
}
if (!result_type) {
#ifdef MODULE_DEBUG
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);
#endif
find_result_type: {
foreach (tag->result_types, Type rtype)
if (rtype->subtype_of (type)) {
result_type = rtype;
break find_result_type;
}
foreach (tag->result_types, Type rtype)
if (type->subtype_of (rtype)) {
result_type = type (rtype->parser_prog, @rtype->parser_args);
break find_result_type;
}
parse_error (
"Tag returns %s but %s is expected.\n",
String.implode_nicely ([array(string)] tag->result_types->name, "or"),
type->name);
}
THIS_TAG_DEBUG ("Resolved result_type to %s from surrounding %s\n",
result_type->name, type->name);
}
else THIS_TAG_DEBUG ("Keeping result_type %s\n", result_type->name);
if (!content_type) {
#ifdef MODULE_DEBUG
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);
#endif
content_type = tag->content_type;
if (content_type == t_same) {
content_type =
result_type (content_type->parser_prog, @content_type->parser_args);
THIS_TAG_DEBUG ("Resolved t_same to content_type %O\n", content_type);
}
else THIS_TAG_DEBUG ("Setting content_type to %O from tag\n", content_type);
}
else THIS_TAG_DEBUG ("Keeping content_type %O\n", content_type);
ctx->frame = up;
return func;
};
ctx->frame = up;
throw (err);
}
|
d52f8f | 2001-05-19 | Martin Stjernholm | | mixed _eval (Context ctx, TagSetParser|PCode evaler, Type type,
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | void|string|PCode in_content)
|
d52f8f | 2001-05-19 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
56532d | 1999-12-19 | Martin Stjernholm | | Frame this = this_object();
|
b48338 | 2000-06-30 | Martin Stjernholm | | RequestID id = ctx->id;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
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;
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | EVAL_ARGS_FUNC in_args;
|
291ade | 2000-01-25 | Martin Stjernholm | | int iter;
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #ifdef DEBUG
int debug_iter = 1;
#endif
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | object(Parser)|object(PCode) subevaler;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | mixed piece;
|
d52f8f | 2001-05-19 | Martin Stjernholm | | array exec = 0;
|
f02d00 | 2000-03-18 | Martin Stjernholm | | TagSet orig_tag_set;
|
c6245b | 1999-12-31 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | 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())
|
d52f8f | 2001-05-19 | Martin Stjernholm | | PRE_INIT_ERROR ("Context not current.\n");
if (!evaler->tag_set_eval)
PRE_INIT_ERROR ("Calling _eval() with non-tag set parser.\n");
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | Frame prev_ctx_frame = ctx->frame;
|
2bd21a | 2000-01-05 | Martin Stjernholm | | #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
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #undef PRE_INIT_ERROR
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d52f8f | 2001-05-19 | Martin Stjernholm | | mixed conv_result = nil;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | mixed err1 = 0;
|
b48338 | 2000-06-30 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | process_tag:
do {
if ((err1 = catch {
if (array state = ctx->unwind_state && ctx->unwind_state[this]) {
#ifdef DEBUG
if (in_content)
fatal_error ("Can't feed new content when resuming parse.\n");
|
b48338 | 2000-06-30 | Martin Stjernholm | | #endif
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | ctx->frame = this;
object ignored;
[ignored, eval_state, in_args, in_content, iter,
subevaler, piece, exec, orig_tag_set, ctx->new_runtime_tags
#ifdef DEBUG
, debug_iter
#endif
] = state;
m_delete (ctx->unwind_state, this);
if (!sizeof (ctx->unwind_state)) ctx->unwind_state = 0;
THIS_TAG_TOP_DEBUG ("Continuing evaluation" +
(piece ? " with stream piece\n" : "\n"));
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
b48338 | 2000-06-30 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | else {
if (tag) {
TRACE_ENTER("tag <" + tag->name + ">", tag);
#ifdef MODULE_LEVEL_SECURITY
if (id->conf->check_security (tag, id, id->misc->seclevel)) {
THIS_TAG_TOP_DEBUG ("Access denied - exiting\n");
TRACE_LEAVE("access denied");
break process_tag;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #endif
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | }
if (in_content) {
THIS_TAG_TOP_DEBUG ("Evaluating\n");
ctx->frame = this;
if (functionp (args)) {
THIS_TAG_DEBUG ("Evaluating compiled arguments\n");
in_args = args;
args = in_args (ctx);
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | content = nil;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | else if (flags & FLAG_UNPARSED) {
#ifdef DEBUG
if (args && !mappingp (args))
fatal_error ("args is not a mapping in unparsed frame.\n");
if (!stringp (content))
fatal_error ("content is not a string in unparsed frame.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | THIS_TAG_TOP_DEBUG ("Evaluating unparsed\n");
in_args = _prepare (ctx, type, args);
ctx->frame = this;
in_content = content;
content = nil;
flags &= ~FLAG_UNPARSED;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
d4768a | 2001-05-18 | Martin Stjernholm | | else {
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | _prepare (ctx, type, 0);
ctx->frame = this;
THIS_TAG_TOP_DEBUG ("Evaluating with constant arguments and content.\n");
|
d4768a | 2001-05-18 | Martin Stjernholm | | }
|
689dc6 | 2000-08-31 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | piece = result = nil;
|
87fb7e | 2000-03-25 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #ifdef DEBUG
if (up != prev_ctx_frame)
fatal_error ("Frame probably mixed between different simultaneous contexts "
"(up: %O, previous ctx->frame: %O).\n", up, prev_ctx_frame);
|
a85a95 | 2000-02-13 | Martin Stjernholm | | #endif
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | })) {
|
a85a95 | 2000-02-13 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (objectp (err1) && ([object] err1)->thrown_at_unwind)
err1 = catch (
fatal_error ("Can't save parser state when evaluating arguments.\n"));
|
a85a95 | 2000-02-13 | Martin Stjernholm | | #endif
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | break process_tag;
}
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (mixed err2 = catch {
#ifdef MAGIC_HELP_ARG
if (tag && (args || ([]))->help) {
TRACE_ENTER ("tag <" + tag->name + " help>", tag);
string help = id->conf->find_tag_doc (tag->name, id);
TRACE_LEAVE ("");
THIS_TAG_TOP_DEBUG ("Reporting help - frame done\n");
ctx->handle_exception (
Backtrace ("help", help, ctx), evaler);
break process_tag;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #endif
|
b48338 | 2000-06-30 | Martin Stjernholm | |
switch (eval_state) {
case EVSTAT_BEGIN:
if (array|function(RequestID:array) do_enter =
[array|function(RequestID:array)] this->do_enter) {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | EXEC_CALLBACK (ctx, evaler, exec, do_enter, id);
EXEC_ARRAY (ctx, evaler, exec, do_enter);
}
else {
THIS_TAG_DEBUG_ENTER_SCOPE (ctx, this);
ENTER_SCOPE (ctx, this);
|
291ade | 2000-01-25 | Martin Stjernholm | | }
|
b48338 | 2000-06-30 | Martin Stjernholm | | eval_state = EVSTAT_ENTERED;
|
4c2b51 | 2001-05-17 | Martin Stjernholm | |
|
b48338 | 2000-06-30 | Martin Stjernholm | | case EVSTAT_ENTERED:
case EVSTAT_LAST_ITER:
|
d52f8f | 2001-05-19 | Martin Stjernholm | | int|function(RequestID:int) do_iterate =
[int|function(RequestID:int)] this->do_iterate;
array|function(RequestID:array) do_process =
[array|function(RequestID:array)] this->do_process;
|
b48338 | 2000-06-30 | Martin Stjernholm | | do {
if (eval_state != EVSTAT_LAST_ITER) {
if (intp (do_iterate)) {
iter = [int] do_iterate || 1;
eval_state = EVSTAT_LAST_ITER;
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #ifdef DEBUG
if (iter > 1)
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | THIS_TAG_DEBUG ("Getting %d iterations from do_iterate\n", iter);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | else if (iter < 0)
THIS_TAG_DEBUG ("Skipping to finish since do_iterate is negative\n");
#endif
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
else {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | LOW_CALL_CALLBACK (iter, do_iterate, id);
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | THIS_TAG_DEBUG ("%O returned from do_iterate\n", iter);
|
d52f8f | 2001-05-19 | Martin Stjernholm | | THIS_TAG_DEBUG_ENTER_SCOPE (ctx, this);
ENTER_SCOPE (ctx, this);
if (evaler->is_RXML_Parser && ctx->new_runtime_tags)
_handle_runtime_tags (ctx, evaler);
|
b48338 | 2000-06-30 | Martin Stjernholm | | if (!iter) eval_state = EVSTAT_LAST_ITER;
}
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | }
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
|
d52f8f | 2001-05-19 | Martin Stjernholm | | for (; iter > 0; iter-- DO_IF_DEBUG (, debug_iter++)) {
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (in_content) {
int finished = 1;
if (subevaler)
finished = 0;
else if (stringp (in_content)) {
if (in_content == "")
subevaler = PCode (content_type);
else if (flags & FLAG_EMPTY_ELEMENT)
parse_error ("This tag doesn't handle content.\n");
else {
|
0f998b | 2000-08-15 | Martin Stjernholm | | if (this->local_tags) {
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | subevaler = content_type->get_pcode_parser (
|
d52f8f | 2001-05-19 | Martin Stjernholm | | ctx, [object(TagSet)] this->local_tags, evaler);
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | subevaler->_local_tag_set = 1;
THIS_TAG_DEBUG ("Iter[%d]: Parsing and evaluating content %s "
"with %O from local_tags\n", debug_iter,
utils->format_short (in_content), subevaler);
|
0f998b | 2000-08-15 | Martin Stjernholm | | }
|
ac6977 | 2000-09-08 | Martin Stjernholm | | else {
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | #ifdef DEBUG
if (orig_tag_set)
fatal_error ("Didn't expect orig_tag_set here.\n");
#endif
if (TagSet add_tags = [object(TagSet)] this->additional_tags) {
TagSet tset = ctx->tag_set;
if (!tset->has_effective_tags (add_tags)) {
THIS_TAG_DEBUG ("Installing additional_tags %O\n", add_tags);
int hash = HASH_INT2 (tset->id_number, add_tags->id_number);
orig_tag_set = tset;
TagSet local_ts;
if (!(local_ts = local_tag_set_cache[hash])) {
local_ts = TagSet (
add_tags->name + "+" + orig_tag_set->name);
local_ts->imported = ({add_tags, orig_tag_set});
local_tag_set_cache[hash] = local_ts;
}
ctx->tag_set = local_ts;
}
else
THIS_TAG_DEBUG ("Not installing additional_tags %O "
"since they're already in the tag set\n",
add_tags);
}
subevaler = content_type->get_pcode_parser (ctx, 0, evaler);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #ifdef DEBUG
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (content_type->parser_prog != PNone)
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | THIS_TAG_DEBUG ("Iter[%d]: Parsing and evaluating content %s "
"with %O\n", debug_iter,
utils->format_short (in_content), subevaler);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #endif
}
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (evaler->recover_errors && !(flags & FLAG_DONT_RECOVER))
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | subevaler->recover_errors = 1;
subevaler->finish (in_content);
(in_content = subevaler->p_code)->finish();
|
0f998b | 2000-08-15 | Martin Stjernholm | | finished = 1;
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | }
else {
THIS_TAG_DEBUG ("Iter[%d]: Evaluating compiled content\n",
debug_iter);
subevaler = in_content;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | eval_sub:
do {
if (piece != nil && flags & FLAG_STREAM_CONTENT) {
THIS_TAG_DEBUG ("Iter[%d]: Got %s stream piece %s\n",
debug_iter, finished ? "ending" : "a",
utils->format_short (piece));
if (!arrayp (do_process)) {
EXEC_CALLBACK (ctx, evaler, exec, do_process, id, piece);
if (exec) {
mixed res = _exec_array (
ctx, evaler, exec, "do_process");
if (flags & FLAG_STREAM_RESULT) {
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #ifdef DEBUG
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (!zero_type (ctx->unwind_state->stream_piece))
fatal_error ("Clobbering unwind_state->stream_piece.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | CONV_RESULT (res, result_type, res, type);
ctx->unwind_state->stream_piece = res;
THIS_TAG_DEBUG ("Iter[%d]: Streaming %s from do_process\n",
debug_iter, utils->format_short (res));
throw (this);
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | exec = 0;
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | else if (flags & FLAG_STREAM_RESULT) {
THIS_TAG_DEBUG ("Iter[%d]: do_process finished the stream; "
"ignoring remaining content\n", debug_iter);
ctx->unwind_state = 0;
piece = nil;
break eval_sub;
|
0f998b | 2000-08-15 | Martin Stjernholm | | }
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | piece = nil;
if (finished) break eval_sub;
}
else {
piece = nil;
if (finished) {
mixed res = subevaler->_eval (ctx);
if (content_type->sequential)
SET_SEQUENTIAL (res, content, "content");
else if (res != nil)
SET_NONSEQUENTIAL (res, content, content_type, "content");
break eval_sub;
}
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (subevaler->is_RXML_Parser) {
subevaler->finish();
(in_content = subevaler->p_code)->finish();
}
finished = 1;
} while (1);
subevaler = 0;
}
|
b48338 | 2000-06-30 | Martin Stjernholm | |
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (do_process) {
EXEC_CALLBACK (ctx, evaler, exec, do_process, id);
EXEC_ARRAY (ctx, evaler, exec, do_process);
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
} while (eval_state != EVSTAT_LAST_ITER);
|
d52f8f | 2001-05-19 | Martin Stjernholm | | eval_state = EVSTAT_ITER_DONE;
|
b48338 | 2000-06-30 | Martin Stjernholm | |
|
4c2b51 | 2001-05-17 | Martin Stjernholm | |
|
b48338 | 2000-06-30 | Martin Stjernholm | | case EVSTAT_ITER_DONE:
if (array|function(RequestID:array) do_return =
[array|function(RequestID:array)] this->do_return) {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | EXEC_CALLBACK (ctx, evaler, exec, do_return, id);
|
b48338 | 2000-06-30 | Martin Stjernholm | | if (exec) {
|
d52f8f | 2001-05-19 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | _exec_array (ctx, evaler, exec, "do_return");
|
e86f2d | 2000-02-15 | Martin Stjernholm | | exec = 0;
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
else if (result == nil && !(flags & FLAG_EMPTY_ELEMENT)) {
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (result_type->parser_prog == PNone) {
|
fe628d | 2001-03-01 | Martin Stjernholm | | if (content_type->name != result_type->name) {
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | THIS_TAG_DEBUG ("Assigning content to result after "
|
d52f8f | 2001-05-19 | Martin Stjernholm | | "conversion from %s to %s\n",
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | content_type->name, result_type->name);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | result = result_type->encode (content, content_type);
}
else {
THIS_TAG_DEBUG ("Assigning content to result\n");
|
b48338 | 2000-06-30 | Martin Stjernholm | | result = content;
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
else
|
ac6977 | 2000-09-08 | Martin Stjernholm | | if (stringp (content)) {
if (!exec) {
THIS_TAG_DEBUG ("Parsing content with exec array "
"for assignment to result\n");
exec = ({content});
}
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | _exec_array (ctx, evaler, exec, "content parse");
|
b48338 | 2000-06-30 | Martin Stjernholm | | exec = 0;
}
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
d52f8f | 2001-05-19 | Martin Stjernholm | |
if (result != nil)
CONV_RESULT (result, result_type, conv_result, type);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #ifdef DEBUG
|
d52f8f | 2001-05-19 | Martin Stjernholm | | else THIS_TAG_DEBUG ("Skipping nil result\n");
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #endif
|
4c2b51 | 2001-05-17 | Martin Stjernholm | |
|
d52f8f | 2001-05-19 | Martin Stjernholm | | THIS_TAG_DEBUG_LEAVE_SCOPE (ctx, this);
|
b48338 | 2000-06-30 | Martin Stjernholm | | LEAVE_SCOPE (ctx, this);
|
f99720 | 2000-01-18 | Martin Stjernholm | |
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (evaler->is_RXML_Parser && ctx->new_runtime_tags)
_handle_runtime_tags (ctx, evaler);
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | }
|
ffa693 | 2000-02-20 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }) {
|
d52f8f | 2001-05-19 | Martin Stjernholm | | THIS_TAG_DEBUG_LEAVE_SCOPE (ctx, this);
|
b48338 | 2000-06-30 | Martin Stjernholm | | LEAVE_SCOPE (ctx, this);
|
d52f8f | 2001-05-19 | Martin Stjernholm | |
|
b48338 | 2000-06-30 | Martin Stjernholm | | string action;
|
d52f8f | 2001-05-19 | Martin Stjernholm | | exception:
{
unwind:
if (objectp (err2) && ([object] err2)->thrown_at_unwind) {
UNWIND_STATE ustate = ctx->unwind_state;
if (!ustate) ustate = ctx->unwind_state = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #ifdef DEBUG
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (ustate[this]) fatal_error ("Frame already has an unwind state.\n");
|
ed8175 | 1999-12-11 | Martin Stjernholm | | #endif
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (ustate->exec_left) {
exec = [array] ustate->exec_left;
m_delete (ustate, "exec_left");
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
|
d52f8f | 2001-05-19 | Martin Stjernholm | |
if (err2 == this || exec && sizeof (exec) && err2 == exec[0])
if (evaler->read && evaler->unwind_safe) {
mixed piece = evaler->read();
if (err2 = catch {
if (type->sequential)
SET_SEQUENTIAL (ustate->stream_piece, piece, "stream piece");
else
SET_NONSEQUENTIAL (ustate->stream_piece, piece, type, "stream piece");
}) break unwind;
if (err2 == this) err2 = 0;
if (orig_tag_set) ctx->tag_set = orig_tag_set, orig_tag_set = 0;
action = "break";
THIS_TAG_TOP_DEBUG ("Breaking to parent frame to do streaming\n");
}
else {
m_delete (ustate, "stream_piece");
action = "continue";
THIS_TAG_TOP_DEBUG ("Not streaming since the parser "
"doesn't allow that\n");
}
else if (!zero_type (ustate->stream_piece)) {
piece = ustate->stream_piece;
|
b48338 | 2000-06-30 | Martin Stjernholm | | m_delete (ustate, "stream_piece");
action = "continue";
}
|
d52f8f | 2001-05-19 | Martin Stjernholm | | else {
action = "break";
THIS_TAG_TOP_DEBUG ("Interrupted\n");
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | ustate[this] = ({err2, eval_state, in_args, in_content, iter,
subevaler, piece, exec, orig_tag_set, ctx->new_runtime_tags,
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #ifdef DEBUG
|
d52f8f | 2001-05-19 | Martin Stjernholm | | debug_iter,
|
ac6977 | 2000-09-08 | Martin Stjernholm | | #endif
|
d52f8f | 2001-05-19 | Martin Stjernholm | | });
TRACE_LEAVE (action);
break exception;
}
|
ac6977 | 2000-09-08 | Martin Stjernholm | | THIS_TAG_TOP_DEBUG ("Exception\n");
|
0f998b | 2000-08-15 | Martin Stjernholm | | TRACE_LEAVE ("exception");
|
d52f8f | 2001-05-19 | Martin Stjernholm | | ctx->handle_exception (err2, evaler);
|
46c68f | 2000-08-12 | Martin Stjernholm | | result = nil;
|
b48338 | 2000-06-30 | Martin Stjernholm | | action = "return";
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
b48338 | 2000-06-30 | Martin Stjernholm | | switch (action) {
case "break":
|
56532d | 1999-12-19 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (!evaler->unwind_state)
fatal_error ("Trying to unwind inside an evaluator "
"that isn't unwind safe.\n");
|
56532d | 1999-12-19 | Martin Stjernholm | | #endif
|
b48338 | 2000-06-30 | Martin Stjernholm | | throw (this);
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | case "continue":
continue process_tag;
case "return":
|
2531fa | 2001-03-23 | Martin Stjernholm | | break process_tag;
|
b48338 | 2000-06-30 | Martin Stjernholm | | default:
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Don't you come here and %O on me!\n", action);
|
b48338 | 2000-06-30 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
|
ac6977 | 2000-09-08 | Martin Stjernholm | | else {
THIS_TAG_TOP_DEBUG ("Done\n");
|
0f998b | 2000-08-15 | Martin Stjernholm | | TRACE_LEAVE ("");
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | break process_tag;
} while (1);
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
|
f02d00 | 2000-03-18 | Martin Stjernholm | | if (orig_tag_set) ctx->tag_set = orig_tag_set;
|
01e43b | 2000-01-14 | Martin Stjernholm | | ctx->frame = up;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | ctx->frame_depth--;
if (err1) throw (err1);
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | args = in_args, content = in_content;
|
4c2b51 | 2001-05-17 | Martin Stjernholm | | return conv_result;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
f02d00 | 2000-03-18 | Martin Stjernholm | | MARK_OBJECT;
|
26ff09 | 2000-01-21 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | string _sprintf()
{
|
f02d00 | 2000-03-18 | Martin Stjernholm | | return "RXML.Frame(" + (tag && [string] tag->name) + ")" + OBJ_COUNT;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
}
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
49897a | 2000-02-13 | Martin Stjernholm | |
|
f134b9 | 2000-11-27 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final mixed get_var (string var, void|string scope_name, void|Type want_type)
|
5ad529 | 2000-03-09 | Martin Stjernholm | | {return get_context()->get_var (var, scope_name, want_type);}
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final mixed user_get_var (string var, void|string scope_name, void|Type want_type)
|
5ad529 | 2000-03-09 | Martin Stjernholm | | {return get_context()->user_get_var (var, scope_name, want_type);}
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final mixed set_var (string var, mixed val, void|string scope_name)
|
5ad529 | 2000-03-09 | Martin Stjernholm | | {return get_context()->set_var (var, val, scope_name);}
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final mixed user_set_var (string var, mixed val, void|string scope_name)
|
5ad529 | 2000-03-09 | Martin Stjernholm | | {return get_context()->user_set_var (var, val, scope_name);}
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final void delete_var (string var, void|string scope_name)
|
5ad529 | 2000-03-09 | Martin Stjernholm | | {get_context()->delete_var (var, scope_name);}
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final void user_delete_var (string var, void|string scope_name)
|
5ad529 | 2000-03-09 | Martin Stjernholm | | {get_context()->user_delete_var (var, scope_name);}
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final 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);
|
51f88b | 2000-06-23 | Martin Stjernholm | | array bt = backtrace();
throw (Backtrace ("run", msg, get_context(), bt[..sizeof (bt) - 2]));
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final 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);
|
51f88b | 2000-06-23 | Martin Stjernholm | | array bt = backtrace();
throw (Backtrace ("parse", msg, get_context(), bt[..sizeof (bt) - 2]));
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final void fatal_error (string msg, mixed... args)
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
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]}));
}
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final void throw_fatal (mixed err)
|
8cb24d | 2000-02-13 | Martin Stjernholm | |
{
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")) {
|
c64acf | 2000-02-17 | Martin Stjernholm | | string descr = Backtrace (0, 0)->describe_rxml_backtrace (1);
|
5ed013 | 2000-02-13 | Martin Stjernholm | | 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 | | }
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | final mixed rxml_index (mixed val, string|int|array(string|int) index,
string scope_name, Context ctx, void|Type want_type)
|
4c2b51 | 2001-05-17 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | {
#ifdef MODULE_DEBUG
if (arrayp (index) ? !sizeof (index) : !(stringp (index) || intp (index)))
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Invalid index specifier.\n");
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | #endif
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | int scope_got_type = 0;
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | array(string|int) idxpath;
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | if (arrayp (index)) idxpath = index, index = index[0];
else idxpath = ({0});
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | for (int i = 1;; i++) {
|
1cfbeb | 2000-11-06 | Martin Stjernholm | |
if( arrayp( val ) )
if (intp (index) && index)
if( (index > sizeof( val ))
|| ((index < 0) && (-index > sizeof( val ) )) )
parse_error( "Index %d out of range for array of size %d in %s.\n",
index, sizeof (val), scope_name );
else if( index < 0 )
val = val[index];
else
val = val[index-1];
else
parse_error( "Cannot index the array in %s with %O.\n", scope_name, index );
else if (val == nil)
parse_error ("%s produced no value to index with %O.\n", scope_name, index);
else if( objectp( val ) && val->`[] ) {
|
fe628d | 2001-03-01 | Martin Stjernholm | | #ifdef MODULE_DEBUG
Scope scope = [object(Scope)] val;
#endif
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | if (zero_type (
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | val = ([object(Scope)] val)->`[](
index, ctx, scope_name,
i == sizeof (idxpath) && (scope_got_type = 1, want_type))))
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | val = nil;
|
fe628d | 2001-03-01 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
2531fa | 2001-03-23 | Martin Stjernholm | | else if (mixed err = scope_got_type && want_type && val != nil &&
|
0c9e5b | 2001-03-13 | Martin Stjernholm | | !(objectp (val) && ([object] val)->rxml_var_eval) &&
|
fe628d | 2001-03-01 | Martin Stjernholm | | catch (want_type->type_check (val)))
if (([object] err)->is_RXML_Backtrace)
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("%O->`[] didn't return a value of the correct type:\n%s",
scope, err->msg);
|
fe628d | 2001-03-01 | Martin Stjernholm | | else throw (err);
#endif
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | }
else if( mappingp( val ) || objectp (val) ) {
if (zero_type (val = val[ index ])) val = nil;
}
else if (multisetp (val)) {
if (!val[index]) val = nil;
}
else if (!(<1, -1>)[index])
parse_error ("%s is %O which cannot be indexed with %O.\n",
scope_name, val, index);
|
2b5f47 | 2001-02-11 | Martin Stjernholm | |
if (i == sizeof (idxpath)) break;
scope_name += "." + index;
index = idxpath[i];
#ifdef MODULE_DEBUG
mapping(object:int) called = ([]);
#endif
|
a708be | 2001-06-01 | Johan Sundström | | while (objectp (val) && ([object] val)->rxml_var_eval && !([object] val)->`[]) {
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (called[val])
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Cyclic rxml_var_eval chain detected in %O.\n"
"All called objects:%{ %O%}\n", val, indices (called));
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | called[val] = 1;
#endif
if (zero_type (val = ([object(Value)] val)->rxml_var_eval (
ctx, index, scope_name, 0))) {
val = nil;
break;
}
}
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | }
if (val == nil)
return ([])[0];
else if (!objectp (val) || !([object] val)->rxml_var_eval)
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | if (want_type && !scope_got_type)
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | return
zero_type (val = want_type->encode (val)) || val == nil ? ([])[0] : val;
else
return val;
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | #ifdef MODULE_DEBUG
mapping(object:int) called = ([]);
#endif
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | do {
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | #ifdef MODULE_DEBUG
if (called[val])
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Cyclic rxml_var_eval chain detected in %O.\n"
"All called objects:%{ %O%}\n", val, indices (called));
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | called[val] = 1;
|
fe628d | 2001-03-01 | Martin Stjernholm | | Value val_obj = [object(Value)] val;
|
2b5f47 | 2001-02-11 | Martin Stjernholm | | #endif
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | if (zero_type (val = ([object(Value)] val)->rxml_var_eval (
ctx, index, scope_name, want_type)) ||
val == nil)
return ([])[0];
|
fe628d | 2001-03-01 | Martin Stjernholm | | #ifdef MODULE_DEBUG
else if (mixed err = want_type && catch (want_type->type_check (val)))
if (([object] err)->is_RXML_Backtrace)
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("%O->rxml_var_eval didn't return a value of the correct type:\n%s",
val_obj, err->msg);
|
fe628d | 2001-03-01 | Martin Stjernholm | | else throw (err);
#endif
|
1cfbeb | 2000-11-06 | Martin Stjernholm | | } while (objectp (val) && ([object] val)->rxml_var_eval);
return val;
}
final void tag_debug (string msg, mixed... args)
|
ac6977 | 2000-09-08 | Martin Stjernholm | |
{
if (Frame f = get_context()->frame)
if (f->flags & FLAG_DEBUG)
|
2cab1b | 2001-03-05 | Martin Nilsson | | report_debug (msg, @args);
|
ac6977 | 2000-09-08 | Martin Stjernholm | | }
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final Frame make_tag (string name, mapping(string:mixed) args, void|mixed content,
void|Tag overridden_by)
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | | {
TagSet tag_set = get_context()->tag_set;
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | Tag tag = overridden_by ? tag_set->get_overridden_tag (overridden_by) :
|
51f88b | 2000-06-23 | Martin Stjernholm | | tag_set->get_tag (name);
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | return tag && tag (args, content);
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
f134b9 | 2000-11-27 | Martin Stjernholm | | final Frame make_unparsed_tag (string name, mapping(string:string) args,
void|string content, void|Tag overridden_by)
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | | {
TagSet tag_set = get_context()->tag_set;
|
2e0a6d | 2000-07-06 | Martin Stjernholm | | Tag tag = overridden_by ? tag_set->get_overridden_tag (overridden_by) :
|
51f88b | 2000-06-23 | Martin Stjernholm | | tag_set->get_tag (name);
if (!tag) return 0;
|
49897a | 2000-02-13 | Martin Stjernholm | | Frame frame = tag (args, content);
frame->flags |= FLAG_UNPARSED;
return frame;
}
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
|
49897a | 2000-02-13 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | class parse_frame
|
49897a | 2000-02-13 | Martin Stjernholm | | {
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;
}
|
ac6977 | 2000-09-08 | Martin Stjernholm | | string _sprintf() {return sprintf ("RXML.parse_frame(%O)", content_type);}
|
49897a | 2000-02-13 | Martin Stjernholm | | }
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
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 | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
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);
|
80954c | 2000-03-03 | Martin Stjernholm | | if (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());
|
80954c | 2000-03-03 | Martin Stjernholm | | })
|
56532d | 1999-12-19 | Martin Stjernholm | | if (objectp (err) && ([object] err)->thrown_at_unwind) {
|
c6245b | 1999-12-31 | Martin Stjernholm | | #ifdef DEBUG
|
80954c | 2000-03-03 | Martin Stjernholm | | if (err != this_object()) {
LEAVE_CONTEXT();
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Unexpected unwind object catched.\n");
|
80954c | 2000-03-03 | Martin Stjernholm | | }
|
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;
}
|
80954c | 2000-03-03 | Martin Stjernholm | | else {
LEAVE_CONTEXT();
throw_fatal (err);
}
LEAVE_CONTEXT();
|
ed8175 | 1999-12-11 | Martin Stjernholm | | return res;
}
void write_end (void|string in)
{
int res;
ENTER_CONTEXT (context);
|
80954c | 2000-03-03 | Martin Stjernholm | | if (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());
|
80954c | 2000-03-03 | Martin Stjernholm | | })
|
56532d | 1999-12-19 | Martin Stjernholm | | if (objectp (err) && ([object] err)->thrown_at_unwind) {
|
c6245b | 1999-12-31 | Martin Stjernholm | | #ifdef DEBUG
|
80954c | 2000-03-03 | Martin Stjernholm | | if (err != this_object()) {
LEAVE_CONTEXT();
|
d52f8f | 2001-05-19 | Martin Stjernholm | | fatal_error ("Unexpected unwind object catched.\n");
|
80954c | 2000-03-03 | Martin Stjernholm | | }
|
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;
}
|
80954c | 2000-03-03 | Martin Stjernholm | | else {
LEAVE_CONTEXT();
throw_fatal (err);
}
LEAVE_CONTEXT();
|
429307 | 2001-05-08 | Martin Stjernholm | | #ifdef PROFILE_PARSER
werror ("Profile for %s: %O\n", context->id->not_query, context->profile);
#endif
|
01e43b | 2000-01-14 | Martin Stjernholm | | }
|
d52f8f | 2001-05-19 | Martin Stjernholm | | mixed handle_var (TagSetParser|PCode evaler, string varref, Type want_type)
|
01e43b | 2000-01-14 | Martin Stjernholm | |
{
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (mixed err = catch {
sscanf (varref, "%[^:]:%s", varref, string encoding);
context->current_var = varref;
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | array(string|int) splitted = context->parse_user_var (varref, 1);
if (splitted[0] == 1)
parse_error (
"No scope in variable reference.\n"
"(Use ':' in front to quote a character reference containing dots.)\n");
|
d52f8f | 2001-05-19 | Martin Stjernholm | | #ifdef DEBUG
if (context->frame)
TAG_DEBUG (context->frame, " Looking up variable %s in context of type %s\n",
splitted * ".", (encoding ? t_string : want_type)->name);
#endif
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | mixed val;
|
429307 | 2001-05-08 | Martin Stjernholm | | PROFILE_SWITCH (context, "rxml internal", "var:" + varref);
|
7937df | 2001-05-16 | Per Hedbor | | COND_PROF_ENTER(mixed id=context->id,varref,"entity");
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (zero_type (val = context->get_var (
splitted[1..], splitted[0],
|
d4768a | 2001-05-18 | Martin Stjernholm | | encoding ? t_string : want_type)))
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | val = nil;
|
7937df | 2001-05-16 | Per Hedbor | | COND_PROF_LEAVE(mixed id=context->id,varref,"entity");
|
429307 | 2001-05-08 | Martin Stjernholm | | PROFILE_SWITCH (context, "var:" + varref, "rxml internal");
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (encoding) {
if (!(val = Roxen->roxen_encode (val + "", encoding)))
parse_error ("Unknown encoding %O.\n", encoding);
#ifdef DEBUG
if (context->frame)
TAG_DEBUG (context->frame, " Got value %s after conversion "
"with encoding %s\n", utils->format_short (val), encoding);
#endif
}
#ifdef DEBUG
else
if (context->frame)
TAG_DEBUG (context->frame, " Got value %s\n", utils->format_short (val));
#endif
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | context->current_var = 0;
|
d52f8f | 2001-05-19 | Martin Stjernholm | | if (evaler->p_code)
evaler->p_code->add (VarRef (splitted[0], splitted[1..], encoding));
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | return val;
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | }) {
context->current_var = 0;
context->handle_exception (err, this_object());
return nil;
}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
Context context;
Type type;
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | PCode p_code;
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
56532d | 1999-12-19 | Martin Stjernholm | |
|
140f36 | 2000-10-19 | Martin Stjernholm | | int recover_errors;
|
4d62ba | 2000-08-15 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | mixed feed (string in);
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
void finish (void|string in);
|
8cb24d | 2000-02-13 | Martin Stjernholm | | optional int report_error (string msg);
|
01e43b | 2000-01-14 | Martin Stjernholm | |
|
4d62ba | 2000-08-15 | Martin Stjernholm | |
|
140f36 | 2000-10-19 | Martin Stjernholm | |
|
4d62ba | 2000-08-15 | Martin Stjernholm | |
|
140f36 | 2000-10-19 | Martin Stjernholm | |
|
01e43b | 2000-01-14 | Martin Stjernholm | |
|
c6245b | 1999-12-31 | Martin Stjernholm | | optional mixed read();
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d52f8f | 2001-05-19 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
56532d | 1999-12-19 | Martin Stjernholm | | mixed eval();
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
46c68f | 2000-08-12 | Martin Stjernholm | |
|
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 | |
|
2531fa | 2001-03-23 | 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 | |
|
2531fa | 2001-03-23 | Martin Stjernholm | | static void create (Context ctx, Type type, mixed... args)
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
2531fa | 2001-03-23 | Martin Stjernholm | | initialize (ctx, type);
|
f02d00 | 2000-03-18 | Martin Stjernholm | | #ifdef RXML_OBJ_DEBUG
__object_marker->create (this_object());
#endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
2531fa | 2001-03-23 | Martin Stjernholm | | static void initialize (Context ctx, Type _type)
{
context = ctx;
type = _type;
}
|
51f88b | 2000-06-23 | Martin Stjernholm | | string current_input() {return 0;}
|
2531fa | 2001-03-23 | Martin Stjernholm | |
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | mixed _eval (Context ignored) {return eval();}
|
ed8175 | 1999-12-11 | Martin Stjernholm | | Parser _next_free;
|
c6245b | 1999-12-31 | Martin Stjernholm | |
Parser _parent;
|
a08cd7 | 2001-06-09 | Martin Stjernholm | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
01e43b | 2000-01-14 | Martin Stjernholm | | Stdio.File _source_file;
mapping _defines;
|
f02d00 | 2000-03-18 | Martin Stjernholm | | MARK_OBJECT_ONLY;
|
ec027c | 2000-03-16 | Martin Stjernholm | |
|
f02d00 | 2000-03-18 | Martin Stjernholm | | string _sprintf()
{
|
ac6977 | 2000-09-08 | Martin Stjernholm | | return sprintf ("RXML.Parser(%O)%s", type, OBJ_COUNT);
|
f02d00 | 2000-03-18 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
class TagSetParser
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
inherit Parser;
|
ffa693 | 2000-02-20 | Martin Stjernholm | | constant is_RXML_TagSetParser = 1;
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | constant tag_set_eval = 1;
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
b43689 | 2000-01-19 | Martin Stjernholm | | mixed eval() {return read();}
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | TagSet tag_set;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
d4768a | 2001-05-18 | Martin Stjernholm | | PCode p_code;
|
2531fa | 2001-03-23 | 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 | | {
|
2531fa | 2001-03-23 | Martin Stjernholm | | initialize (ctx, type, tag_set);
|
f02d00 | 2000-03-18 | Martin Stjernholm | | #ifdef RXML_OBJ_DEBUG
__object_marker->create (this_object());
#endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
2531fa | 2001-03-23 | Martin Stjernholm | |
static void initialize (Context ctx, Type type, TagSet _tag_set)
{
::initialize (ctx, type);
tag_set = _tag_set;
|
d4768a | 2001-05-18 | Martin Stjernholm | | p_code = 0;
|
2531fa | 2001-03-23 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
2bd21a | 2000-01-05 | Martin Stjernholm | | mixed read();
|
3187d8 | 2000-01-28 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
|
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 | |
|
24f9e8 | 2000-08-05 | Martin Stjernholm | | optional void remove_runtime_tag (string|Tag tag, void|int proc_instr);
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | string raw_tag_text() {return 0;}
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
950285 | 2000-02-15 | Martin Stjernholm | |
int _local_tag_set;
|
f02d00 | 2000-03-18 | Martin Stjernholm | | string _sprintf()
{
|
ac6977 | 2000-09-08 | Martin Stjernholm | | return sprintf ("RXML.TagSetParser(%O,%O)%s", type, tag_set, OBJ_COUNT);
|
f02d00 | 2000-03-18 | Martin Stjernholm | | }
|
c6245b | 1999-12-31 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | class PNone
{
inherit Parser;
|
d4768a | 2001-05-18 | Martin Stjernholm | | static string data = "";
static int evalpos = 0;
PCode p_code;
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
int feed (string in)
{
data += in;
return 1;
}
void finish (void|string in)
{
if (in) data += in;
|
d4768a | 2001-05-18 | Martin Stjernholm | | if (p_code) p_code->add (data);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
string eval()
{
string res = data[evalpos..];
evalpos = sizeof (data);
return res;
}
void reset (Context ctx)
{
context = ctx;
data = "";
evalpos = 0;
}
|
2bd21a | 2000-01-05 | Martin Stjernholm | |
|
f02d00 | 2000-03-18 | Martin Stjernholm | | string _sprintf() {return "RXML.PNone" + OBJ_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 | | }
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | static mapping(string:Type) reg_types = ([]);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | class Type
|
d4768a | 2001-05-18 | Martin Stjernholm | |
|
0c9e5b | 2001-03-13 | Martin Stjernholm | |
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
constant is_RXML_Type = 1;
|
151fa9 | 2001-04-19 | Johan Sundström | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
int `== (mixed other)
|
fe628d | 2001-03-01 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
|
fe628d | 2001-03-01 | Martin Stjernholm | | return
objectp (other) && ([object] other)->is_RXML_Type &&
|
56532d | 1999-12-19 | Martin Stjernholm | | ([object(Type)] other)->name == this_object()->name;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
int subtype_of (Type other)
|
fe628d | 2001-03-01 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
{
for (Type type = this_object(); type; type = type->supertype)
if (type->name == other->name) return 1;
return 0;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
fe628d | 2001-03-01 | Martin Stjernholm | | int `< (mixed other)
{
if (objectp (other) && ([object] other)->is_RXML_Type) {
if (([object(Type)] other)->name == this_object()->name) return 0;
return subtype_of (other);
}
return this_object()->name < other;
}
int convertible (Type from)
{
if (conversion_type->name == from->name ||
conversion_type->name == from->conversion_type->name ||
this_object()->name == from->conversion_type->name ||
this_object()->name == from->name)
return 1;
for (Type tconv = conversion_type; tconv; tconv = tconv->conversion_type)
for (Type fconv = from->conversion_type; fconv; fconv = fconv->conversion_type)
if (fconv->name == tconv->name)
return 1;
return 0;
}
|
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();
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | newtype->parser_prog = newparser;
newtype->parser_args = parser_args;
|
f02d00 | 2000-03-18 | Martin Stjernholm | | if (newparser->tag_set_eval) newtype->_p_cache = set_weak_flag (([]), 1);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
else {
if (!_t_obj_cache) _t_obj_cache = ([]);
if (!(newtype = _t_obj_cache[newparser]))
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | 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();
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | newtype->parser_prog = newparser;
|
f02d00 | 2000-03-18 | Martin Stjernholm | | if (newparser->tag_set_eval) newtype->_p_cache = set_weak_flag (([]), 1);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
}
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | #ifdef DEBUG
if (reg_types[this_object()->name]->parser_prog != PNone)
error ("Incorrect type object registered in reg_types.\n");
#endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | return newtype;
}
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | inline final 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;
|
ffa693 | 2000-02-20 | Martin Stjernholm | | if (parent && parent->is_RXML_TagSetParser &&
tset == parent->tag_set && sizeof (ctx->runtime_tags) &&
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | parent->clone && parent->type->name == this_object()->name) {
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | p = parent->clone (ctx, this_object(), tset, @parser_args);
|
0ebc9d | 2000-02-15 | Martin Stjernholm | | 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;
|
d4768a | 2001-05-18 | Martin Stjernholm | | p->data_callback = 0;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | p->reset (ctx, this_object(), tset, @parser_args);
|
f02d00 | 2000-03-18 | Martin Stjernholm | | #ifdef RXML_OBJ_DEBUG
p->__object_marker->create (p);
#endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | else
if (pco->clone_parser)
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | p = pco->clone_parser->clone (ctx, this_object(), tset, @parser_args);
else if ((p = parser_prog (ctx, this_object(), tset, @parser_args))->clone) {
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
ec027c | 2000-03-16 | Martin Stjernholm | | p->context = 0;
|
f02d00 | 2000-03-18 | Martin Stjernholm | | #ifdef RXML_OBJ_DEBUG
p->__object_marker->create (p);
#endif
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | p = (pco->clone_parser = p)->clone (ctx, this_object(), tset, @parser_args);
|
ec027c | 2000-03-16 | Martin Stjernholm | | }
|
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;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if ((p = parser_prog (ctx, this_object(), tset, @parser_args))->clone) {
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
ec027c | 2000-03-16 | Martin Stjernholm | | p->context = 0;
|
f02d00 | 2000-03-18 | Martin Stjernholm | | #ifdef RXML_OBJ_DEBUG
p->__object_marker->create (p);
#endif
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | p = (pco->clone_parser = p)->clone (ctx, this_object(), tset, @parser_args);
|
ec027c | 2000-03-16 | Martin Stjernholm | | }
|
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))
|
87fb7e | 2000-03-25 | Martin Stjernholm | | foreach (values (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;
|
d4768a | 2001-05-18 | Martin Stjernholm | | p->data_callback = 0;
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | p->reset (ctx, this_object(), @parser_args);
|
f02d00 | 2000-03-18 | Martin Stjernholm | | #ifdef RXML_OBJ_DEBUG
p->__object_marker->create (p);
#endif
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | else if (clone_parser)
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | p = clone_parser->clone (ctx, this_object(), @parser_args);
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | else if ((p = parser_prog (ctx, this_object(), @parser_args))->clone) {
|
ed8175 | 1999-12-11 | Martin Stjernholm | |
|
ec027c | 2000-03-16 | Martin Stjernholm | | p->context = 0;
|
f02d00 | 2000-03-18 | Martin Stjernholm | | #ifdef RXML_OBJ_DEBUG
p->__object_marker->create (p);
#endif
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | p = (clone_parser = p)->clone (ctx, this_object(), @parser_args);
|
ec027c | 2000-03-16 | Martin Stjernholm | | }
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
|
0ebc9d | 2000-02-15 | Martin Stjernholm | |
p->_parent = parent;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | return p;
}
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | Parser get_pcode_parser (Context ctx, void|TagSet tag_set, void|Parser|PCode parent)
{
Parser p = get_parser (ctx, tag_set, parent);
p->p_code = PCode (this_object());
return p;
}
inline final void give_back (Parser parser, void|TagSet tag_set)
{
#ifdef DEBUG
if (parser->type->name != this_object()->name)
error ("Giving back parser to wrong type.\n");
#endif
if (parser->reset) {
parser->context = parser->recover_errors = parser->_parent = 0;
#ifdef RXML_OBJ_DEBUG
parser->__object_marker->create (p);
#endif
if (_p_cache) {
if (PCacheObj pco = _p_cache[tag_set]) {
parser->_next_free = pco->free_parser;
pco->free_parser = parser;
}
}
else {
parser->_next_free = free_parser;
free_parser = parser;
}
}
}
|
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)
|
51f88b | 2000-06-23 | Martin Stjernholm | |
|
ed8175 | 1999-12-11 | Martin Stjernholm | | {
mixed res;
if (!ctx) ctx = get_context();
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | | if (parser_prog == PNone) res = in;
|
ed8175 | 1999-12-11 | Martin Stjernholm | | else {
|
a08cd7 | 2001-06-09 | Martin Stjernholm | | if (!tag_set) tag_set = ctx->tag_set;
Parser parser = get_parser (ctx, tag_set, parent);
parser->_parent = parent;
if (dont_switch_ctx) parser->finish (in);
else parser->write_end (in);
res = parser->eval();
give_back (parser, tag_set);
|
ed8175 | 1999-12-11 | Martin Stjernholm | | }
if (ctx->type_check) type_check (res);
return res;
}
|
7dd3f8 | 2001-04-18 | Martin Stjernholm | |
program parser_prog =
lambda () {
if (!reg_types[this_object()->name])
reg_types[this_object()->name] = this_object();
return |