<commit_before>import React from 'react';

class Lazy extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      reprValue: null
    };
    this.expand = this.expand.bind(this);
  }
  expand() {
    this.setState({reprValue: this.props.reprValue.getValue()});
  }
  render() {
    if (this.state.reprValue === null) {
      return <button onClick={this.expand}>&lt;click to expand&gt;</button>;
    } else {
      return <REPLValue reprValue={this.state.reprValue} />;
    }
  }
}
Lazy.propTypes = {reprValue: React.PropTypes.object};

function Opaque() {
  return <span>&lt;opaque&gt;</span>;
}

function Cyclic() {
  return <span>&lt;cyclic&gt;</span>;
}

function Image() {
  return <span>Image</span>;
}

const NumberProp = React.PropTypes.oneOfType([
  React.PropTypes.shape({
    numerator: React.PropTypes.number,
    denominator: React.PropTypes.number,
    whole: React.PropTypes.number,
    fractional: React.PropTypes.number,
    repeating: React.PropTypes.number,
  })
]);

const ReprValueProp = (valuePropType) => React.PropTypes.shape({
  type: React.PropTypes.string.isRequired,
  value: valuePropType
});

class Number extends React.Component {
  static propTypes = {
    reprValue: ReprValueProp(NumberProp)
  };

  state = {showFraction: false};

  toggleFraction = () => {
    this.setState({showFraction: !this.state.showFraction});
  }

  render() {
    if (typeof this.props.reprValue.value === "object") {
      const {
        numerator,
        denominator,
        whole,
        fractional,
        repeating
      } = this.props.reprValue.value;
      let text = `${whole}.${fractional}${repeating}`;
      if (this.state.showFraction) {
        text = `${numerator}/${denominator}`;
      }
      return (
        <button onClick={this.toggleFraction}>
          {text}
        </button>
      );
    }
    return <span>{this.props.reprValue.value}</span>;
  }
}

function Nothing() {
  return <span>&lt;nothing&gt;</span>;
}
Nothing.propTypes = {reprValue: React.PropTypes.object};

function Boolean({reprValue}) {
  return <span>{reprValue.value ? "true" : "false"}</span>;
}
Boolean.propTypes = {reprValue: React.PropTypes.object};

function String({reprValue}) {
  return <span>{`"${reprValue.value}"`}</span>;
}
String.propTypes = {reprValue: React.PropTypes.object};

function Method() {
  return <span>&lt;method&gt;</span>;
}

function Func() {
  return <span>&lt;func&gt;</span>;
}

function Array({reprValue}) {
  return (
    <span>
      [
      {reprValue.values.map((item, index) => (
        <span>
          <REPLValue reprValue={item} />
          {index < reprValue.values.length - 1 && ", "}
        </span>
       ))}
         ]
    </span>
  );
}
Array.propTypes = {reprValue: React.PropTypes.object};

function Ref() {
  return <span>Ref</span>;
}

function Tuple({reprValue}) {
  return (
    <span>
      (
      {reprValue.values.map((item, index) => (
        <span>
          <REPLValue reprValue={item} />
          {index < reprValue.values.length - 1 && ", "}
        </span>
       ))}
         )
    </span>
  );
}
Tuple.propTypes = {reprValue: React.PropTypes.object};

function Obj({reprValue}) {
  console.log("got repr values keyValues", reprValue.keyValues);

  return (
    <dl>
      {reprValue.keyValues.map(
         ({key, value}) => [
           <dt key={`dt-${key}`}>{key}</dt>,
           <dd key={`dd-${key}`}><REPLValue reprValue={value} /></dd>
         ]
       )}
    </dl>
  );
}
Obj.propTypes = {reprValue: React.PropTypes.shape({
  type: React.PropTypes.string,
  keyValues: React.PropTypes.arrayOf(React.PropTypes.shape({
    key: React.PropTypes.string,
    value: React.PropTypes.object,
  }))
})};

function Data() {
  return <span>Data</span>;
}

function StandardOut({reprValue}) {
  return <span>stdout: {reprValue.value}</span>;
}
StandardOut.propTypes = {
  reprValue: ReprValueProp(React.PropTypes.string),
};

function StandardError({reprValue}) {
  return <span>stderr: {reprValue.value}</span>;
}
StandardError.propTypes = {
  reprValue: ReprValueProp(React.PropTypes.string),
};


const RENDERERS = {
  opaque: Opaque,
  cyclic: Cyclic,
  image: Image,
  number: Number,
  nothing: Nothing,
  boolean: Boolean,
  string: String,
  method: Method,
  func: Func,
  array: Array,
  ref: Ref,
  tuple: Tuple,
  object: Obj,
  data: Data,
  lazy: Lazy,
  stdout: StandardOut,
  stderr: StandardError,
};


export default function REPLValue({reprValue}) {
  var renderer = typeof reprValue === "object" && RENDERERS[reprValue.type];
  if (!renderer) {
    return <span>{`UNRENDERABLE: ${JSON.stringify(reprValue)}`}</span>;
  }
  return React.createElement(renderer, {reprValue});
}<commit_msg>Consistently name these "*Value" to avoid clashing with builtins<commit_after>import React from 'react';

