<commit_before>/*
 * @(#)$Id$
 *
 * This file is distributed under the terms in the attached LICENSE file.
 * If you do not find this file, copies can be found by writing to:
 * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300,
 * Berkeley, CA, 94704.  Attention:  Intel License Inquiry.
 * Or
 * UC Berkeley EECS Computer Science Division, 387 Soda Hall #1776, 
 * Berkeley, CA,  94707. Attention: P2 Group.
 * 
 * DESCRIPTION: Parsing environment for Overlog (the P2 dialect of datalog)
 *
 */

#ifndef __PARSER_UTIL_H__
#define __PARSER_UTIL_H__

#include <deque>
#include <iostream>
#include <map>
#include "value.h"
#include "val_str.h"
#include <string>

class OL_Lexer;

/**
 * A Parse_Expr represents expressions in the Overlog language
 */
class Parse_Expr {
public:
  static Parse_Expr* Now;

  Parse_Expr() : position_(-1) {};
  Parse_Expr(ValuePtr val) : v(val), position_(-1) {};
  Parse_Expr(Parse_Expr *val) : v(val->v), position_(-1) {};

  virtual ~Parse_Expr() {};

  virtual bool operator==(const Parse_Expr &e) 
    { return v == e.v; };

  virtual string toString() = 0;

  virtual void position(int p) { position_ = p; };
  virtual int position() { return position_; }

  ValuePtr v;
  int      position_;
};
typedef std::deque<Parse_Expr *> Parse_ExprList;

// Boxing up a ValuePtr see we can pass it through the Bison parser
// union unscathed. 
class Parse_Val : public Parse_Expr { 
public:
  Parse_Val(ValuePtr val) : Parse_Expr(val), id_(false) {};
  virtual void id(bool i) { id_ = i; };
  virtual bool id() { return id_; };

  virtual string toString() { 
    return v->toString(); 
  };

  virtual ValuePtr value() { return v; };

private:
  bool id_;
};

class Parse_Var : public Parse_Expr { 
public:
  Parse_Var(ValuePtr var) : Parse_Expr(var) {};
  Parse_Var(const string& var) : Parse_Expr(Val_Str::mk(var))  {};

  virtual string toString() { return v->toString(); };
};

class Parse_Agg : public Parse_Expr {
public:
  string oper;

  static Parse_Expr* DONT_CARE;
<commit_msg>print string literals correctly<commit_after>/*
 * @(#)$Id$
 *
 * This file is distributed under the terms in the attached LICENSE file.
 * If you do not find this file, copies can be found by writing to:
 * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300,
 * Berkeley, CA, 94704.  Attention:  Intel License Inquiry.
 * Or
 * UC Berkeley EECS Computer Science Division, 387 Soda Hall #1776, 
 * Berkeley, CA,  94707. Attention: P2 Group.
 * 
 * DESCRIPTION: Parsing environment for Overlog (the P2 dialect of datalog)
 *
 */

#ifndef __PARSER_UTIL_H__
#define __PARSER_UTIL_H__

#include <deque>
#include <iostream>
#include <map>
#include "value.h"
#include "val_str.h"
#include <string>

class OL_Lexer;

/**
 * A Parse_Expr represents expressions in the Overlog language
 */
class Parse_Expr {
public:
  static Parse_Expr* Now;

  Parse_Expr() : position_(-1) {};
  Parse_Expr(ValuePtr val) : v(val), position_(-1) {};
  Parse_Expr(Parse_Expr *val) : v(val->v), position_(-1) {};

  virtual ~Parse_Expr() {};

  virtual bool operator==(const Parse_Expr &e) 
    { return v == e.v; };

  virtual string toString() = 0;

  virtual void position(int p) { position_ = p; };
  virtual int position() { return position_; }

  ValuePtr v;
  int      position_;
};
typedef std::deque<Parse_Expr *> Parse_ExprList;

// Boxing up a ValuePtr see we can pass it through the Bison parser
// union unscathed. 
class Parse_Val : public Parse_Expr { 
public:
  Parse_Val(ValuePtr val) : Parse_Expr(val), id_(false) {};
  virtual void id(bool i) { id_ = i; };
  virtual bool id() { return id_; };

  virtual string toString() { 
    if (v->typeCode() == Value::STR) {
      ostringstream oss; 
      oss << "\"" << v->toString() << "\"";
      return oss.str();
    }
    return v->toString(); 
  };

  virtual ValuePtr value() { return v; };

private:
  bool id_;
};

class Parse_Var : public Parse_Expr { 
public:
  Parse_Var(ValuePtr var) : Parse_Expr(var) {};
  Parse_Var(const string& var) : Parse_Expr(Val_Str::mk(var))  {};

  virtual string toString() { return v->toString(); };
};

class Parse_Agg : public Parse_Expr {
public:
  string oper;

  static Parse_Expr* DONT_CARE;

{'fraction_non_alphanumeric': 0.12936979785969085, 'fraction_numerical': 0.014744351961950059, 'mean_word_length': 3.8400460299194474, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7182026', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1397, 'n_words': 450}