<commit_before>/*
 * Copyright 2013-2014 must-be.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.mustbe.consulo.msil.lang.parser;

import org.jetbrains.annotations.NotNull;
import org.mustbe.consulo.msil.lang.psi.MsilElements;
import org.mustbe.consulo.msil.lang.psi.MsilTokenSets;
import org.mustbe.consulo.msil.lang.psi.MsilTokens;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LanguageVersion;
import com.intellij.lang.PsiBuilder;
import com.intellij.lang.PsiBuilderUtil;
import com.intellij.lang.PsiParser;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;

/**
 * @author VISTALL
 * @since 21.05.14
 */
public class MsilParser implements PsiParser, MsilTokens, MsilTokenSets, MsilElements
{
	@NotNull
	@Override
	public ASTNode parse(@NotNull IElementType elementType, @NotNull PsiBuilder builder, @NotNull LanguageVersion languageVersion)
	{
		PsiBuilder.Marker mark = builder.mark();
		while(!builder.eof())
		{
			parse(builder);
		}
		mark.done(elementType);
		return builder.getTreeBuilt();
	}

	private void parse(PsiBuilder builder)
	{
		IElementType tokenType = builder.getTokenType();
		if(tokenType == _CLASS_KEYWORD)
		{
			parseClass(builder);
		}
		else if(tokenType == _CUSTOM_KEYWORD)
		{
			parseAttribute(builder);
		}
		else if(tokenType == _FIELD_KEYWORD)
		{
			parseField(builder);
		}
		else if(tokenType == _EVENT_KEYWORD)
		{
			parseEvent(builder);
		}
		else
		{
			builder.error("Unexpected token " + tokenType);
			builder.advanceLexer();
		}
	}

	private void parseField(PsiBuilder builder)
	{<commit_msg>property parsing<commit_after>/*
 * Copyright 2013-2014 must-be.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.mustbe.consulo.msil.lang.parser;

import org.jetbrains.annotations.NotNull;
import org.mustbe.consulo.msil.lang.psi.MsilElements;
import org.mustbe.consulo.msil.lang.psi.MsilTokenSets;
import org.mustbe.consulo.msil.lang.psi.MsilTokens;
import com.intellij.lang.ASTNode;
import com.intellij.lang.LanguageVersion;
import com.intellij.lang.PsiBuilder;
import com.intellij.lang.PsiBuilderUtil;
import com.intellij.lang.PsiParser;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;

/**
 * @author VISTALL
 * @since 21.05.14
 */
public class MsilParser implements PsiParser, MsilTokens, MsilTokenSets, MsilElements
{
	@NotNull
	@Override
	public ASTNode parse(@NotNull IElementType elementType, @NotNull PsiBuilder builder, @NotNull LanguageVersion languageVersion)
	{
		PsiBuilder.Marker mark = builder.mark();
		while(!builder.eof())
		{
			parse(builder);
		}
		mark.done(elementType);
		return builder.getTreeBuilt();
	}

	private void parse(PsiBuilder builder)
	{
		IElementType tokenType = builder.getTokenType();
		if(tokenType == _CLASS_KEYWORD)
		{
			parseClass(builder);
		}
		else if(tokenType == _CUSTOM_KEYWORD)
		{
			parseAttribute(builder);
		}
		else if(tokenType == _FIELD_KEYWORD)
		{
			parseField(builder);
		}
		else if(tokenType == _EVENT_KEYWORD)
		{
			parseEvent(builder);
		}
		else if(tokenType == _PROPERTY_KEYWORD)
		{
			parseProperty(builder);
		}
		else
		{
			builder.error("Unexpected token " + tokenType);
			builder.advanceLexer();
		}
	}

	private void parseProperty(PsiBuilder builder)
	{
		PsiBuilder.Marker mark = builder.mark();

		builder.advanceLexer();

		parseModifierList(builder);

		parseType(builder);

		expect(builder, IDENTIFIER, "Identifier expected");

		if(expect(builder, LBRACE, "'{' expected"))
		{
			while(!builder.eof())
			{
				if(builder.getTokenType() == RBRACE)
				{
					break;
				}
				else
				{
					parse(builder);
				}
			}
			expect(builder, RBRACE, "'}' expected");
		}

		mark.done(PROPERTY);
	}

	private void parseField(PsiBuilder builder)
	{
{'fraction_non_alphanumeric': 0.10956050822745261, 'fraction_numerical': 0.007498437825453031, 'mean_word_length': 4.248087431693989, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5629751', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1535, 'n_words': 372}