class LazyValue extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      reprValue: null
    };
    this.expand = this.expand.bind(this);
  }
  expand() {
    this.setState({reprValue: this.props.reprValue.getValue()});
  }
  render() {
    if (this.state.reprValue === null) {
      return <button onClick={this.expand}>&lt;click to expand&gt;</button>;
    } else {
      return <REPLValue reprValue={this.state.reprValue} />;
    }
  }
}
LazyValue.propTypes = {reprValue: React.PropTypes.object};

function OpaqueValue() {
  return <span>&lt;opaque&gt;</span>;
}

function CyclicValue() {
  return <span>&lt;cyclic&gt;</span>;
}

function ImageValue() {
  return <span>Image</span>;
}

const NumberProp = React.PropTypes.oneOfType([
  React.PropTypes.shape({
    numerator: React.PropTypes.number,
    denominator: React.PropTypes.number,
    whole: React.PropTypes.number,
    fractional: React.PropTypes.number,
    repeating: React.PropTypes.number,
  })
]);

const ReprValueProp = (valuePropType) => React.PropTypes.shape({
  type: React.PropTypes.string.isRequired,
  value: valuePropType
});

class NumberValue extends React.Component {
  static propTypes = {
    reprValue: ReprValueProp(NumberProp)
  };

  state = {showFraction: false};

  toggleFraction = () => {
    this.setState({showFraction: !this.state.showFraction});
  }

  render() {
    if (typeof this.props.reprValue.value === "object") {
      const {
        numerator,
        denominator,
        whole,
        fractional,
        repeating
      } = this.props.reprValue.value;
      let text = `${whole}.${fractional}${repeating}`;
      if (this.state.showFraction) {
        text = `${numerator}/${denominator}`;
      }
      return (
        <button onClick={this.toggleFraction}>
          {text}
        </button>
      );
    }
    return <span>{this.props.reprValue.value}</span>;
  }
}

function NothingValue() {
  return <span>&lt;nothing&gt;</span>;
}
NothingValue.propTypes = {reprValue: React.PropTypes.object};

function BooleanValue({reprValue}) {
  return <span>{reprValue.value ? "true" : "false"}</span>;
}
BooleanValue.propTypes = {reprValue: React.PropTypes.object};

function StringValue({reprValue}) {
  return <span>{`"${reprValue.value}"`}</span>;
}
StringValue.propTypes = {reprValue: React.PropTypes.object};

function MethodValue() {
  return <span>&lt;method&gt;</span>;
}

function FuncValue() {
  return <span>&lt;func&gt;</span>;
}

function ArrayValue({reprValue}) {
  return (
    <span>
      [
      {reprValue.values.map((item, index) => (
        <span>
          <REPLValue reprValue={item} />
          {index < reprValue.values.length - 1 && ", "}
        </span>
       ))}
         ]
    </span>
  );
}
ArrayValue.propTypes = {reprValue: React.PropTypes.object};

function RefValue() {
  return <span>Ref</span>;
}

function TupleValue({reprValue}) {
  return (
    <span>
      (
      {reprValue.values.map((item, index) => (
        <span>
          <REPLValue reprValue={item} />
          {index < reprValue.values.length - 1 && ", "}
        </span>
       ))}
         )
    </span>
  );
}
TupleValue.propTypes = {reprValue: React.PropTypes.object};

function ObjValue({reprValue}) {
  return (
    <dl>
      {reprValue.keyValues.map(
         ({key, value}) => [
           <dt key={`dt-${key}`}>{key}</dt>,
           <dd key={`dd-${key}`}><REPLValue reprValue={value} /></dd>
         ]
       )}
    </dl>
  );
}
ObjValue.propTypes = {reprValue: React.PropTypes.shape({
  type: React.PropTypes.string,
  keyValues: React.PropTypes.arrayOf(React.PropTypes.shape({
    key: React.PropTypes.string,
    value: React.PropTypes.object,
  }))
})};

function DataValue() {
  return <span>Data</span>;
}

function StandardOut({reprValue}) {
  return <span>stdout: {reprValue.value}</span>;
}
StandardOut.propTypes = {
  reprValue: ReprValueProp(React.PropTypes.string),
};

function StandardError({reprValue}) {
  return <span>stderr: {reprValue.value}</span>;
}
StandardError.propTypes = {
  reprValue: ReprValueProp(React.PropTypes.string),
};


const RENDERERS = {
  opaque: OpaqueValue,
  cyclic: CyclicValue,
  image: ImageValue,
  number: NumberValue,
  nothing: NothingValue,
  boolean: BooleanValue,
  string: StringValue,
  method: MethodValue,
  func: FuncValue,
  array: ArrayValue,
  ref: RefValue,
  tuple: TupleValue,
  object: ObjValue,
  data: DataValue,
  lazy: LazyValue,
  stdout: StandardOut,
  stderr: StandardError,
};


export default function REPLValue({reprValue}) {
  var renderer = typeof reprValue === "object" && RENDERERS[reprValue.type];
  if (!renderer) {
    return <span>{`UNRENDERABLE: ${JSON.stringify(reprValue)}`}</span>;
  }
  return React.createElement(renderer, {reprValue});
}
{'fraction_non_alphanumeric': 0.1642024156601416, 'fraction_numerical': 0.00041649312786339027, 'mean_word_length': 3.251881363435148, 'pattern_counts': {'":': 0, '<': 107, '<?xml version=': 0, '>': 113, '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': '331416', 'n_tokens_mistral': 3303, 'n_tokens_neox': 3288, 'n_words': 565}