protected IResult <string> checkTraits() { traits = new Hash <string, Trait>(); foreach (var traitName in traitNames) { var _trait = CompilerState.Trait(traitName); if (_trait.If(out var trait)) { traits[traitName] = trait; } else { return($"{traitName} is not a trait".Failure <string>()); } } foreach (var(traitName, trait) in traits) { foreach (var(_, possibleSignature) in trait.Members) { if (possibleSignature is Signature signature && !signatures.ContainsKey(signature.Name)) { return($"Trait {traitName}.{signature.UnmangledSignature} not defined in class {className}".Failure <string>()); } } } return(className.Success()); }
IResult <string> checkTraits() { traits = new Hash <string, Trait>(); foreach (var traitName in traitNames) { var trait = CompilerState.Trait(traitName); if (trait.IsNone) { return($"{traitName} is not a trait".Failure <string>()); } traits[traitName] = trait.Value; } // ReSharper disable once LoopCanBePartlyConvertedToQuery foreach (var item in traits) { var traitName = item.Key; var trait = item.Value; // ReSharper disable once LoopCanBeConvertedToQuery foreach (var member in trait.Members) { if (member.Value is Signature signature && !signatures.ContainsKey(signature.Name)) { return($"Trait {traitName}.{signature.UnmangledSignature} not defined in class {className}".Failure <string>()); } } } return(className.Success()); }
static Value evaluateVariable(string name) { if (name == "_") { return(new Any()); } var possibleClass = CompilerState.Class(name); if (possibleClass.IsSome) { return(possibleClass.Value); } var possibleTrait = CompilerState.Trait(name); if (possibleTrait.IsSome) { return(possibleTrait.Value); } if (IsClassName(name)) { return(new Variable(name)); } return(new Placeholder(name)); }
public override Verb CreateVerb(string[] tokens) { Color(position, tokens[1].Length, KeyWords); var name = tokens[2]; Color(name.Length, Types); var index = NextPosition; if (doesParser.Scan(source, index)) { traits = doesParser.Traits; index = doesParser.Position; } if (endOfLineParser.Scan(source, index)) { index = endOfLineParser.Position; } var members = new Hash <string, Value>(); InClassDefinition = true; foreach (var traitName in traits) { var trait = CompilerState.Trait(traitName).Must().HaveValue().Force(LOCATION, () => $"Trait {traitName} isn't defined"); foreach (var(key, value) in trait.Members) { members[key] = value; } } try { AdvanceTabs(); while (index < source.Length) { if (bodyParser.Scan(source, index) && bodyParser.Parser.If(out var parser)) { index = parser.Position; if (parser is ITraitName aTraitName) { var traitName = aTraitName; var memberName = traitName.MemberName; var value = parser.Result.Value; if (value != null) { members[memberName] = value; } else { value = traitName.Getter; if (value != null) { members[GetterName(memberName)] = value; } value = traitName.Setter; if (value != null) { members[SetterName(memberName)] = value; } members[MangledName(memberName)] = new Null(); } } else { return(null); } } else { break; } } } finally { InClassDefinition = false; RegressTabs(); } var newTrait = new Trait(name, members); overridePosition = index; CompilerState.RegisterTrait(newTrait); return(new CreateTrait(newTrait, traits) { Index = position }); }