public AstReader GetReader() { var reader = new AstReader(); reader.AddGroup(new GroupSymbol("(", ")")); reader.AddGroup(new GroupSymbol("[", "]")); reader.AddGroup(new GroupSymbol("{", "}")); reader.AddGroup(new GroupSymbol("<", ">")); reader.StrictGroups = true; return(reader); }
private IData ReadInput() { var reader = new AstReader(); reader.Escape = "!"; reader.EscapeBehavior = AstReader.EscapeHandling.Skip; reader.SequenceSplit = ","; var group = new GroupSymbol("{", "}"); var garbage = new GroupSymbol("<", ">", false); reader.AddGroup(group).AddGroup(garbage); var parser = new AstParser <IData>(); parser.Add(new TupleParser <IData>(group, (IList <IData> args, out IData result) => { result = new Group { Data = args.ToList() }; return(true); })); parser.Add(new TupleParser <IData>(garbage, (IList <IData> args, out IData result) => { result = new Garbage { Content = args.Count > 0 ? args[0] as GarbageData : null }; return(true); })); parser.Add(new SequenceParser <IData>((AstParser <IData> _, IList <AstNode> nodes, out IData result) => { result = new GarbageData(nodes.Str()); return(true); })); var nodes = reader.Read(InputLine, new TokenSettings { SingleLetters = true }); return(parser.Parse(nodes)); }