Validating Input

Jun 17, 2009 at 11:23 AM

I am using Flee to evaluate expression to call into custom functions.

For example:

var expression = context.CompileGeneric<Double>("MyMethod(\"ABC\")"); 


public static Double MyMethod(String identifier)
// retrieves value based on identifier 

I need a way to evaluate the expression to retrieve the identifiers without having to wait until the expression.Evaluate() method is called. This is because the expression are built in a UI separate from the context of where MyMethod can retrieve the actual values (they are in a db which I don't want the UI to have access to)

Is there anyway to retrieve the inputs for validation post expression compilation but before evaluation. They are not variables, these are actual inputs. 





Jun 18, 2009 at 3:28 PM

Just to make sure I'm clear on your question:

If you have an expression such as "MyMethod("a", 33)"

You'd like to have a way to pick out the literals from the expression (ie: "a" and 33).  Correct?

Jun 19, 2009 at 10:27 AM

Spot on.

I know I could do it by parsing it myself but seeing Flee is already doing the parsing then it makes sense to expose the parsed expression tree (or something along those lines).






Jun 24, 2009 at 12:30 AM

Yeah, giving access to a parse tree seems like the only way.  Once you have the root node, I'm guessing you just want to traverse the tree, know if a node is a literal, and to get its value.

I'll try to put something in by the next release (couple of weeks to a month).

Jun 26, 2009 at 8:54 AM


Let me know when this happens.



Sep 9, 2009 at 4:22 PM

Was wondering if you had any update?





Dec 1, 2009 at 12:11 AM
Edited Jan 25, 2010 at 11:32 PM

I had the same requirement last week and changed the Flee library to cater for this. Two issues had to be addressed:

a) The expression tree that FLEE builds up during parsing is not accessible publicly

b) The FLEE library is too strict about types for this usage pattern. In my case I don’t know the type of the expression "MyMethod(\"ABC\")" until later.

To overcome these hurdles I modified the Flee library so that it exposes the AST (Abstract Syntax Tree) that it creates during parsing. In addition all expression elements are now public and support the visitor pattern in conjunction with an abstract ExpressionWalker class (the visitor). The ExpressionWalker is analogous to the TreeWalker that IronPython offers. Finally a flag controls whether type checks should be performed during parsing.

Here is a sample code snippet that demonstrates the usage. The AstPrinter class derives from the new ExpressionWalker class and writes out information about the various expression elements.

      ExpressionContext expressionContext = new ExpressionContext();



      expressionContext.ParserOptions.SkipTypeCheck = true;

      IDynamicExpression expression = expressionContext.CompileDynamic("Value(\"..Blah\") + Value(\"..Blah1\", 15)");

      RootExpressionElement rootElement = ((Expression<object>)expression).RootElement;

      AstPrinter astPrinter = new AstPrinter();


You can download the code from here: The solution contains an additional C# project called FleeLibraryPlayground that demonstrates the usage of the ExpressionWalker class.

 Thank you, Eciloci, for sharing your great library! Without your source code I would have been stuck.