/// <summary> /// Learn tokens which evalutes to the `expected` string. /// </summary> /// <param name="input">Input.</param> /// <param name="expected">Output: the expected string.</param> /// <returns>Consistent programs.</returns> private ProgramSet LearnToken(TInput input, string expected) { var programs = new List <ProgramNode>(); // Option 1: err token. if (expected == input.errNode.code) { programs.Add(ErrToken()); } // Option 2: variable token. input.TryFind(expected).Select(key => { programs.Add(VarToken(key)); }); // Option 3: constant token. programs.Add(ConstToken(expected)); return(ProgramSet.List(Symbol("token"), programs)); }
public static string ErrToken(TInput input) => input.errNode.code;
public static string VarToken(TInput input, EnvKey key) => input[key];
public static SyntaxNode Var(TInput input, EnvKey key) => input.inputTree.Leaves().Where(l => l.code == input[key]).ArgMin(l => l.depth);
public static SyntaxNode Err(TInput input) => input.errNode;