<commit_before>#include "pprint/js_pprint.hpp"

#include <math.h>

#include <vector>
#include <memory>

#include "pprint/generic_term_walker.hpp"
#include "rdb_protocol/ql2_extensions.pb.h"
#include "debug.hpp"

namespace pprint {

// we know what we're doing here, and I don't think 169 random
// Term types is going to clarify anything.
#pragma GCC diagnostic ignored "-Wswitch-enum"

class js_pretty_printer_t
    : public generic_term_walker_t<counted_t<const document_t> > {
    unsigned int depth;
    bool prepend_ok, in_r_expr;
    typedef std::vector<counted_t<const document_t> > v;
public:
    js_pretty_printer_t() : depth(0), prepend_ok(true), in_r_expr(false) {}
protected:
    counted_t<const document_t> visit_generic(Term *t) override {
        bool old_r_expr = in_r_expr;
        ++depth;
        if (depth > MAX_DEPTH) return dotdotdot; // Crude attempt to avoid blowing stack
        counted_t<const document_t> doc;
        switch (t->type()) {
        case Term::DATUM:
            doc = to_js_datum(t->mutable_datum());
            if (!in_r_expr) {
                doc = prepend_r_expr(doc);
            }
            break;
        case Term::FUNCALL:
            // Hack here: JS users expect .do in suffix position if
            // there's only one argument.
            if (t->args_size() == 2) {
                doc = string_dots_together(t);
            } else {
                doc = toplevel_funcall(t);
            }
            break;
        case Term::DB:
        case Term::TABLE:
            guarantee(t->args_size() == 1);
            guarantee(t->mutable_args(0)->type() == Term::DATUM);
            doc = prepend_r_dot(make_c(make_text(to_js_name(t)),
                                       wrap_parens(to_js_datum(t->mutable_args(0)->mutable_datum()))));
            break;
        case Term::MAKE_ARRAY:
            in_r_expr = true;
            doc = to_js_array(t);
            if (!old_r_expr) {
                doc = prepend_r_expr(doc);
            }
            break;
        case Term::MAKE_OBJ:
            in_r_expr = true;
            if (old_r_expr) {
                doc = to_js_natural_object(t);<commit_msg>Don't need this any more.<commit_after>#include "pprint/js_pprint.hpp"

#include <math.h>

#include <vector>
#include <memory>

#include "pprint/generic_term_walker.hpp"
#include "rdb_protocol/ql2_extensions.pb.h"
#include "debug.hpp"

namespace pprint {

// we know what we're doing here, and I don't think 169 random
// Term types is going to clarify anything.
#pragma GCC diagnostic ignored "-Wswitch-enum"

class js_pretty_printer_t
    : public generic_term_walker_t<counted_t<const document_t> > {
    unsigned int depth;
    bool prepend_ok, in_r_expr;
    typedef std::vector<counted_t<const document_t> > v;
public:
    js_pretty_printer_t() : depth(0), prepend_ok(true), in_r_expr(false) {}
protected:
    counted_t<const document_t> visit_generic(Term *t) override {
        bool old_r_expr = in_r_expr;
        ++depth;
        if (depth > MAX_DEPTH) return dotdotdot; // Crude attempt to avoid blowing stack
        counted_t<const document_t> doc;
        switch (t->type()) {
        case Term::DATUM:
            doc = to_js_datum(t->mutable_datum());
            if (!in_r_expr) {
                doc = prepend_r_expr(doc);
            }
            break;
        case Term::FUNCALL:
            // Hack here: JS users expect .do in suffix position if
            // there's only one argument.
            if (t->args_size() == 2) {
                doc = string_dots_together(t);
            } else {
                doc = toplevel_funcall(t);
            }
            break;
        case Term::MAKE_ARRAY:
            in_r_expr = true;
            doc = to_js_array(t);
            if (!old_r_expr) {
                doc = prepend_r_expr(doc);
            }
            break;
        case Term::MAKE_OBJ:
            in_r_expr = true;
            if (old_r_expr) {
                doc = to_js_natural_object(t);
{'fraction_non_alphanumeric': 0.10852713178294573, 'fraction_numerical': 0.0037509377344336083, 'mean_word_length': 2.074558032282859, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5865734', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1285, 'n_words': 293}