Flit's Object Model

Flit's primary purpose is to parse a source file into an object model that's easy to consume from any T4 template. Here is a class diagram of Flit's object model:


The Graph

The graph is the root of our object model. A T4 Template can get a reference to a Flit Graph by running Irony against a source file:
Irony.Parsing.Parser parser = new Irony.Parsing.Parser(new Flit.FlitGrammar());
Irony.Parser.ParseTree tree = parser.Parse(System.IO.File.ReadAllText("filename.txt"));
Irony.Parser.ParseTreeNode node = tree.Root;
Flit.Graph graph = node.AstNode as Flit.Graph;


A state represents a class in your fluent interface. Each time you call a method on one of your states, a new state is returned. Flit's T4 template iterates over each state in the graph and generates a partial class.


A transition joins states together. A transition will usually be represented as a method on its FromState, that returns a new object of the ToState's class. Rather than iterating over a graph's transitions, Flit's T4 template has a nested loop that iterates of each state's outgoing transitions (All the transitions that leave that state).

Common Graph Item Components

Both States and Transitions share a few properties:

Generic Attributes

Dot allows for a large number of attributes to be specified against a "node" or an "edge", while Flit only recognises the "label" attribute. Thus, all attributes other than "label" are stored in this Dictionary<string, string>. You can use this dictionary to find out what a state's color or shape is, for example. This means you can create your own conventions and have the template behave differently for some types of states.


The label attribute of Dot is visible on Dot's diagrams. Flit uses labels to provide the name and parameters of each state and transition. A valid label could be Foo(string name) (a state or transition named Foo that requires a string called name) or Foo (no parameters).


Labels can have parameters. Parameters represent bits of data that your classes or methods require to be passed into them.

If that seems a bit complex, then the best thing to do is to go check out the samples, and see the code that gets generated for the sample source files.

Continue reading: Code generation.

Last edited Oct 18, 2009 at 8:46 PM by robfe, version 5


No comments yet.