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

import com.intellij.lang.PsiBuilder, org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes
import org.jetbrains.plugins.scala.lang.parser.ScalaElementTypes
import org.jetbrains.plugins.scala.ScalaBundle
import builder.ScalaPsiBuilder

/**
* @author <NAME>
* Date: 15.02.2008
*/

/*
 * SimpleType ::= SimpleType TypeArgs
 *              | SimpleType '#' id
 *              | StableId
 *              | Path '.' 'type'
 *              | '(' Types [','] ')'
 */

object SimpleType {
  def parse(builder: ScalaPsiBuilder): Boolean = {

    def parseTail(curMarker: PsiBuilder.Marker) {
      builder.getTokenType match {
        case ScalaTokenTypes.tLSQBRACKET => {
          val newMarker = curMarker.precede
          TypeArgs parse builder
          curMarker.done(ScalaElementTypes.TYPE_GENERIC_CALL)
          parseTail(newMarker)
        }
        case ScalaTokenTypes.tINNER_CLASS => {
          val newMarker = curMarker.precede
          builder.advanceLexer() //Ate #
          builder.getTokenType match {
            case ScalaTokenTypes.tIDENTIFIER => {
              builder.advanceLexer() //Ate id
              curMarker.done(ScalaElementTypes.TYPE_PROJECTION)
              parseTail(newMarker)
            }
            case _ => {
              newMarker.drop()
              curMarker.drop()
            }
          }
        }
        case _ => {
          curMarker.drop()
        }
      }
    }

    val simpleMarker = builder.mark
    builder.getTokenType match {
      case ScalaTokenTypes.tLPARENTHESIS => {
        val tupleMarker = builder.mark
        builder.advanceLexer()
        builder.disableNewlines
        val (_, isTuple) = Types parse builder
        builder.getTokenType match {
          case ScalaTokenTypes.tCOMMA => {
            builder.advanceLexer() //Ate ,
            builder.getTokenType match {
              case ScalaTokenTypes.tRPARENTHESIS => {
                builder.advanceLexer() //Ate )
                tupleMarker.done(ScalaElementTypes.TUPLE_TYPE)
              }
              case _ => {
                builder error ScalaBundle.message("rparenthesis.expacted")
                tupleMarker.done(ScalaElementTypes.TUPLE_TYPE)
              }
            }
          }
          case ScalaTokenTypes.tRPARENTHESIS => {
            builder.advanceLexer() //Ate )
            if (isTuple) tupleMarker.done(ScalaElementTypes.TUPLE_TYPE)
            else tupleMarker.done(ScalaElementTypes.TYPE_IN_PARENTHESIS)
          }
          case _ => {
            builder error ScalaBundle.message("rparenthesis.expected")
            if (isTuple) tupleMarker.done(ScalaElementTypes.TUPLE_TYPE)
            else tupleMarker.done(ScalaElementTypes.TYPE_IN_PARENTHESIS)
          }
        }
        builder.restoreNewlinesState
      }
      case ScalaTokenTypes.kTHIS |<commit_msg>parser patched to avoid NPE<commit_after>package org.jetbrains.plugins.scala
package lang
package parser
package parsing
package types

import com.intellij.lang.PsiBuilder, org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes
import org.jetbrains.plugins.scala.lang.parser.ScalaElementTypes
import org.jetbrains.plugins.scala.ScalaBundle
import builder.ScalaPsiBuilder

/**
* @author <NAME>
* Date: 15.02.2008
*/

/*
 * SimpleType ::= SimpleType TypeArgs
 *              | SimpleType '#' id
 *              | StableId
 *              | Path '.' 'type'
 *              | '(' Types [','] ')'
 */

object SimpleType {
  def parse(builder: ScalaPsiBuilder): Boolean = {

    def parseTail(curMarker: PsiBuilder.Marker) {
      builder.getTokenType match {
        case ScalaTokenTypes.tLSQBRACKET => {
          val newMarker = curMarker.precede
          TypeArgs parse builder
          curMarker.done(ScalaElementTypes.TYPE_GENERIC_CALL)
          parseTail(newMarker)
        }
        case ScalaTokenTypes.tINNER_CLASS => {
          val newMarker = curMarker.precede
          builder.advanceLexer() //Ate #
          builder.getTokenType match {
            case ScalaTokenTypes.tIDENTIFIER => {
              builder.advanceLexer() //Ate id
              curMarker.done(ScalaElementTypes.TYPE_PROJECTION)
              parseTail(newMarker)
            }
            case _ => {
              newMarker.drop()
              curMarker.drop()
            }
          }
        }
        case _ => {
          curMarker.drop()
        }
      }
    }

    val simpleMarker = builder.mark
    builder.getTokenType match {
      case ScalaTokenTypes.tLPARENTHESIS => {
        val tupleMarker = builder.mark
        builder.advanceLexer()
        builder.disableNewlines
        val (_, isTuple) = Types parse builder
        builder.getTokenType match {
          case ScalaTokenTypes.tCOMMA => {
            builder.advanceLexer() //Ate ,
            builder.getTokenType match {
              case ScalaTokenTypes.tRPARENTHESIS => {
                builder.advanceLexer() //Ate )
                if (isTuple) tupleMarker.done(ScalaElementTypes.TUPLE_TYPE)
                else {
                  builder.error("Identifier expected, but ',' found")
                  tupleMarker.done(ScalaElementTypes.TYPE_IN_PARENTHESIS)
                }
              }
              case _ => {
                builder error ScalaBundle.message("rparenthesis.expacted")
                if (isTuple) tupleMarker.done(ScalaElementTypes.TUPLE_TYPE)
                else tupleMarker.done(ScalaElementTypes.TYPE_IN_PARENTHESIS)
              }
            }
          }
          case ScalaTokenTypes.tRPARENTHESIS => {
            builder.advanceLexer() //Ate )
            if (isTuple) tupleMarker.done(ScalaElementTypes.TUPLE_TYPE)
            else tupleMarker.done(ScalaElementTypes.TYPE_IN_PARENTHESIS)
          }
          case _ => {
            builder error ScalaBundle.message("rparenthesis.expected")
            if (isTuple) tupleMarker.done(ScalaElementTypes.TUPLE_TYPE)
            else tupleMarker.done(ScalaElementTypes.TYPE_IN_PARENTHESIS)
          }
        }
        builder.restoreNewlinesState
      }
      case ScalaTokenTypes.kTHIS |
{'fraction_non_alphanumeric': 0.08839689722042664, 'fraction_numerical': 0.002585649644473174, 'mean_word_length': 1.8988290398126464, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '19045', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1752, 'n_words': 276}