<commit_before>package org.jetbrains.plugins.groovy.lang.parser.parsing.statements.expressions.primary;

import org.jetbrains.plugins.groovy.lang.parser.parsing.util.ParserUtils;
import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.blocks.OpenOrClosableBlock;
import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.expressions.StrictContextExpression;
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
import org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType;
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
import org.jetbrains.plugins.groovy.GroovyBundle;
import com.intellij.lang.PsiBuilder;

/**
 * @author Ilya.Sergey
 */
public class PrimaryExpression implements GroovyElementTypes {

  public static GroovyElementType parse(PsiBuilder builder){

    if (TokenSets.BUILT_IN_TYPE.contains(builder.getTokenType())) {
      ParserUtils.eatElement(builder, BUILT_IN_TYPE);
      return PRIMARY_EXPRESSION;
    }
    if (kTHIS.equals(builder.getTokenType())) {
      ParserUtils.eatElement(builder, REFERENCE_EXPRESSION);
      return PRIMARY_EXPRESSION;
    }
    if (kSUPER.equals(builder.getTokenType())) {
      ParserUtils.eatElement(builder, REFERENCE_EXPRESSION);
      return PRIMARY_EXPRESSION;
    }
    if (mIDENT.equals(builder.getTokenType())){
      ParserUtils.eatElement(builder, REFERENCE_EXPRESSION);
      return PRIMARY_EXPRESSION;
    }
    if (mGSTRING_SINGLE_BEGIN.equals(builder.getTokenType())){
      StringConstructorExpression.parse(builder);
      return PRIMARY_EXPRESSION;
    }
    if (mLBRACK.equals(builder.getTokenType())){
      ListOrMapConstructorExpression.parse(builder);
      return PRIMARY_EXPRESSION;
    }
    if (mLPAREN.equals(builder.getTokenType())){
      return parenthesizedExprParse(builder);
    }
    if (mLCURLY.equals(builder.getTokenType())){
      OpenOrClosableBlock.parseClosableBlock(builder);
      return PRIMARY_EXPRESSION;
    }
    if (TokenSets.CONSTANTS.contains(builder.getTokenType())){
      ParserUtils.eatElement(builder, LITERAL);
      return PRIMARY_EXPRESSION;
    }

    // TODO implement all cases!

    return WRONGWAY;
  }

  private static GroovyElementType parenthesizedExprParse(PsiBuilder builder){
    PsiBuilder.Marker marker = builder.mark();
    ParserUtils.getToken(builder, mLPAREN);
    StrictContextExpression.parse(builder);
    if(!ParserUtils.getToken(builder, mRPAREN, GroovyBundle.message("rparen.expected"))){
      builder.error(GroovyBundle.message("rparen.expected"));
      while (!builder.eof() && !mNLS.equals(builder.getTokenType()) && !mSEMI.equals(builder.getTokenType())
              && !mRPAREN.equals(builder.getTokenType())){
        builder.error(GroovyBundle.message("rparen.expected"));
        builder.advanceLexer();
      }
      ParserUtils.getToken(builder, mRPAREN);
    }
    marker.done(PARENTHSIZED_EXPRESSION);
    return PARENTHSIZED_EXPRESSION;
  }
<commit_msg>Added expression in braces parsing<commit_after>package org.jetbrains.plugins.groovy.lang.parser.parsing.statements.expressions.primary;

import org.jetbrains.plugins.groovy.lang.parser.parsing.util.ParserUtils;
import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.blocks.OpenOrClosableBlock;
import org.jetbrains.plugins.groovy.lang.parser.parsing.statements.expressions.StrictContextExpression;
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
import org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType;
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
import org.jetbrains.plugins.groovy.GroovyBundle;
import com.intellij.lang.PsiBuilder;

/**
 * @author Ilya.Sergey
 */
public class PrimaryExpression implements GroovyElementTypes {

  public static GroovyElementType parse(PsiBuilder builder){

    if (TokenSets.BUILT_IN_TYPE.contains(builder.getTokenType())) {
      ParserUtils.eatElement(builder, BUILT_IN_TYPE);
      return PRIMARY_EXPRESSION;
    }
    if (kTHIS.equals(builder.getTokenType())) {
      ParserUtils.eatElement(builder, REFERENCE_EXPRESSION);
      return PRIMARY_EXPRESSION;
    }
    if (kSUPER.equals(builder.getTokenType())) {
      ParserUtils.eatElement(builder, REFERENCE_EXPRESSION);
      return PRIMARY_EXPRESSION;
    }
    if (mIDENT.equals(builder.getTokenType())){
      ParserUtils.eatElement(builder, REFERENCE_EXPRESSION);
      return PRIMARY_EXPRESSION;
    }
    if (mGSTRING_SINGLE_BEGIN.equals(builder.getTokenType())){
      StringConstructorExpression.parse(builder);
      return PRIMARY_EXPRESSION;
    }
    if (mLBRACK.equals(builder.getTokenType())){
      ListOrMapConstructorExpression.parse(builder);
      return PRIMARY_EXPRESSION;
    }
    if (mLPAREN.equals(builder.getTokenType())){
      return parenthesizedExprParse(builder);
    }
    if (mLCURLY.equals(builder.getTokenType())){
      OpenOrClosableBlock.parseClosableBlock(builder);
      return PRIMARY_EXPRESSION;
    }
    if (TokenSets.CONSTANTS.contains(builder.getTokenType())){
      ParserUtils.eatElement(builder, LITERAL);
      return PRIMARY_EXPRESSION;
    }

    // TODO implement all cases!

    return WRONGWAY;
  }

  public static GroovyElementType parenthesizedExprParse(PsiBuilder builder){
    PsiBuilder.Marker marker = builder.mark();
    ParserUtils.getToken(builder, mLPAREN);
    StrictContextExpression.parse(builder);
    if(!ParserUtils.getToken(builder, mRPAREN, GroovyBundle.message("rparen.expected"))){
      builder.error(GroovyBundle.message("rparen.expected"));
      while (!builder.eof() && !mNLS.equals(builder.getTokenType()) && !mSEMI.equals(builder.getTokenType())
              && !mRPAREN.equals(builder.getTokenType())){
        builder.error(GroovyBundle.message("rparen.expected"));
        builder.advanceLexer();
      }
      ParserUtils.getToken(builder, mRPAREN);
    }
    marker.done(PARENTHSIZED_EXPRESSION);
    return PARENTHSIZED_EXPRESSION;
  }

{'fraction_non_alphanumeric': 0.11238609517381033, 'fraction_numerical': 0.0, 'mean_word_length': 4.523765144454799, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1095970', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1845, 'n_words': 228}