<commit_before>﻿using System.Collections.Generic;
using System.Linq;

namespace Crayon.ParseTree
{
	internal class DotStep : Expression
	{
		public override bool CanAssignTo { get { return true; } }

		public Expression Root { get; set; }
		public Token DotToken { get; private set; }
		public Token StepToken { get; private set; }

		public DotStep(Expression root, Token dotToken, Token stepToken, Executable owner)
			: base(root.FirstToken, owner)
		{
			this.Root = root;
			this.DotToken = dotToken;
			this.StepToken = stepToken;
		}

		internal override Expression Resolve(Parser parser)
		{
			this.Root = this.Root.Resolve(parser);

			string step = this.StepToken.Value;

			if (this.Root is EnumReference)
			{
				EnumDefinition enumDef = ((EnumReference)this.Root).EnumDefinition;
				if (step == "length")
				{
					return new IntegerConstant(this.FirstToken, enumDef.IntValue.Count, this.FunctionOrClassOwner);
				}
				else if (enumDef.IntValue.ContainsKey(step))
				{
					return new IntegerConstant(this.FirstToken, enumDef.IntValue.Count, this.FunctionOrClassOwner);
				}
				else
				{
					throw new ParserException(this.StepToken, "The enum '" + enumDef.Name + "' does not contain a definition for '" + step + "'");
				}
			}

			Variable variable = this.Root as Variable;
			if (variable != null)
			{
				string varName = variable.Name;

				if (parser.IsTranslateMode && varName.Contains('$'))
				{
					string[] parts = varName.Split('$');
					if (parts.Length == 2 && parts[0].Length > 0 && parts[1].Length > 0)
					{
						// struct casting
						string structName = parts[0];
						string realVarName = parts[1];
						StructDefinition structDef = parser.GetStructDefinition(structName);
						if (structDef == null)
						{
							throw new ParserException(this.Root.FirstToken, "The struct '" + structName + "' does not exist.");
						}
						if (!structDef.IndexByField.ContainsKey(step))<commit_msg>Copy paste error. Enum values were being resolved as enum.length.<commit_after>﻿using System.Collections.Generic;
using System.Linq;

namespace Crayon.ParseTree
{
	internal class DotStep : Expression
	{
		public override bool CanAssignTo { get { return true; } }

		public Expression Root { get; set; }
		public Token DotToken { get; private set; }
		public Token StepToken { get; private set; }

		public DotStep(Expression root, Token dotToken, Token stepToken, Executable owner)
			: base(root.FirstToken, owner)
		{
			this.Root = root;
			this.DotToken = dotToken;
			this.StepToken = stepToken;
		}

		internal override Expression Resolve(Parser parser)
		{
			this.Root = this.Root.Resolve(parser);

			string step = this.StepToken.Value;

			if (this.Root is EnumReference)
			{
				EnumDefinition enumDef = ((EnumReference)this.Root).EnumDefinition;
				if (step == "length")
				{
					return new IntegerConstant(this.FirstToken, enumDef.IntValue.Count, this.FunctionOrClassOwner);
				}
				else if (enumDef.IntValue.ContainsKey(step))
				{
					return new IntegerConstant(this.FirstToken, enumDef.IntValue[step], this.FunctionOrClassOwner);
				}
				else
				{
					throw new ParserException(this.StepToken, "The enum '" + enumDef.Name + "' does not contain a definition for '" + step + "'");
				}
			}

			Variable variable = this.Root as Variable;
			if (variable != null)
			{
				string varName = variable.Name;

				if (parser.IsTranslateMode && varName.Contains('$'))
				{
					string[] parts = varName.Split('$');
					if (parts.Length == 2 && parts[0].Length > 0 && parts[1].Length > 0)
					{
						// struct casting
						string structName = parts[0];
						string realVarName = parts[1];
						StructDefinition structDef = parser.GetStructDefinition(structName);
						if (structDef == null)
						{
							throw new ParserException(this.Root.FirstToken, "The struct '" + structName + "' does not exist.");
						}
						if (!structDef.IndexByField.ContainsKey(step))
{'fraction_non_alphanumeric': 0.11686991869918699, 'fraction_numerical': 0.003556910569105691, 'mean_word_length': 3.270065075921909, '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': '7562056', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1158, 'n_words': 302}