<commit_before>package com.hacklanta
package formality

import scala.language.experimental.macros

import net.liftweb.common._
  import HListies._
import net.liftweb.util._
  import Helpers._

object FieldGroup {
  import scala.reflect.macros.whitebox.Context

  def withFieldsImpl(c: Context)(fields: c.Expr[FieldHolderBase[_]]*) = {
    FormalityFormProto.buildFieldsExpression(c)(fields)
  }

  def formalizeImpl(c: Context) = {
    import c.universe._

    val (boxedHlistType, boxedHlistTypes, hlistType, hlistTypes) =
      c.prefix.actualType match {
        case TypeRef(_, _, _ :: boxedValueTypes :: headValueType :: restValueTypes :: Nil) =>
          (
            tq"$boxedValueTypes",
            FormalityFormHelper.unwindHlistTypes(c)(boxedValueTypes),
            tq"net.liftweb.common.HLists.HCons[$headValueType, $restValueTypes]",
            headValueType :: FormalityFormHelper.unwindHlistTypes(c)(restValueTypes)
          )

        case TypeRef(_, thing, other) =>
          (tq"net.liftweb.common.HLists.HNil", Nil, tq"net.liftweb.common.HLists.HNil", Nil)
      }

    if (hlistTypes.length > 22) {
      q"""{
        val initialGroup = ${c.prefix}

        new FieldGroup(
          initialGroup.scopingSelector,
          initialGroup.converter,
          initialGroup.computeValues,
          initialGroup.bindFields
        )
      }"""
    } else {
      val (matcher, parameterList) =
        (0 until hlistTypes.length)
          .reverse
          .foldLeft((q"HNil": c.Tree, List[Ident]())) {
            case ((typeMatch, parameters), _) =>
              val name = TermName(c.freshName("boxedFieldValue$"))

              (pq""":+:($name, $typeMatch)""", q"$name" :: parameters)
          }<commit_msg>Add a friendly error if we can't resolve the field group types.<commit_after>package com.hacklanta
package formality

import scala.language.experimental.macros

import net.liftweb.common._
  import HListies._
import net.liftweb.util._
  import Helpers._

object FieldGroup {
  import scala.reflect.macros.whitebox.Context

  def withFieldsImpl(c: Context)(fields: c.Expr[FieldHolderBase[_]]*) = {
    FormalityFormProto.buildFieldsExpression(c)(fields)
  }

  def formalizeImpl(c: Context) = {
    import c.universe._

    val (boxedHlistType, boxedHlistTypes, hlistType, hlistTypes) =
      c.prefix.actualType match {
        case TypeRef(_, _, _ :: boxedValueTypes :: headValueType :: restValueTypes :: Nil) =>
          (
            tq"$boxedValueTypes",
            FormalityFormHelper.unwindHlistTypes(c)(boxedValueTypes),
            tq"net.liftweb.common.HLists.HCons[$headValueType, $restValueTypes]",
            headValueType :: FormalityFormHelper.unwindHlistTypes(c)(restValueTypes)
          )

        case TypeRef(_, thing, other) =>
          (tq"net.liftweb.common.HLists.HNil", Nil, tq"net.liftweb.common.HLists.HNil", Nil)

        case other =>
          c.abort(
            c.enclosingPosition,
            "Couldn't fully resolve field group types; please make sure you declare the field group and converter in the same expression."
          )
      }

    if (hlistTypes.length > 22) {
      q"""{
        val initialGroup = ${c.prefix}

        new FieldGroup(
          initialGroup.scopingSelector,
          initialGroup.converter,
          initialGroup.computeValues,
          initialGroup.bindFields
        )
      }"""
    } else {
      val (matcher, parameterList) =
        (0 until hlistTypes.length)
          .reverse
          .foldLeft((q"HNil": c.Tree, List[Ident]())) {
            case ((typeMatch, parameters), _) =>
              val name = TermName(c.freshName("boxedFieldValue$"))

              (pq""":+:($name, $typeMatch)""", q"$name" :: parameters)
          }
{'fraction_non_alphanumeric': 0.11927582534611289, 'fraction_numerical': 0.001597444089456869, 'mean_word_length': 2.5815061963775023, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 12, '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': '6268338', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1131, 'n_words': 213}