<commit_before>package org.jetbrains.plugins.scala.lang
package parser
package parsing
package top

import com.intellij.psi.tree.IElementType
import org.jetbrains.plugins.scala.ScalaBundle
import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes.{kWITH, tCOMMA}
import org.jetbrains.plugins.scala.lang.parser.parsing.base.Constructor
import org.jetbrains.plugins.scala.lang.parser.parsing.builder.ScalaPsiBuilder

import scala.annotation.tailrec

sealed abstract class Parents(val allowCommaSeparatedParentsInScala3: Boolean = true) extends ParsingRule {
  override def parse(implicit builder: ScalaPsiBuilder): Boolean = {
    val marker = builder.mark()

    if (parseParent()) {
      parseNextSimpleTypes()
    }

    marker.done(ScalaElementType.TEMPLATE_PARENTS)
    true
  }

  @tailrec
  private def parseNextSimpleTypes()(implicit builder: ScalaPsiBuilder): Unit =
    builder.getTokenType match {
      case `kWITH` | CommaIfAllowed() =>
        builder.advanceLexer() // Ate with
        if (parseParent()) {
          parseNextSimpleTypes()
        }
      case _ =>
    }

  private def parseParent()(implicit builder: ScalaPsiBuilder): Boolean = {
    val result = Constructor()

    if (!result) {
      builder.error(ScalaBundle.message("identifier.expected"))
    }

    result
  }

  private object CommaIfAllowed {
    def unapply(element: IElementType)(implicit builder: ScalaPsiBuilder): Boolean =
      element == tCOMMA && builder.isScala3 && allowCommaSeparatedParentsInScala3
  }
}


object NewTemplateDefParents extends Parents(allowCommaSeparatedParentsInScala3 = false)
object TypeDefinitionParents extends Parents<commit_msg>Fix parsing of parents for ScNewTemplateDefinitions in scala 3<commit_after>package org.jetbrains.plugins.scala.lang
package parser
package parsing
package top

import com.intellij.psi.tree.IElementType
import org.jetbrains.plugins.scala.ScalaBundle
import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes.{kWITH, tCOMMA}
import org.jetbrains.plugins.scala.lang.parser.parsing.base.Constructor
import org.jetbrains.plugins.scala.lang.parser.parsing.builder.ScalaPsiBuilder

import scala.annotation.tailrec

sealed abstract class Parents(
  val allowCommaSeparatedParentsInScala3: Boolean = true,
  val allowEmptyParents:                  Boolean = false
) extends ParsingRule {
  override def parse(implicit builder: ScalaPsiBuilder): Boolean = {
    val marker = builder.mark()

    if (parseParent()) {
      parseNextSimpleTypes()
    }

    marker.done(ScalaElementType.TEMPLATE_PARENTS)
    true
  }

  @tailrec
  private def parseNextSimpleTypes()(implicit builder: ScalaPsiBuilder): Unit =
    builder.getTokenType match {
      case `kWITH` | CommaIfAllowed() =>
        builder.advanceLexer() // Ate with
        if (parseParent()) {
          parseNextSimpleTypes()
        }
      case _ =>
    }

  private def parseParent()(implicit builder: ScalaPsiBuilder): Boolean = {
    val result = Constructor()

    if (!result && !allowEmptyParents) {
      builder.error(ScalaBundle.message("identifier.expected"))
    }

    result
  }

  private object CommaIfAllowed {
    def unapply(element: IElementType)(implicit builder: ScalaPsiBuilder): Boolean =
      element == tCOMMA && builder.isScala3 && allowCommaSeparatedParentsInScala3
  }
}

object NewTemplateDefParents extends Parents(allowCommaSeparatedParentsInScala3 = false, allowEmptyParents = true)
object TypeDefinitionParents extends Parents
{'fraction_non_alphanumeric': 0.08915731952832902, 'fraction_numerical': 0.0025884383088869713, 'mean_word_length': 4.152592592592592, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2774099', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1015, 'n_words': 211}