<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JDT&#039;s Blog &#187; Calidus</title>
	<atom:link href="http://jdt.toron.be/blog/tag/calidus/feed/" rel="self" type="application/rss+xml" />
	<link>http://jdt.toron.be/blog</link>
	<description>JDT on computers, programming and pie</description>
	<lastBuildDate>Tue, 03 Nov 2009 17:52:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating custom Statements</title>
		<link>http://jdt.toron.be/blog/2009/11/creating-custom-statements/</link>
		<comments>http://jdt.toron.be/blog/2009/11/creating-custom-statements/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 17:45:19 +0000</pubDate>
		<dc:creator>JDT</dc:creator>
				<category><![CDATA[Various]]></category>
		<category><![CDATA[Calidus]]></category>
		<category><![CDATA[Statements]]></category>

		<guid isPermaLink="false">http://jdt.toron.be/blog/?p=58</guid>
		<description><![CDATA[Abstract
In which the author outlines the method used in Calidus to parse a set of tokens into a new type of statement.
Concrete
Creating a new statement in Calidus is simple. A lot of utilities, methods and classes are available to make creating a statement a breeze.
Creating the basic classes
The first thing to do is to make [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Abstract</strong></p>
<p>In which the author outlines the method used in Calidus to parse a set of tokens into a new type of statement.</p>
<p><strong>Concrete</strong><br />
Creating a new statement in Calidus is simple. A lot of utilities, methods and classes are available to make creating a statement a breeze.</p>
<h2><strong>Creating the basic classes</strong></h2>
<p>The first thing to do is to make sure that all parts are in place. The statement class itself must be declared. This class is derived from the <em>AccessModifierStatement</em> because an indexer can have an access modifier, and the base <em>AccessModifierStatement</em> class provides a few methods to work with these access modifiers.</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="co1">/// &lt;summary&gt;</span><br />
<span class="co1">/// This class represents an indexer statement</span><br />
<span class="co1">/// &lt;/summary&gt;</span><br />
<span class="kw1">public</span> <span class="kw4">class</span> IndexerStatement <span class="sy0">:</span> AccessModifierStatement<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="co1">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; <span class="co1">/// Create a new instance of this class</span><br />
&nbsp; &nbsp; <span class="co1">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; <span class="co1">/// &lt;param name=&quot;tokens&quot;&gt;The list of tokens in the statement&lt;/param&gt;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> IndexerStatement<span class="br0">&#40;</span>IEnumerable<span class="sy0">&lt;</span>TokenBase<span class="sy0">&gt;</span> tokens<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">:</span> <span class="kw1">base</span><span class="br0">&#40;</span>tokens<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>The basic code for the statement factory class is also needed. In order to make this parsing as easy as possible the factory is derived from the <em>FluentStatementFactory</em> class to gain access to statement expressions. These statement expressions provide a fluent interface to declare the requirements for a statement.</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="co1">/// &lt;summary&gt;</span><br />
<span class="co1">/// This class creates indexer statements</span><br />
<span class="co1">/// &lt;/summary&gt;</span><br />
<span class="kw1">public</span> <span class="kw4">class</span> IndexerStatementFactory <span class="sy0">:</span> FluentStatementFactory<span class="sy0">&lt;</span>IndexerStatement<span class="sy0">&gt;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">protected</span> <span class="kw1">override</span> IndexerStatement BuildStatement<span class="br0">&#40;</span>IEnumerable<span class="sy0">&lt;</span>TokenBase<span class="sy0">&gt;</span> input<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> IndexerStatement<span class="br0">&#40;</span>input<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">protected</span> <span class="kw1">override</span> <span class="kw4">bool</span> IsValidContext<span class="br0">&#40;</span>IStatementContext context<span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> false<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">protected</span> <span class="kw1">override</span> IStatementExpression Expression<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; get <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StatementExpression expression <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> StatementExpression<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> expression<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Since Calidus is test-driven, a set of tests are needed to indicate that the statement is parsed correctly. For a factory, define a base test class that derives from <em>CalidusTestBase. </em>This class provides a set of utility methods and classes such as a TokenCreator and a StatementCreator that can be used by Calidus tests.</p>
<p>The TDD aficionado&#8217;s will notice that this is technically not a valid test: an additional unit test should be created to validate the context checking separately. However, this test already checks that the context is called through the mock repository in the VerifyAll-method. An extra test provides no additional advantage here.</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="br0">&#91;</span>TestFixture<span class="br0">&#93;</span><br />
<span class="kw1">public</span> <span class="kw4">class</span> IndexerStatementFactoryTest <span class="sy0">:</span> CalidusTestBase<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="br0">&#91;</span>SetUp<span class="br0">&#93;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">override</span> <span class="kw1">void</span> SetUp<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">base</span>.<span class="me1">SetUp</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Next, define a series of tests to indicate what is needed, and in this case a single test will suffice. Some additional information is needed to make this test work, so the basic frame of the test class must be expanded to suit the requirements for mocking.</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="br0">&#91;</span>TestFixture<span class="br0">&#93;</span><br />
<span class="kw1">public</span> <span class="kw4">class</span> IndexerStatementFactoryTest <span class="sy0">:</span> CalidusTestBase<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">private</span> IndexerStatementFactory _factory<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">private</span> IStatementContext _context<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">private</span> MockRepository _mocker<span class="sy0">;</span></p>
<p>&nbsp; &nbsp; <span class="br0">&#91;</span>SetUp<span class="br0">&#93;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">override</span> <span class="kw1">void</span> SetUp<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">base</span>.<span class="me1">SetUp</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _factory <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> IndexerStatementFactory<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _mocker <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> MockRepository<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _context <span class="sy0">=</span> _mocker.<span class="me1">DynamicMock</span><span class="sy0">&lt;</span>IStatementContext<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="br0">&#91;</span>Test<span class="br0">&#93;</span><br />
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">void</span> FactoryShouldCreateStatementFromThisFollowedBySquareBracketInClass<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Expect.<span class="me1">Call</span><span class="br0">&#40;</span>_context.<span class="me1">Parents</span><span class="br0">&#41;</span>.<span class="kw1">Return</span><span class="br0">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#123;</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> StatementParent<span class="br0">&#40;</span>StatementCreator.<span class="me1">CreateClassStatement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>, StatementCreator.<span class="me1">CreateOpenBlockStatement</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">Repeat</span>.<span class="me1">Once</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; IList<span class="sy0">&lt;</span>TokenBase<span class="sy0">&gt;</span> input <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> List<span class="sy0">&lt;</span>TokenBase<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; input.<span class="me1">Add</span><span class="br0">&#40;</span>TokenCreator.<span class="me1">Create</span><span class="sy0">&lt;</span>PublicModifierToken<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; input.<span class="me1">Add</span><span class="br0">&#40;</span>TokenCreator.<span class="me1">Create</span><span class="sy0">&lt;</span>SpaceToken<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; input.<span class="me1">Add</span><span class="br0">&#40;</span>TokenCreator.<span class="me1">Create</span><span class="sy0">&lt;</span>IdentifierToken<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="st0">&quot;String&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; input.<span class="me1">Add</span><span class="br0">&#40;</span>TokenCreator.<span class="me1">Create</span><span class="sy0">&lt;</span>SpaceToken<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; input.<span class="me1">Add</span><span class="br0">&#40;</span>TokenCreator.<span class="me1">Create</span><span class="sy0">&lt;</span>ThisToken<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; input.<span class="me1">Add</span><span class="br0">&#40;</span>TokenCreator.<span class="me1">Create</span><span class="sy0">&lt;</span>OpenSquareBracketToken<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; input.<span class="me1">Add</span><span class="br0">&#40;</span>TokenCreator.<span class="me1">Create</span><span class="sy0">&lt;</span>IntToken<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; input.<span class="me1">Add</span><span class="br0">&#40;</span>TokenCreator.<span class="me1">Create</span><span class="sy0">&lt;</span>SpaceToken<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; input.<span class="me1">Add</span><span class="br0">&#40;</span>TokenCreator.<span class="me1">Create</span><span class="sy0">&lt;</span>IdentifierToken<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="st0">&quot;index&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; input.<span class="me1">Add</span><span class="br0">&#40;</span>TokenCreator.<span class="me1">Create</span><span class="sy0">&lt;</span>CloseSquareBracketToken<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; _mocker.<span class="me1">ReplayAll</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Assert.<span class="me1">IsTrue</span><span class="br0">&#40;</span>_factory.<span class="me1">CanCreateStatementFrom</span><span class="br0">&#40;</span>input, _context<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _mocker.<span class="me1">VerifyAll</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>This test code defines a mock statement context that indicates that the list of tokens to be parsed by the factory was found inside a class. The token list to parse is also created here.</p>
<h2><strong>Making it work</strong></h2>
<p>The following code is fairly simple as there are only two requirements for an indexer statement. First of all, it is part of a class: it can only be defined where the parent of the statement is the scope of a class. Second, an indexer statement consists of the This-keyword followed by a square bracket open.  Both requirements can be expressed in code.</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="kw1">protected</span> <span class="kw1">override</span> <span class="kw4">bool</span> IsValidContext<span class="br0">&#40;</span>IStatementContext context<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> context.<span class="me1">Parents</span>.<span class="me1">FirstParentIsOfType</span><span class="sy0">&lt;</span>ClassStatement<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw1">protected</span> <span class="kw1">override</span> IStatementExpression Expression<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; get <br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; StatementExpression expression <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> StatementExpression<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; expression.<span class="me1">Contains</span><span class="sy0">&lt;</span>ThisToken<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.<span class="me1">FollowedBy</span><span class="sy0">&lt;</span>OpenSquareBracketToken<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> expression<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>Combining these two pieces of codes validates both the context and the tokens, and running the unit tests with this code now yields a nice green bar.</p>
]]></content:encoded>
			<wfw:commentRss>http://jdt.toron.be/blog/2009/11/creating-custom-statements/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introducing&#8230;</title>
		<link>http://jdt.toron.be/blog/2009/10/introducing/</link>
		<comments>http://jdt.toron.be/blog/2009/10/introducing/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 01:02:20 +0000</pubDate>
		<dc:creator>JDT</dc:creator>
				<category><![CDATA[Various]]></category>
		<category><![CDATA[Calidus]]></category>

		<guid isPermaLink="false">http://jdt.toron.be/blog/?p=51</guid>
		<description><![CDATA[The Calidus Logo!

]]></description>
			<content:encoded><![CDATA[<p>The Calidus Logo!</p>
<p><img class="size-full wp-image-52 alignleft" title="Calidus Logo" src="http://jdt.toron.be/blog/wp-content/uploads/2009/10/calidus_logo.jpg" alt="The Calidus Logo" width="200" height="200" /></p>
]]></content:encoded>
			<wfw:commentRss>http://jdt.toron.be/blog/2009/10/introducing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Calidus Model</title>
		<link>http://jdt.toron.be/blog/2009/10/the-calidus-model/</link>
		<comments>http://jdt.toron.be/blog/2009/10/the-calidus-model/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 21:24:29 +0000</pubDate>
		<dc:creator>JDT</dc:creator>
				<category><![CDATA[Various]]></category>
		<category><![CDATA[Blocks]]></category>
		<category><![CDATA[Calidus]]></category>
		<category><![CDATA[Lines]]></category>
		<category><![CDATA[Rules]]></category>
		<category><![CDATA[Statements]]></category>
		<category><![CDATA[Tokens]]></category>

		<guid isPermaLink="false">http://jdt.toron.be/blog/?p=42</guid>
		<description><![CDATA[Abstract
In which the author outlines the basics of Calidus, the most important concepts and classes and how to use them.
Concrete
Calidus is not a terribly complex application. There are no zillion classes to get to know, there are no hard words or hidden meanings and most things do exactly what they sound like. In order to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Abstract</strong></p>
<p>In which the author outlines the basics of Calidus, the most important concepts and classes and how to use them.</p>
<p><strong>Concrete</strong></p>
<p>Calidus is not a terribly complex application. There are no zillion classes to get to know, there are no hard words or hidden meanings and most things do exactly what they sound like. In order to take full advantage of Calidus and develop custom parts such as rules it is important to know some of the inner workings of Calidus. This part is intended for advanced users and is a must-read for developers.</p>
<h2>Characters</h2>
<p>Technically, the smallest part of Calidus is the character, provided by the builtin character class. The concept of a character is not explicitly present in Calidus because no rule validation is performed on characters, but since they are the base element on which a token is built they deserve an honorable mention.</p>
<h2>Tokens</h2>
<p>A token is the smallest usefull part of the Calidus model. A token can be described as a collection containing at least one character, grouped together in the builtin String class. A token is either:</p>
<ul>
<li>A single-character token, such as a <em>SpaceToken </em>or a <em>TabToken</em></li>
<li>A single string token, such as an <em>IdentifierToken </em>or a <em>NameSpaceToken</em></li>
<li>A multiple string token, such as a <em>LineCommentToken</em></li>
</ul>
<p>Calidus uses <a href="http://www.ssw.uni-linz.ac.at/coco/" target="_blank">Coco/R</a> to parse source code into tokens. This means that the list of tokens recognized by Calidus is almost exactly the same as the list of tokens recognized by Coco/R. There are some exceptions to this rule: whitespace is not normally part of the Coco/R parser&#8217;s returned token types and is therefore provided by an additional parser.</p>
<p>Tokens that cannot be parsed as a more specific token are <em>GenericTokens</em>.</p>
<h2>Statements</h2>
<p>A statement is a collection containing at least one token. What exactly constitutes a statement is somewhat determined by the C# language: in most cases the end of a statement is a semicolon. For <em>if</em>, <em>for</em>, <em>while</em> constructs and the likes the end of a statement is the closing round bracket &#8216;)&#8217;, and for attributes the end of a statement is the closing square bracket &#8216;]&#8217;.</p>
<p>The statement parser groups tokens together by splitting them at certain well-defined places, the most common example of this is when a semicolon was encountered. There are other ways to group statements, which include using brackets, newlines and other special token types.<span style="color: #ff0000;"></span></p>
<p>Parsing token groups to see if they match a statement definition is a complex operation, and the definition of what constitutes a statement can differ greatly.  One thing that creates a lot of complexity is the amount of whitespace separating tokens, which may or may not be relevant depending on the context. To make token parsing easy Calidus provides a fluent interface that allows a declarative statement definition.</p>
<p>Statements that cannot be parsed as a more specific statement are <em>GenericStatements</em>.</p>
<h2>Lines</h2>
<p>Lines are probably the easiest elements in the Calidus model. A line is just a line: it is a collection of tokens that reside on the same line. Lines are the only elements that can have rules associated with them but do not have any native support for pluggable definitions and extensions: what constitutes a line can never change and is fixed by Calidus.</p>
<h2>Blocks</h2>
<p>Blocks are logical groupings of at least one statement. Blocks have very wide definitions: a series of using statements in a file are grouped into a block because they are related, but so are all elements in the source file since they compose the <em>FileBlock</em>.  The entire contents of a class constitutes a <em>ClassBlock</em>, and blocks are also the place where an <em>if</em>, <em>while</em>, <em>for</em>, <em>do while, foreach&#8230;</em> statement is present along with the code that is run as part of it.</p>
<h2>Rules</h2>
<p>Calidus is a source style validation tool, and the constraints placed on the source are coded into rules. Rules can be put on top of the following Calidus elements:</p>
<ul>
<li>Statements, based off of <em>StatementRuleBase</em></li>
<li>Lines, based off of <em>LineRuleBase</em></li>
<li>Blocks, based off of <em>BlockRuleBase</em></li>
</ul>
<p>Tokens do not have rules associated with them as a token itself cannot be invalid. For example, a line comment is parsed into a <em>LineCommentToken</em>, but validating this token must be done through the statement that contains this token which is the <em>LineCommentStatement</em>.</p>
<p>Calidus rules are automatically configured by the class reponsible for creating them, allowing a user to use a pre-built rule but apply some customization to it. A good example of this principle is the <em>MemberNameMatchesPatternRule</em>, where a class member&#8217;s name is validated against a regex pattern. The pattern itself has a default setting, which can be adjusted to meet the developers needs.  This is unlike Microsoft&#8217;s StyleCop tool, which has several rules used to validate member names, each of which must be enabled or disabled and might not even meet the requirements when a naming pattern is used that is not built into the application. Rule configuration can be done through the main Calidus GUI.</p>
]]></content:encoded>
			<wfw:commentRss>http://jdt.toron.be/blog/2009/10/the-calidus-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I did it</title>
		<link>http://jdt.toron.be/blog/2009/10/i-did-it/</link>
		<comments>http://jdt.toron.be/blog/2009/10/i-did-it/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 21:17:37 +0000</pubDate>
		<dc:creator>JDT</dc:creator>
				<category><![CDATA[Various]]></category>
		<category><![CDATA[Calidus]]></category>

		<guid isPermaLink="false">http://jdt.toron.be/blog/?p=47</guid>
		<description><![CDATA[Calidus is now published at http://code.google.com/p/calidus/
]]></description>
			<content:encoded><![CDATA[<p>Calidus is now published at <a href="http://code.google.com/p/calidus/" target="_blank">http://code.google.com/p/calidus/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jdt.toron.be/blog/2009/10/i-did-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
