public override void Handle(IStateMachine <string, Tokenizer> machine) { if (machine.SharedContext.Current != LexiconSymbol.Destroy) { return; } while (Identifier == null) { if (!machine.SharedContext.MoveNext()) { break; } if (!ValidLexemes.Contains(machine.SharedContext.Current)) { continue; } //if (machine.SharedContext.Current == LexiconSymbol.DestroyerLetter) //{ // Console.WriteLine($"adding {nameof(DestroyerExpression)}"); // Identifier = new DestroyerExpression(); // Identifier.Handle(machine); //} if (machine.SharedContext.Current == LexiconSymbol.TagIdentifier) { Console.WriteLine($"adding {nameof(TagExpression)}"); Identifier = new TagExpression(); Identifier.Handle(machine); } } if (Identifier == null) { throw new InvalidOperationException($"Syntax error: ${nameof(Identifier)} side is not implemented near {machine.SharedContext.CurrentBuffer}"); } }
public override void Handle(IStateMachine <string, Tokenizer> machine) { if (machine.SharedContext.Current != LexiconSymbol.If) { throw new InvalidOperationException("Trying to handle If, where If is not a token"); } while (Left == null || Right == null || Comparison == null) { if (!machine.SharedContext.MoveNext()) { break; } if (!ValidLexemes.Contains(machine.SharedContext.Current)) { continue; } if (machine.SharedContext.Current == LexiconSymbol.Letter && Left == null) { Left = new IdentifierExpression(); Left.Handle(machine); } if (machine.SharedContext.Current == LexiconSymbol.Equal && Left != null) { Comparison = new ComparisonExpression(); Comparison.Handle(machine); } //right depends on the type of the left identifier if (machine.SharedContext.Current != LexiconSymbol.SkipMaterial && machine.SharedContext.Current != LexiconSymbol.Equal && Left != null && Comparison != null) { Right = new TagExpression(); Right.Handle(machine); } } if (Left == null) { throw new ArgumentNullException($"{nameof(Left)} not found. Maybe a syntax error?"); } if (Right == null) { throw new ArgumentNullException($"{nameof(Right)} not found. Maybe a syntax error?"); } if (Comparison == null) { throw new ArgumentNullException($"{nameof(Comparison)} not found. Maybe a syntax error?"); } }
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"); } }