private string GenerateConsumeString(ParseAction action) { ConsumeString consume = (ConsumeString)action; return(this.WrapAssignment(action, (consume.IsOptional ? "Maybe" : "") + "Consume(\"" + consume.String + "\")" ) + ";"); }
public void testMinimalModelWithProperty() { // e.g. rule ::= StringProperty @ "a" Property property = new Property() { Name = "StringProperty" }; ParseAction consume = new ConsumeString() { Property = property, String = "a" }; property.Source = consume; Model model = new Model() { Entities = new List <Entity> { new Entity() { Name = "rule", Properties = (new List <Property> { property }).AsReadOnly(), ParseAction = consume } } }; Assert.AreEqual( @"new Model() { Entities = new List<Entity>() { new Entity() { Rule = null, Name = ""rule"", Properties = new List<Property>() { new Property() { Name = ""StringProperty"", Source = new ConsumeString() { String = ""a"" } } }.AsReadOnly(), ParseAction = new ConsumeString() { String = ""a"" }, Supers = new HashSet<string>(), Subs = new HashSet<string>() } }, RootName = ""rule"" }", model.ToString() ); }
void LookupString(Frame frame, string name, ConsumeString consume) { var lookup = new Lookup(task_master, source_ref, new [] { name }, Context.Prepend(frame, null)); lookup.Notify(result => { if (result is Stringish) { var str = result.ToString(); consume(str); } else { task_master.ReportOtherError(source_ref, String.Format("Expected “{0}” to be a string. Got {1} instead.", name, Stringish.NameForType(result.GetType()))); } }); }
void LookupString(Frame frame, string name, ConsumeString consume) { var lookup = new Lookup(task_master, source_ref, new []{name}, Context.Prepend(frame, null)); lookup.Notify(result => { if (result is Stringish) { var str = result.ToString(); consume(str); } else { task_master.ReportOtherError(source_ref, String.Format("Expected “{0}” to be a string. Got {1} instead.", name, Stringish.NameForType(result.GetType()))); } }); }