I am new to IronRuby. I am trying to integrate it with C#.
I have created following example and it is working fine.
string rubyCode = @"
def function_111(test)
print 1
end
";
ScriptEngine engine = Ruby.CreateEngine();
ScriptScope scope = engine.CreateScope();
engine.Execute(rubyCode, scope);
dynamic sayHelloFun = scope.GetVariable("function_111");
sayHelloFun("test");
If you look at above code then I am using execute method that compile and execute code but instead of that I only want to parse code it means its syntax are correct or not.
How can that possible ?
The link posted appears dead, and the search engine cache copies appear to be rotting, so I'm going to scrape what is left of the post and interpret it below.
You can use IronRuby along with the Dynamic Language Runtime (DLR) to parse the Ruby code. The steps are to: create a Ruby engine instance, create a script source and unit, create a parser and parse to an AST, and walk the AST with a Walker.
Create the Engine
Create the Source Unit
Parse
Walk the AST
You'll need to subclass the Walker class, which has numerous virtual methods to handle visiting various nodes in the AST. The one used in the LinqPad Query looks like so:
When you run this walker on the AST generated above, you get the following:
I used LinqPad and added the IronRuby 1.1.3 nuget package and created a LinqPad Query with the above.