/
CDC-1.2b/
CDC-1.2b/src/
parent $root_evaluator
object $format_evaluator

var $root dbref 'format_evaluator
var $root child_index 1
var $root fertile 0
var $root manager $format_evaluator
var $root owned [$format_evaluator]
var $root owners [$]
var $root writable []
var $root readable ['parameters, 'methods, 'code]
var $prep_evaluator append_str "_stmt"
var $root inited 1

method ul_stmt
    arg vars, args, indent;
    
    return .list_type(dict_add(vars, 'context, 'list), args, indent + 1);
.

method br_stmt
    arg vars, term, indent;
    
    return ["", ""];
.

method string_type
    arg vars, term, indent;
    
    return term;
.

method eval_ctext
    arg vars, term;
    
    if (listlen(term) == 1)
        term = term[1];
    if (term) {
        if (!('context in dict_keys(vars)))
            vars = dict_add(vars, 'context, 'string);
        return .(term[1])(vars, term[2], 0);
    }
    return "";
.

method list_type
    arg vars, args, indent;
    var t, output, result, last;
    
    output = [];
    for t in (args) {
        result = .(t[1])(vars, t[2], indent);
        if ((vars['context]) == 'list) {
            if (type(result) == 'string)
                output = [@output, ._eol(vars, result, indent)];
            else
                output = [@output, @result];
        } else if (type(result) == 'string) {
            output = output.join(result);
        } else {
            output = output.join(result.to_string(" "));
        }
    }
    return output;
.

method p_stmt
    arg vars, args, indent;
    
    return ["", "", ""];
.

method anchor_stmt
    arg vars, args, indent;
    
    return ("/" + ((args[1])[2])) + "/";
.

method dbref_type
    arg vars, term;
    
    return (term[2]).dbref();
.

method symbol_type
    arg vars, args, indent;
    
    return tostr(args);
.

method text_stmt
    arg vars, args, indent;
    var t, output, result;
    
    output = [];
    for t in (args) {
        catch ~methodnf {
            result = .(t[1])(vars, t[2], indent);
        } with handler {
            result = (">>ERROR: unknown method " + ($data.unparse(t[1]))) + "<<";
        }
        output = output.join(result);
    }
    if (listlen(output) == 1)
        return output[1];
    return output;
.

method _line_stmt
    arg vars, args;
    
    return "";
.

method bold_stmt
    arg vars, args;
    
    return uppercase(args[1]);
.

method b_stmt
    arg vars, args;
    
    return uppercase(.eval_ctext(vars, args[1]));
.

method strong_stmt
    arg vars, args, indent;
    
    return uppercase(.eval_ctext(vars, args[1]));
.

method dfn_stmt
    arg vars, args, indent;
    var term, defn, l, lines, a;
    
    term = .((args[1])[1])(vars, (args[1])[2], indent);
    term = ._eol(vars, term, indent);
    defn = .ul_stmt(vars, sublist(args, 2), indent);
    return [term, @defn];
.

method _indent
    arg what, [by];
    
    // prepends <what> with <by>
    //if (by)
    //  return by[1]+what;
    //else
    return "  " + what;
.

method integer_type
    arg vars, args;
    
    return tostr(args);
.

method evaluator
    arg vars, args, indent;
    
    vars = dict_add(vars, 'force, 1);
    vars = dict_add(vars, 'delay, 0);
    vars = ((args[1])[2])._eval_ctext(vars, args[2]);
    return (vars['result])[2];
.

method error_stmt
    arg vars, args;
    
    return $list.join(">>ERROR: ", $list.join(.((args[1])[1])(vars, (args[1])[2]), "<<"));
.

method integer
    arg vars, term, indent;
    
    return tostr(term[2]);
.

method _eol
    arg vars, line, indent;
    
    //handles indention for 1 line.
    return ("  ".repeat(indent)) + line;
.

method header_stmt
    arg vars, args, indent;
    var href, text, anchors;
    
    text = (args[1])[2];
    return [text, pad("", strlen(text), "-"), "", ""];
.

method evalctext
    arg vars, term;
    
    if (listlen(term) == 1)
        term = term[1];
    if (term) {
        if (!('context in dict_keys(vars)))
            vars = dict_add(vars, 'context, 'string);
        return .(term[1])(vars, term[2], 0);
    }
    return "";
.