<commit_before>jQuery(document).ready(function ($) {
  var Env = Ibis.Env;
  var Parser = Ibis.Parser;
  var Inferer = Ibis.Inferer;
  var Eva = Ibis.Eva;
  var Type = Ibis.Type;
  var Value = Ibis.Value;
  var Compat = Ibis.Compat;
  var Default = Ibis.Default;
  var IbisError = Ibis.IbisError;
  
  var env = Default.createEnv();
  var valueEnv = env.valueEnv;
  var typeCtxt = env.typeCtxt;
  var typeEnv = env.typeEnv;
  var variants = Env.createGlobal({});
  var slideArray;
  var currentExpression;
  var currentInferenceStep;
  
  $("#interpret").click(function () {
    var input = $("#edit").val();
    var parser = Parser.ofString(input);
    var visual = null;
    var result = "";
    initSlide();
    try {
      while (true) {
        visual = { root: null, slides: [] };
        var expr = Parser.parse(parser);
        if (!expr) {
          break;
        }
        visual.root = expr;
        var type = Inferer.infer(typeCtxt, typeEnv, variants, visual, expr);
        var value = Eva.eval(valueEnv, expr);
        result += "- : " + type + " = " + value + "\n";
        setSlide(visual.slides);
      }
    } catch (e) {
      if (e instanceof IbisError) {
        result += "ERROR: " + e.message + "\n";
        if (visual.slides.length != 0) {
          setSlide(visual.slides);
        }
      } else {
        throw e;
      }
    } finally {
      $("#result").val(result);
    }
  });
  
  function initSlide() {
    slideArray = [];
    currentExpression = -1;
    currentInferenceStep = -1;
    $("#inference .first").attr("disabled", true);
    $("#inference .prev").attr("disabled", true);
    $("#inference .next").attr("disabled", true);
    $("#inference .last").attr("disabled", true);
    $("#screen").val("");
  }
  
  function setSlide(slides) {
    slideArray.push(slides);
    currentExpression++;
    currentInferenceStep = slides.length - 1;
    updateScreen();
  }
  
  function updateScreen() {
    $("#inference .first").attr("disabled", false);
    $("#inference .prev").attr("disabled", false);
    $("#inference .next").attr("disabled", false);
    $("#inference .last").attr("disabled", false);
    if (currentInferenceStep <= 0) {
      $("#inference .first").attr("disabled", true);
      $("#inference .prev").attr("disabled", true);
    }
    if (currentInferenceStep >= slideArray[currentExpression].length - 1) {
      $("#inference .next").attr("disabled", true);
      $("#inference .last").attr("disabled", true);
    }
    var scrollTop = $("#screen").scrollTop();
    $("#screen").val(slideArray[currentExpression][currentInferenceStep]);
    $("#screen").scrollTop(scrollTop);
  }
  
  $("#inference .first").click(function () {
    currentInferenceStep = 0;
    updateScreen();
  });
  
  $("#inference .prev").click(function () {
    if (currentInferenceStep != 0) {
      currentInferenceStep--;
      updateScreen();
    }
  });
  
  $("#inference .next").click(function () {
    if (currentInferenceStep != slideArray[currentExpression].length - 1) {
      currentInferenceStep++;
      updateScreen();
    }
  });
  
  $("#inference .last").click(function () {
    currentInferenceStep = slideArray[currentExpression].length - 1<commit_msg>Support multiple expressions in slideshow<commit_after>jQuery(document).ready(function ($) {
  var Env = Ibis.Env;
  var Parser = Ibis.Parser;
  var Inferer = Ibis.Inferer;
  var Eva = Ibis.Eva;
  var Type = Ibis.Type;
  var Value = Ibis.Value;
  var Compat = Ibis.Compat;
  var Default = Ibis.Default;
  var IbisError = Ibis.IbisError;
  
  var env = Default.createEnv();
  var valueEnv = env.valueEnv;
  var typeCtxt = env.typeCtxt;
  var typeEnv = env.typeEnv;
  var variants = Env.createGlobal({});
  var slideArray;
  var currentExpression;
  var currentInferenceStep;
  
  $("#interpret").click(function () {
    var input = $("#edit").val();
    var parser = Parser.ofString(input);
    var visual = null;
    var result = "";
    initSlide();
    try {
      while (true) {
        visual = { root: null, slides: [] };
        var expr = Parser.parse(parser);
        if (!expr) {
          break;
        }
        visual.root = expr;
        var type = Inferer.infer(typeCtxt, typeEnv, variants, visual, expr);
        var value = Eva.eval(valueEnv, expr);
        result += "- : " + type + " = " + value + "\n";
        setSlide(visual.slides);
      }
    } catch (e) {
      if (e instanceof IbisError) {
        result += "ERROR: " + e.message + "\n";
        if (visual.slides.length != 0) {
          setSlide(visual.slides);
        }
      } else {
        throw e;
      }
    } finally {
      $("#result").val(result);
    }
  });
  
  function initSlide() {
    slideArray = [];
    currentExpression = -1;
    currentInferenceStep = -1;
    $("#expression > *").attr("disabled", true);
    $("#inference > *").attr("disabled", true);
    $("#screen").val("");
  }
  
  function setSlide(slides) {
    slideArray.push(slides);
    currentExpression++;
    currentInferenceStep = slides.length - 1;
    updateScreen();
  }
  
  function updateScreen() {
    $("#expression > *").attr("disabled", false);
    $("#inference > *").attr("disabled", false);
    if (currentExpression <= 0) {
      $("#expression .first").attr("disabled", true);
      $("#expression .prev").attr("disabled", true);
    }
    if (currentExpression >= slideArray.length - 1) {
      $("#expression .next").attr("disabled", true);
      $("#expression .last").attr("disabled", true);
    }
    if (currentInferenceStep <= 0) {
      $("#inference .first").attr("disabled", true);
      $("#inference .prev").attr("disabled", true);
    }
    if (currentInferenceStep >= slideArray[currentExpression].length - 1) {
      $("#inference .next").attr("disabled", true);
      $("#inference .last").attr("disabled", true);
    }
    var scrollTop = $("#screen").scrollTop();
    $("#screen").val(slideArray[currentExpression][currentInferenceStep]);
    $("#screen").scrollTop(scrollTop);
  }
  
  $("#expression .first").click(function () {
    currentExpression = 0;
    currentInferenceStep = slideArray[currentExpression].length - 1;
    updateScreen();
  });
  
  $("#expression .prev").click(function () {
    if (currentExpression != 0) {
      currentExpression--;
      currentInferenceStep = slideArray[currentExpression].length - 1;
      updateScreen();
    }
  });
  
  $("#expression .next").click(function () {
    if (currentExpression != slideArray.length - 1) {
      currentExpression++;
      currentInferenceStep = slideArray[currentExpression].length - 1;
      updateScreen();
    }
  });
  
  $("#expression .last").click(function () {
    currentExpression = slideArray.length - 1
    currentInferenceStep = slideArray[currentExpression].length - 1;
    updateScreen();
  });
  
  $("#inference .first").click(function () {
    currentInferenceStep = 0;
    updateScreen();
  });
  
  $("#inference .prev").click(function () {
    if (currentInferenceStep != 0) {
      currentInferenceStep--;
      updateScreen();
    }
  });
  
  $("#inference .next").click(function () {
    if (currentInferenceStep != slideArray[currentExpression].length - 1) {
      currentInferenceStep++;
      updateScreen();
    }
  });
  
  $("#inference .last").click(function () {
    currentInferenceStep = slideArray[currentExpression].length - 1
{'fraction_non_alphanumeric': 0.17530259757921937, 'fraction_numerical': 0.004079967360261118, 'mean_word_length': 2.8242329693187727, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, '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': '573332', 'n_tokens_mistral': 2262, 'n_tokens_neox': 2271, 'n_words': 454}