public override void Warmup(JsonTestSuite suite) { var g = new global::Irony.Samples.Json.IronyJsonGrammar(); parser = new global::Irony.Parsing.Parser(g); parser.Parse(suite.Json); }
public override void GenerateCode(Span target, CodeGeneratorContext context) { // will be parsing this code var code = target.Content.Trim(); // parse the attribute declaration code var p = new global::Irony.Parsing.Parser(new CSharpAttributeDeclarationGrammar()).Parse(code); p.ThrowParseErrors(); // extract attribute name var attributeName = p .Node("attribute") .Node("qual_name_with_targs") .SpanText(code); // extract attribute args var attributeArgs = p .Node("attribute") .Node("attribute_arguments_par_opt") .Node("attribute_arguments") .Nodes("attr_arg") .Select(i => i.SpanText(code)) .ToList(); // custom attribute declaration, using a code snippet expression context.GeneratedClass.CustomAttributes.Add(new CodeAttributeDeclaration( attributeName, attributeArgs .Select(i => new CodeAttributeArgument(new CodeSnippetExpression(i))) .ToArray())); }
ParseTree Parse(string code) { var p = new global::Irony.Parsing.Parser(new CSharpAttributeDeclarationGrammar()); var v = p.Parse(code); return(v); }
/// <summary> /// Attempts to resolve the type specified by <paramref name="typeName"/>. /// </summary> /// <param name="typeName"></param> /// <returns></returns> public static Type ResolveType(string typeName, IEnumerable <Assembly> assemblies, IEnumerable <string> namespaces) { // will be parsing this code var code = typeName.Trim(); // parse the attribute declaration code var p = new global::Irony.Parsing.Parser(new CSharpTypeNameGrammar()).Parse(code); p.ThrowParseErrors(); // find type specifier var t = p .Node("type_specifier"); if (t == null) { return(null); } return(ResolveTypeSpecifier(t, assemblies, namespaces)); }
public IronyBenchmark() { var g = new global::Irony.Samples.Json.IronyJsonGrammar(); parser = new global::Irony.Parsing.Parser(g); }