public override void Handle(IStateMachine <string, Tokenizer> machine) { // Gate if (machine.SharedContext.Current != LexiconSymbol.Wait) { return; } while (Number == null || SignConverter == null || Unit == null) { if (!machine.SharedContext.MoveNext()) { break; } if (!ValidLexemes.Contains(machine.SharedContext.Current)) { continue; } // Console.WriteLine(machine.SharedContext.CurrentBuffer); if ( machine.SharedContext.Current == LexiconSymbol.Milliseconds || machine.SharedContext.Current == LexiconSymbol.Seconds || machine.SharedContext.Current == LexiconSymbol.Minutes || machine.SharedContext.Current == LexiconSymbol.Hours) { //Console.WriteLine($"adding {nameof(TimeUnitExpression)}"); Unit = new TimeUnitExpression(); Unit.Handle(machine); } if (machine.SharedContext.Current == LexiconSymbol.PositiveSign || machine.SharedContext.Current == LexiconSymbol.NegativeSign) { //Console.WriteLine($"adding {nameof(SignConverterExpression)}"); SignConverter = new SignConverterExpression(); SignConverter.Handle(machine); } if (machine.SharedContext.Current == LexiconSymbol.Number) { //Console.WriteLine($"adding {nameof(NumberExpression)}"); Number = new NumberExpression(); Number.Handle(machine); } } if (Number == null) { throw new InvalidOperationException($"Syntax error: ${nameof(Number)} side is not implemented near {machine.SharedContext.CurrentBuffer}"); } if (SignConverter == null) { throw new InvalidOperationException($"Syntax error: ${nameof(SignConverter)} side is not implemented near {machine.SharedContext.CurrentBuffer}"); } if (Unit == null) { throw new InvalidOperationException($"Syntax error: ${nameof(Unit)} side is not implemented near {machine.SharedContext.CurrentBuffer}"); } }
public override void Handle(IStateMachine <string, Tokenizer> machine) { // Gate if (machine.SharedContext.Current != LexiconSymbol.Modify) { return; } while (Identifier == null || Section == null || Attribute == null || SignConverter == null || Number == null) { if (!machine.SharedContext.MoveNext()) { break; } if (!ValidLexemes.Contains(machine.SharedContext.Current)) { continue; } // Console.WriteLine(machine.SharedContext.CurrentBuffer); if (machine.SharedContext.Current == LexiconSymbol.EntityIdentifier && Identifier == null && Section != null && Attribute != null) { Console.WriteLine($"adding {nameof(EntityExpression)}"); Identifier = new EntityExpression(); Identifier.Handle(machine); } if (machine.SharedContext.Current == LexiconSymbol.TagIdentifier && Identifier == null && Section != null && Attribute != null) { Console.WriteLine($"adding {nameof(TagExpression)}"); Identifier = new TagExpression(); Identifier.Handle(machine); } if (machine.SharedContext.Current == LexiconSymbol.Attribute) { Console.WriteLine($"adding {nameof(AttributeExpression)}"); Attribute = new AttributeExpression(); Attribute.Handle(machine); } if (machine.SharedContext.Current == LexiconSymbol.Position || machine.SharedContext.Current == LexiconSymbol.Scale || machine.SharedContext.Current == LexiconSymbol.Color || machine.SharedContext.Current == LexiconSymbol.Alpha || machine.SharedContext.Current == LexiconSymbol.Stats) { Console.WriteLine($"adding section {nameof(AttributeExpression)}"); Section = new AttributeExpression(); Section.Handle(machine); } //this part sets the order of the if (machine.SharedContext.Current == LexiconSymbol.Letter && Identifier == null && Section != null && Attribute != null) { Console.WriteLine($"adding {nameof(IdentifierExpression)}"); Identifier = new IdentifierExpression(); Identifier.Handle(machine); } if (machine.SharedContext.Current == LexiconSymbol.PositiveSign || machine.SharedContext.Current == LexiconSymbol.NegativeSign) { Console.WriteLine($"adding {nameof(SignConverterExpression)}"); SignConverter = new SignConverterExpression(); SignConverter.Handle(machine); } if (machine.SharedContext.Current == LexiconSymbol.Number) { Console.WriteLine($"adding {nameof(NumberExpression)}"); Number = new NumberExpression(); Number.Handle(machine); } } if (Identifier == null) { throw new ArgumentNullException($"{nameof(Identifier)} not found. Maybe a syntax error? Ex. Mod Stats Health +123 myVar or Mod Stats Health +123 .myTag"); } if (Section == null) { throw new ArgumentNullException($"{nameof(Section)} not found. Maybe a syntax error? Ex. Mod Stats Health +123 myVar or Mod Stats Health +123 .myTag"); } if (Number == null) { throw new ArgumentNullException($"{nameof(Number)} not found. Maybe a syntax error? Ex. Mod Stats Health +123 myVar or Mod Stats Health +123 .myTag"); } }