<?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>Matthew Manela&#039;s Home Page</title>
	<atom:link href="http://matthewmanela.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewmanela.com</link>
	<description>The life and work of Matthew Manela</description>
	<lastBuildDate>Sun, 28 Feb 2010 02:10:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DiffPlex 1.0 Released!!</title>
		<link>http://blogs.msdn.com/matt/archive/2010/02/27/diffplex-1-0-released.aspx</link>
		<comments>http://blogs.msdn.com/matt/archive/2010/02/27/diffplex-1-0-released.aspx#comments</comments>
		<pubDate>Sun, 28 Feb 2010 02:10:00 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[Codeplex]]></category>
		<category><![CDATA[DiffPlex]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blogs.msdn.com/matt/archive/2010/02/27/diffplex-1-0-released.aspx</guid>
		<description><![CDATA[The DiffPlex (http://diffplex.codeplex.com) project is now available on Codeplex!
The DiffPlex project is a combination of a .NET Diffing Library with a Silverlight and HTML diff viewer. It is released open source under the MS-PL license. 

The library...]]></description>
			<content:encoded><![CDATA[<P style="FONT-SIZE: 18px">The <A href="http://diffplex.codeplex.com/"  mce_href="http://diffplex.codeplex.com/">DiffPlex</A> (<A href="http://diffplex.codeplex.com/" mce_href="http://diffplex.codeplex.com">http://diffplex.codeplex.com</A>) project is now available on <A href="http://codeplex.com/"  mce_href="http://codeplex.com">Codeplex</A>!</P>
<P>The DiffPlex project is a combination of a .NET Diffing Library with a Silverlight and HTML diff viewer. It is released open source under the MS-PL license. </P>
<UL>
<LI>The library allows developers to embed diffing functionality inside their applications or websites. (<A href="http://diffplex.codeplex.com/wikipage?title=library&amp;referringTitle=Home"  mce_href="http://diffplex.codeplex.com/wikipage?title=library&amp;referringTitle=Home">Click here to learn how to use the api</A>) </LI></UL>
<P><A href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/code_2.png" mce_href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/code_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=code border=0 alt=code src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/code_thumb.png" width=654 height=236 mce_src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/code_thumb.png"></A> </P>
<UL>
<LI>The Silverlight viewer allows real-time diffing of documents. (<A href="http://diffplex.codeplex.com/wikipage?title=silverlight&amp;referringTitle=Home"  mce_href="http://diffplex.codeplex.com/wikipage?title=silverlight&amp;referringTitle=Home">Click here to try it out</A>) </LI></UL>
<P><A href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/silverlight_2.png" mce_href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/silverlight_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=silverlight border=0 alt=silverlight src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/silverlight_thumb.png" width=654 height=288 mce_src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/silverlight_thumb.png"></A> </P>
<UL>
<LI>The website viewer shows how to embed diffing functionality inside of a website. (<A href="http://diffplex.codeplex.com/wikipage?title=website&amp;referringTitle=Home"  mce_href="http://diffplex.codeplex.com/wikipage?title=website&amp;referringTitle=Home">Click here to learn more</A>) </LI></UL>
<P><A href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/websiteInput_2.png" mce_href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/websiteInput_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=websiteInput border=0 alt=websiteInput src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/websiteInput_thumb.png" width=654 height=229 mce_src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/websiteInput_thumb.png"></A> </P>
<P mce_keep="true">&nbsp;</P>
<P mce_keep="true">&nbsp;</P>
<P><A href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/websiteOutput_2.png" mce_href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/websiteOutput_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=websiteOutput border=0 alt=websiteOutput src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/websiteOutput_thumb.png" width=654 height=248 mce_src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/DiffPlex1.0Released_FE1E/websiteOutput_thumb.png"></A></P><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9970421" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://blogs.msdn.com/matt/archive/2010/02/27/diffplex-1-0-released.aspx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Snippet Designer 1.2 Beta Release with Visual Studio 2010 Support</title>
		<link>http://blogs.msdn.com/matt/archive/2010/01/22/snippet-designer-1-2-beta-release-with-visual-studio-2010-support.aspx</link>
		<comments>http://blogs.msdn.com/matt/archive/2010/01/22/snippet-designer-1-2-beta-release-with-visual-studio-2010-support.aspx#comments</comments>
		<pubDate>Fri, 22 Jan 2010 14:52:00 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[Codeplex]]></category>
		<category><![CDATA[Snippet Designer]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio Gallery]]></category>

		<guid isPermaLink="false">http://blogs.msdn.com/matt/archive/2010/01/22/snippet-designer-1-2-beta-release-with-visual-studio-2010-support.aspx</guid>
		<description><![CDATA[Yesterday I released Snippet Designer 1.2 Beta. 
Codeplex Page: http://snippetdesigner.codeplex.com/
Visual Studio Gallery Page: http://visualstudiogallery.msdn.microsoft.com/en-us/B08B0375-139E-41D7-AF9B-FAEE50F68392
This release contains several bug ...]]></description>
			<content:encoded><![CDATA[<P>Yesterday I released Snippet Designer 1.2 Beta. </P>
<P>Codeplex Page: <A title=http://snippetdesigner.codeplex.com/ href="http://snippetdesigner.codeplex.com/" mce_href="http://snippetdesigner.codeplex.com/">http://snippetdesigner.codeplex.com/</A></P>
<P>Visual Studio Gallery Page: <A title=http://visualstudiogallery.msdn.microsoft.com/en-us/B08B0375-139E-41D7-AF9B-FAEE50F68392 href="http://visualstudiogallery.msdn.microsoft.com/en-us/B08B0375-139E-41D7-AF9B-FAEE50F68392" mce_href="http://visualstudiogallery.msdn.microsoft.com/en-us/B08B0375-139E-41D7-AF9B-FAEE50F68392">http://visualstudiogallery.msdn.microsoft.com/en-us/B08B0375-139E-41D7-AF9B-FAEE50F68392</A></P>
<P>This release contains several bug fixes but more importantly it now includes support for Visual Studio 2010. </P>
<P>I am super excited for this since now you can install the Snippet Designer from inside of Visual Studio using the new extension manager. Just open up the extension manager and search for “Snippet Designer”.</P>
<P><A href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/Sni.2BetaReleasewithVisualStudio2010Supp_F28A/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/Sni.2BetaReleasewithVisualStudio2010Supp_F28A/image_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; WIDTH: 658px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; HEIGHT: 488px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/Sni.2BetaReleasewithVisualStudio2010Supp_F28A/image_thumb.png" width=817 height=566 mce_src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/Sni.2BetaReleasewithVisualStudio2010Supp_F28A/image_thumb.png"></A></P>
<P>Then you just need to install it and restart Visual Studio.</P>
<P><A href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/Sni.2BetaReleasewithVisualStudio2010Supp_F28A/image_6.png" mce_href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/Sni.2BetaReleasewithVisualStudio2010Supp_F28A/image_6.png"><IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; WIDTH: 655px; DISPLAY: inline; HEIGHT: 475px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/Sni.2BetaReleasewithVisualStudio2010Supp_F28A/image_thumb_2.png" width=815 height=565 mce_src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/Sni.2BetaReleasewithVisualStudio2010Supp_F28A/image_thumb_2.png"></A> </P>
<P>Enjoy!</P><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9951993" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://blogs.msdn.com/matt/archive/2010/01/22/snippet-designer-1-2-beta-release-with-visual-studio-2010-support.aspx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regex based Lexer with F#</title>
		<link>http://blogs.msdn.com/matt/archive/2010/01/19/regex-lexer-with-f.aspx</link>
		<comments>http://blogs.msdn.com/matt/archive/2010/01/19/regex-lexer-with-f.aspx#comments</comments>
		<pubDate>Tue, 19 Jan 2010 14:52:00 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blogs.msdn.com/matt/archive/2010/01/19/regex-lexer-with-f.aspx</guid>
		<description><![CDATA[This lexer allows you to define your regular expression based rules in a very declarative way using F# computation expressions. open Lexer
let definitions = 
    lexerDefinitions {
        do! addNextlineDefinition "NEWLINE" @"(\n\r)&#124;\n&#124;\r"
        do!...]]></description>
			<content:encoded><![CDATA[<P>This lexer allows you to define your regular expression based rules in a very declarative way using F# computation expressions. </P><PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">open Lexer
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> definitions = 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    lexerDefinitions {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">do</SPAN>! addNextlineDefinition "<SPAN style="COLOR: #8b0000">NEWLINE</SPAN>" @"<SPAN style="COLOR: #8b0000">(\n\r)|\n|\r</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">do</SPAN>! addIgnoreDefinition "<SPAN style="COLOR: #8b0000">WS</SPAN>"        @"<SPAN style="COLOR: #8b0000">\s</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">do</SPAN>! addDefinition "<SPAN style="COLOR: #8b0000">LET</SPAN>"             "<SPAN style="COLOR: #8b0000">let</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">do</SPAN>! addDefinition "<SPAN style="COLOR: #8b0000">ID</SPAN>"              "<SPAN style="COLOR: #8b0000">(?i)[a-z][a-z0-9]*</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">do</SPAN>! addDefinition "<SPAN style="COLOR: #8b0000">FLOAT</SPAN>"           @"<SPAN style="COLOR: #8b0000">[0-9]+\.[0-9]+</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">do</SPAN>! addDefinition "<SPAN style="COLOR: #8b0000">INT</SPAN>"             "<SPAN style="COLOR: #8b0000">[0-9]+</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">do</SPAN>! addDefinition "<SPAN style="COLOR: #8b0000">OPERATOR</SPAN>"      @"<SPAN style="COLOR: #8b0000">[+*=!/&amp;|&lt;&gt;\^\-]+</SPAN>"   
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    }</PRE></PRE>
<P>With those defined you can execute the lexer with:</P><PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">open Lexer
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> lex input = 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">try</SPAN>    
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">let</SPAN> y = Lexer.tokenize definitions input
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        printfn "<SPAN style="COLOR: #8b0000">%A</SPAN>" y
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">with</SPAN> e -&gt; printf "<SPAN style="COLOR: #8b0000">%s</SPAN>" e.Message
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">lex "<SPAN style="COLOR: #8b0000">let a = 5</SPAN>"</PRE></PRE>
<P>Which will result in:</P>
<BLOCKQUOTE>
<P align=left>seq [{name = "LET"; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text = "let"; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos = 0; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; column = 0; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line = 0;}; {name = "ID"; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text = "a"; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos = 4; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; column = 4; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line = 0;}; {name = "OPERATOR"; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text = "="; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos = 6; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; column = 6; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line = 0;}; {name = "INT"; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text = "5"; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos = 8; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; column = 8; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line = 0;}]</P></BLOCKQUOTE>
<P align=left>The lexer’s code is structured in three parts.&nbsp; The first part is a state monad using the F# computation expressions.&nbsp; This enables the declarative approach (seen above) to setup your lexer rules.</P><PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">module StateMonad
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">type State&lt;'s,'a&gt; = State of ('s -&gt; ('a *'s))
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> runState (State f) = f
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">type StateBuilder() = 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    member b.Return(x) = State (fun s -&gt; (x,s))
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    member b.Delay(f) = f() : State&lt;'s,'a&gt;
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    member b.Zero() = State (fun s -&gt; ((),s))
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    member b.Bind(State p,rest) = State (fun s -&gt; <SPAN style="COLOR: #0000ff">let</SPAN> v,s2 = p s <SPAN style="COLOR: #0000ff">in</SPAN>  (runState (rest v)) s2)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    member b.<SPAN style="COLOR: #0000ff">Get</SPAN> () = State (fun s -&gt; (s,s))
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    member b.Put s = State (fun _ -&gt; ((),s))</PRE></PRE>
<P>The second part are the combinators that are used to define your lexer rules.&nbsp; There are three main combinators:&nbsp; <STRONG>AddDefinition</STRONG> which lets you define a name / regex pair, <STRONG>AddIgnoreDefinition </STRONG>which lets you define characters which the lexer should ignore and <STRONG>AddNextlineDefinition </STRONG>which lets you define what characters determine a new line.</P><PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">type LexDefinitions = 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">  {regexes : <SPAN style="COLOR: #0000ff">string</SPAN> list;
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   names : <SPAN style="COLOR: #0000ff">string</SPAN> list;
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   nextlines : bool list;
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   ignores : bool list; }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> buildDefinition name pattern nextLine ignore =
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    state {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">let</SPAN>! x = state.<SPAN style="COLOR: #0000ff">Get</SPAN>()
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">do</SPAN>! state.Put { regexes = x.regexes @  [sprintf @"<SPAN style="COLOR: #8b0000">(?&lt;%s&gt;%s)</SPAN>" name pattern];
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                        names = x.names @ [name]; 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                        nextlines  = x.nextlines @ [nextLine];
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                        ignores = x.ignores @ [ignore]}
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> addDefinition name pattern = buildDefinition name pattern false false
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> addIgnoreDefinition name pattern = buildDefinition name pattern false true
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> addNextlineDefinition name pattern = buildDefinition name pattern true true    </PRE></PRE>
<P>And the final part is the code that performs the tokenizing.&nbsp; It uses the Seq.unfold method to create the list of tokens.&nbsp; Unfold is a function which takes a single item and generates a list of new items from it.&nbsp; It is the opposite of Seq.fold which takes a list of items and turns it into a single item.&nbsp; The tokenize function used Seq.unfold to generate each token while keeping track of the current line number, position in that line and position in the input string.</P><PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">type Token = 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    { name : <SPAN style="COLOR: #0000ff">string</SPAN>;
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">      text: <SPAN style="COLOR: #0000ff">string</SPAN>; 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">      pos :<SPAN style="COLOR: #0000ff">int</SPAN>;
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">      column: <SPAN style="COLOR: #0000ff">int</SPAN>;
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">      line: <SPAN style="COLOR: #0000ff">int</SPAN> }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> createLexDefs pb =  (runState pb) {regexes = []; names = []; nextlines = []; ignores = []} |&gt; snd
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"> 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> tokenize lexerBuilder (str:<SPAN style="COLOR: #0000ff">string</SPAN>) = 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">let</SPAN> patterns = createLexDefs lexerBuilder
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">let</SPAN> combinedRegex =  Regex(List.fold (fun acc reg -&gt; acc + "<SPAN style="COLOR: #8b0000">|</SPAN>" + reg) (List.head patterns.regexes) (List.tail patterns.regexes))
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">let</SPAN> nextlineMap = List.zip patterns.names patterns.nextlines |&gt; Map.ofList
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">let</SPAN> ignoreMap = List.zip patterns.names patterns.ignores |&gt; Map.ofList
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">let</SPAN> tokenizeStep (pos,line,lineStart) = 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">if</SPAN> pos &gt;= str.Length <SPAN style="COLOR: #0000ff">then</SPAN>
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            None
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">else</SPAN>
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            <SPAN style="COLOR: #0000ff">let</SPAN> getMatchedGroupName (grps:GroupCollection) names = List.find (fun (name:<SPAN style="COLOR: #0000ff">string</SPAN>) -&gt; grps.[name].Length &gt; 0) names
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            <SPAN style="COLOR: #0000ff">match</SPAN> combinedRegex.<SPAN style="COLOR: #0000ff">Match</SPAN>(str, pos) <SPAN style="COLOR: #0000ff">with</SPAN>
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                | mt when mt.Success &amp;&amp; pos = mt.Index  -&gt; 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    <SPAN style="COLOR: #0000ff">let</SPAN> groupName = getMatchedGroupName mt.Groups patterns.names
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    <SPAN style="COLOR: #0000ff">let</SPAN> column = mt.Index - lineStart
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    <SPAN style="COLOR: #0000ff">let</SPAN> nextPos = pos + mt.Length
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    <SPAN style="COLOR: #0000ff">let</SPAN> (nextLine, nextLineStart) = <SPAN style="COLOR: #0000ff">if</SPAN> nextlineMap.Item groupName <SPAN style="COLOR: #0000ff">then</SPAN> (line + 1, nextPos) <SPAN style="COLOR: #0000ff">else</SPAN> (line,lineStart)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    <SPAN style="COLOR: #0000ff">let</SPAN> token = <SPAN style="COLOR: #0000ff">if</SPAN> ignoreMap.Item groupName 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                                <SPAN style="COLOR: #0000ff">then</SPAN> None 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                                <SPAN style="COLOR: #0000ff">else</SPAN> Some {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                                        name = groupName; 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                                        text = mt.Value; 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                                        pos = pos; 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                                        line = line; 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                                        column = column; }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    Some(token, (nextPos, nextLine, nextLineStart))
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                | otherwise -&gt; 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    <SPAN style="COLOR: #0000ff">let</SPAN> textAroundError = str.Substring(pos, min (pos + 5) str.Length)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    raise (ArgumentException (sprintf "<SPAN style="COLOR: #8b0000">Lexing error occured at line:%d and column:%d near the text:%s</SPAN>" line (pos - lineStart) textAroundError))
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Seq.unfold tokenizeStep (0, 0, 0) |&gt; Seq.<SPAN style="COLOR: #0000ff">filter</SPAN> (fun x -&gt; x.IsSome) |&gt; Seq.map (fun x -&gt; x.Value)</PRE></PRE>
<P>Lastly, here are the unit tests written using <A href="http://xunit.codeplex.com/" mce_href="http://xunit.codeplex.com/">XUnit.Net</A>:</P><PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">module LexerFacts
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">open Xunit
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">open Lexer
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">open System.Linq
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> simpleDefs = 
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    state {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">do</SPAN>! addNextlineDefinition "<SPAN style="COLOR: #8b0000">NextLine</SPAN>"           "<SPAN style="COLOR: #8b0000">/</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">do</SPAN>! addIgnoreDefinition "<SPAN style="COLOR: #8b0000">IgnoredSymbol</SPAN>"        "<SPAN style="COLOR: #8b0000">=+</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">do</SPAN>! addDefinition "<SPAN style="COLOR: #8b0000">String</SPAN>"                     "<SPAN style="COLOR: #8b0000">[a-zA-Z]+</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">do</SPAN>! addDefinition "<SPAN style="COLOR: #8b0000">Number</SPAN>"                     "<SPAN style="COLOR: #8b0000">\d+</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">do</SPAN>! addDefinition "<SPAN style="COLOR: #8b0000">Name</SPAN>"                       "<SPAN style="COLOR: #8b0000">Matt</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">[&lt;Fact&gt;]
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> Will_return_no_tokens_for_empty_string() =
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">  
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">let</SPAN> tokens = Lexer.tokenize simpleDefs "<SPAN style="COLOR: #8b0000"></SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal(0, tokens.Count())
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">[&lt;Fact&gt;]
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> Will_throw_exception_for_invalid_token() =
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">  
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">let</SPAN> tokens = Lexer.tokenize simpleDefs "<SPAN style="COLOR: #8b0000">-</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">let</SPAN> ex = Assert.ThrowsDelegateWithReturn(fun () -&gt; upcast tokens.Count()) |&gt; Record.Exception
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.NotNull(ex)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.True(ex :? System.ArgumentException)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">[&lt;Fact&gt;]
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> Will_ignore_symbols_defined_as_ignore_symbols() =
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">  
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">let</SPAN> tokens = Lexer.tokenize simpleDefs "<SPAN style="COLOR: #8b0000">=========</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal(0, tokens.Count())
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">[&lt;Fact&gt;]
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> Will_get_token_with_correct_position_and_type() =
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">  
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">let</SPAN> tokens = Lexer.tokenize simpleDefs "<SPAN style="COLOR: #8b0000">1one=2=two</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal("<SPAN style="COLOR: #8b0000">Number</SPAN>",tokens.ElementAt(2).name)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal("<SPAN style="COLOR: #8b0000">2</SPAN>",tokens.ElementAt(2).text)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal(5,tokens.ElementAt(2).pos)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal(5,tokens.ElementAt(2).column)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal(0,tokens.ElementAt(2).line)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">[&lt;Fact&gt;]
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> Will_tokenize_string_with_alernating_numbers_and_strings() =
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">  
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">let</SPAN> tokens = Lexer.tokenize simpleDefs "<SPAN style="COLOR: #8b0000">1one2two</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal("<SPAN style="COLOR: #8b0000">1</SPAN>",tokens.ElementAt(0).text)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal("<SPAN style="COLOR: #8b0000">one</SPAN>",tokens.ElementAt(1).text)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal("<SPAN style="COLOR: #8b0000">2</SPAN>",tokens.ElementAt(2).text)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal("<SPAN style="COLOR: #8b0000">two</SPAN>",tokens.ElementAt(3).text)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">[&lt;Fact&gt;]
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> Will_increment_line_with_newline_symbol() =
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">  
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">let</SPAN> tokens = Lexer.tokenize simpleDefs "<SPAN style="COLOR: #8b0000">1one/2two</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal("<SPAN style="COLOR: #8b0000">Number</SPAN>",tokens.ElementAt(2).name)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal("<SPAN style="COLOR: #8b0000">2</SPAN>",tokens.ElementAt(2).text)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal(5,tokens.ElementAt(2).pos)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal(0,tokens.ElementAt(2).column)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal(1,tokens.ElementAt(2).line)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">[&lt;Fact&gt;]
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">let</SPAN> Will_give_priority_to_lexer_definitions_defined_earlier() =
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">  
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">let</SPAN> tokens = Lexer.tokenize simpleDefs "<SPAN style="COLOR: #8b0000">Matt</SPAN>"
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    Assert.Equal("<SPAN style="COLOR: #8b0000">String</SPAN>",tokens.ElementAt(0).name)</PRE></PRE>
<P mce_keep="true">&nbsp;</P>
<P>I attached a zip (<A href="http://blogs.msdn.com/matt/attachment/9950348.ashx" mce_href="http://blogs.msdn.com/matt/attachment/9950348.ashx">Lexer.zip</A>) containing all the code mentioned above.</P><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9950348" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://blogs.msdn.com/matt/archive/2010/01/19/regex-lexer-with-f.aspx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://blogs.msdn.com/matt/attachment/9950348.ashx" length="2225" type="application/x-zip-compressed" />
		</item>
		<item>
		<title>Count the number of lines in your project with one line of Powershell</title>
		<link>http://blogs.msdn.com/matt/archive/2009/12/11/count-the-number-of-lines-in-your-project-with-one-line-of-powershell.aspx</link>
		<comments>http://blogs.msdn.com/matt/archive/2009/12/11/count-the-number-of-lines-in-your-project-with-one-line-of-powershell.aspx#comments</comments>
		<pubDate>Fri, 11 Dec 2009 14:50:00 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://blogs.msdn.com/matt/archive/2009/12/11/count-the-number-of-lines-in-your-project-with-one-line-of-powershell.aspx</guid>
		<description><![CDATA[ls * -recurse -include *.aspx, *.ascx, *.cs, *.ps1 &#124; Get-Content &#124; Measure-Object -Line

Just replace the file extensions with the ones you use in your project.]]></description>
			<content:encoded><![CDATA[<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">ls * -recurse -include *.aspx, *.ascx, *.cs, *.ps1 | Get-Content | Measure-Object -Line</pre></pre>

<p>Just replace the file extensions with the ones you use in your project.</p><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9935693" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://blogs.msdn.com/matt/archive/2009/12/11/count-the-number-of-lines-in-your-project-with-one-line-of-powershell.aspx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful Moq Extension Method</title>
		<link>http://blogs.msdn.com/matt/archive/2009/11/24/useful-moq-extension-method.aspx</link>
		<comments>http://blogs.msdn.com/matt/archive/2009/11/24/useful-moq-extension-method.aspx#comments</comments>
		<pubDate>Wed, 25 Nov 2009 00:03:00 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[ASP .NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Moq]]></category>

		<guid isPermaLink="false">http://blogs.msdn.com/matt/archive/2009/11/24/useful-moq-extension-method.aspx</guid>
		<description><![CDATA[I have been working with ASP .NET MVC and I use the Moq mocking library to help test the code I write.&#160;&#160; Often in ASP MVC anonymous objects are passed around as function arguments.&#160; This is especially common in calls to RouteUrl.&#160; S...]]></description>
			<content:encoded><![CDATA[<P>I have been working with ASP .NET MVC and I use the <A href="http://code.google.com/p/moq/" mce_href="http://code.google.com/p/moq/">Moq</A> mocking library to help test the code I write.&nbsp;&nbsp; Often in ASP MVC anonymous objects are passed around as function arguments.&nbsp; This is especially common in calls to RouteUrl.&nbsp; Since I want to be able to test this and verify that it is called correctly I wrote a handy extension method to make it easier called <STRONG>AsMatch</STRONG>.</P>
<P>To be able to test the UrlHelper (since it doesn't have an interface or virtual methods) I wrote a simple wrapper around it with an interface to enable testing.&nbsp; Using that with this extension method makes testing route generation a breeze.</P>
<P>Given a call to generate a Url like this:</P><PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">var url = Url.RouteUrl("<SPAN style="COLOR: #8b0000">Show</SPAN>", <SPAN style="COLOR: #0000ff">new</SPAN> { projectName="<SPAN style="COLOR: #8b0000">matt</SPAN>" });</PRE></PRE>
<P>You can write a setup on your Mock of the Url helper using a similar syntax:</P><PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">UrlHelperMock
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">.Setup(x =&gt; x.RouteUrl("<SPAN style="COLOR: #8b0000">Show</SPAN>",<SPAN style="COLOR: #0000ff">new</SPAN>{ projectName="<SPAN style="COLOR: #8b0000">matt</SPAN>"}.AsMatch()))
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">.Return("<SPAN style="COLOR: #8b0000">someUrlToTest</SPAN>");</PRE></PRE>
<P>Here is the code that defines the AsMatch extension method:</P><PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN style="COLOR: #0000ff">static</SPAN> <SPAN style="COLOR: #0000ff">class</SPAN> ObjectMoqExtensions
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN style="COLOR: #0000ff">static</SPAN> <SPAN style="COLOR: #0000ff">object</SPAN> AsMatch(<SPAN style="COLOR: #0000ff">this</SPAN> <SPAN style="COLOR: #0000ff">object</SPAN> @<SPAN style="COLOR: #0000ff">object</SPAN>)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            <SPAN style="COLOR: #0000ff">return</SPAN> Match&lt;<SPAN style="COLOR: #0000ff">object</SPAN>&gt;.Create(testObject =&gt; DoObjectsMatch(@<SPAN style="COLOR: #0000ff">object</SPAN>, testObject));
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">private</SPAN> <SPAN style="COLOR: #0000ff">static</SPAN> <SPAN style="COLOR: #0000ff">bool</SPAN> DoObjectsMatch(<SPAN style="COLOR: #0000ff">object</SPAN> <SPAN style="COLOR: #0000ff">object</SPAN>1, <SPAN style="COLOR: #0000ff">object</SPAN> <SPAN style="COLOR: #0000ff">object</SPAN>2)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            var props1 = ToDictionary(<SPAN style="COLOR: #0000ff">object</SPAN>1);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            var props2 = ToDictionary(<SPAN style="COLOR: #0000ff">object</SPAN>2);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            var query = from prop1 <SPAN style="COLOR: #0000ff">in</SPAN> props1
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                        join prop2 <SPAN style="COLOR: #0000ff">in</SPAN> props2 on prop1.Key equals prop2.Key
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                        select prop1.Value.Equals(prop2.Value);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            <SPAN style="COLOR: #0000ff">return</SPAN> query.Count(x =&gt; x) == Math.Max(props1.Count(), props2.Count());
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN style="COLOR: #0000ff">static</SPAN> Dictionary&lt;<SPAN style="COLOR: #0000ff">string</SPAN>, <SPAN style="COLOR: #0000ff">object</SPAN>&gt; ToDictionary(<SPAN style="COLOR: #0000ff">object</SPAN> @<SPAN style="COLOR: #0000ff">object</SPAN>)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            var dictionary = <SPAN style="COLOR: #0000ff">new</SPAN> Dictionary&lt;<SPAN style="COLOR: #0000ff">string</SPAN>, <SPAN style="COLOR: #0000ff">object</SPAN>&gt;();
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            var properties = TypeDescriptor.GetProperties(@<SPAN style="COLOR: #0000ff">object</SPAN>);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            <SPAN style="COLOR: #0000ff">foreach</SPAN> (PropertyDescriptor property <SPAN style="COLOR: #0000ff">in</SPAN> properties)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                dictionary.Add(property.Name, property.GetValue(@<SPAN style="COLOR: #0000ff">object</SPAN>));
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            <SPAN style="COLOR: #0000ff">return</SPAN> dictionary;
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    }</PRE></PRE><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9928293" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://blogs.msdn.com/matt/archive/2009/11/24/useful-moq-extension-method.aspx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting RTF to HTML</title>
		<link>http://blogs.msdn.com/matt/archive/2009/09/28/converting-rtf-to-html.aspx</link>
		<comments>http://blogs.msdn.com/matt/archive/2009/09/28/converting-rtf-to-html.aspx#comments</comments>
		<pubDate>Mon, 28 Sep 2009 21:28:00 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[RTF]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://blogs.msdn.com/matt/archive/2009/09/28/converting-rtf-to-html.aspx</guid>
		<description><![CDATA[Have you ever had the desire to convert some RTF text into HTML? Probably not. But if you do, then you are in luck! I recently had the need to do this conversion and after some searching found out a way to do it by enhancing a sample distributed in the...]]></description>
			<content:encoded><![CDATA[<P>Have you ever had the desire to convert some RTF text into HTML? Probably not. But if you do, then you are in luck! I recently had the need to do this conversion and after some searching found out a way to do it by enhancing a sample distributed in the MSDN library.&nbsp; The sample is called: <A href="http://msdn.microsoft.com/en-us/library/aa972129.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa972129.aspx">XAML to HTML Conversion Demo</A>.&nbsp; </P>
<P>The sample has code which converts HTML to and from a XAML Flow Document.&nbsp; But this doesn’t make things easier until you realize that there is a way to convert RTF to XAML easily. The key is to use <A title=http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx href="http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx">System.Windows.Controls.RichTextBox</A> which can load RTF from a stream and save it as XAML.&nbsp; This conversion is shown below:</P><PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">private</SPAN> <SPAN style="COLOR: #0000ff">static</SPAN> <SPAN style="COLOR: #0000ff">string</SPAN> ConvertRtfToXaml(<SPAN style="COLOR: #0000ff">string</SPAN> rtfText)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            var richTextBox = <SPAN style="COLOR: #0000ff">new</SPAN> RichTextBox();
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            <SPAN style="COLOR: #0000ff">if</SPAN> (<SPAN style="COLOR: #0000ff">string</SPAN>.IsNullOrEmpty(rtfText)) <SPAN style="COLOR: #0000ff">return</SPAN> "<SPAN style="COLOR: #8b0000"></SPAN>";
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            var textRange = <SPAN style="COLOR: #0000ff">new</SPAN> TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            <SPAN style="COLOR: #0000ff">using</SPAN> (var rtfMemoryStream = <SPAN style="COLOR: #0000ff">new</SPAN> MemoryStream())
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                <SPAN style="COLOR: #0000ff">using</SPAN> (var rtfStreamWriter = <SPAN style="COLOR: #0000ff">new</SPAN> StreamWriter(rtfMemoryStream))
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    rtfStreamWriter.Write(rtfText);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    rtfStreamWriter.Flush();
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    rtfMemoryStream.Seek(0, SeekOrigin.Begin);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    textRange.Load(rtfMemoryStream, DataFormats.Rtf);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            <SPAN style="COLOR: #0000ff">using</SPAN> (var rtfMemoryStream = <SPAN style="COLOR: #0000ff">new</SPAN> MemoryStream())
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                textRange = <SPAN style="COLOR: #0000ff">new</SPAN> TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                textRange.Save(rtfMemoryStream, DataFormats.Xaml);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                rtfMemoryStream.Seek(0, SeekOrigin.Begin);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                <SPAN style="COLOR: #0000ff">using</SPAN> (var rtfStreamReader = <SPAN style="COLOR: #0000ff">new</SPAN> StreamReader(rtfMemoryStream))
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                    <SPAN style="COLOR: #0000ff">return</SPAN> rtfStreamReader.ReadToEnd();
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">                }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        }</PRE></PRE>
<P>With this code we have all we need to convert RTF to HTML. I modified the sample to add this RTF To XAML conversation and then I run that XAML through HTML converter which results in the HTML text. I added an interface to these conversion utilities and converted the sample into a library so that I would be able to use it from other projects.&nbsp; Here is the interface:</P><PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"> <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN style="COLOR: #0000ff">interface</SPAN> IMarkupConverter
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">string</SPAN> ConvertXamlToHtml(<SPAN style="COLOR: #0000ff">string</SPAN> xamlText);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">string</SPAN> ConvertHtmlToXaml(<SPAN style="COLOR: #0000ff">string</SPAN> htmlText);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">string</SPAN> ConvertRtfToHtml(<SPAN style="COLOR: #0000ff">string</SPAN> rtfText);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN style="COLOR: #0000ff">class</SPAN> MarkupConverter : IMarkupConverter
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN style="COLOR: #0000ff">string</SPAN> ConvertXamlToHtml(<SPAN style="COLOR: #0000ff">string</SPAN> xamlText)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            <SPAN style="COLOR: #0000ff">return</SPAN> HtmlFromXamlConverter.ConvertXamlToHtml(xamlText, <SPAN style="COLOR: #0000ff">false</SPAN>);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN style="COLOR: #0000ff">string</SPAN> ConvertHtmlToXaml(<SPAN style="COLOR: #0000ff">string</SPAN> htmlText)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            <SPAN style="COLOR: #0000ff">return</SPAN> HtmlToXamlConverter.ConvertHtmlToXaml(htmlText, <SPAN style="COLOR: #0000ff">true</SPAN>);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN style="COLOR: #0000ff">string</SPAN> ConvertRtfToHtml(<SPAN style="COLOR: #0000ff">string</SPAN> rtfText)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        {
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">            <SPAN style="COLOR: #0000ff">return</SPAN> RtfToHtmlConverter.ConvertRtfToHtml(rtfText);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">    }</PRE></PRE>
<P>With this I am now able to convert from RTF to HTML.&nbsp; However, there is one catch - the conversion uses the RichTextBox WPF control which requires a single threaded apartment (STA).&nbsp; Therefore in order to run your code that calls the ConvertRtfToHtml function, it must also be running in a STA.&nbsp; If you can’t have your program run in a STA then you must create a new STA thread to run the conversion. Like this:</P><PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">MarkupConverter markupConverter = <SPAN style="COLOR: #0000ff">new</SPAN> MarkupConverter();
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">private</SPAN> <SPAN style="COLOR: #0000ff">string</SPAN> ConvertRtfToHtml(<SPAN style="COLOR: #0000ff">string</SPAN> rtfText)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">{
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   var thread = <SPAN style="COLOR: #0000ff">new</SPAN> Thread(ConvertRtfInSTAThread);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   var threadData = <SPAN style="COLOR: #0000ff">new</SPAN> ConvertRtfThreadData { RtfText = rtfText };
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   thread.SetApartmentState(ApartmentState.STA);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   thread.Start(threadData);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   thread.Join();
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   <SPAN style="COLOR: #0000ff">return</SPAN> threadData.HtmlText;
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">}
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"></PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">private</SPAN> <SPAN style="COLOR: #0000ff">void</SPAN> ConvertRtfInSTAThread(<SPAN style="COLOR: #0000ff">object</SPAN> rtf)
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">{
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   var threadData = rtf <SPAN style="COLOR: #0000ff">as</SPAN> ConvertRtfThreadData;
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   threadData.HtmlText = markupConverter.ConvertRtfToHtml(threadData.RtfText);
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">}
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">        
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"><SPAN style="COLOR: #0000ff">private</SPAN> <SPAN style="COLOR: #0000ff">class</SPAN> ConvertRtfThreadData
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">{
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN style="COLOR: #0000ff">string</SPAN> RtfText { <SPAN style="COLOR: #0000ff">get</SPAN>; <SPAN style="COLOR: #0000ff">set</SPAN>; }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">   <SPAN style="COLOR: #0000ff">public</SPAN> <SPAN style="COLOR: #0000ff">string</SPAN> HtmlText { <SPAN style="COLOR: #0000ff">get</SPAN>; <SPAN style="COLOR: #0000ff">set</SPAN>; }
</PRE><PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px">}</PRE></PRE>
<P>Here is the zip contain the code for the Markup converter: <A href="http://blogs.msdn.com/matt/attachment/9900386.ashx" mce_href="http://blogs.msdn.com/matt/attachment/9900386.ashx">MarkupConverter.zip</A></P><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9900386" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://blogs.msdn.com/matt/archive/2009/09/28/converting-rtf-to-html.aspx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://blogs.msdn.com/matt/attachment/9900386.ashx" length="64021" type="application/x-zip-compressed" />
		</item>
		<item>
		<title>I finally got fed up with Enum.Parse</title>
		<link>http://blogs.msdn.com/matt/archive/2009/07/24/i-finally-got-fed-up-with-enum-parse.aspx</link>
		<comments>http://blogs.msdn.com/matt/archive/2009/07/24/i-finally-got-fed-up-with-enum-parse.aspx#comments</comments>
		<pubDate>Fri, 24 Jul 2009 19:02:04 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blogs.msdn.com/matt/archive/2009/07/24/i-finally-got-fed-up-with-enum-parse.aspx</guid>
		<description><![CDATA[I don’t know why I didn’t do this long ago, but I am done writing this:     var val = (SomeEnum)Enum.Parse(typeof(SomeEnum),”someString”);

I have typed this too many times and it annoys me.&#160; 

I wrote a small extension method on the st...]]></description>
			<content:encoded><![CDATA[<p>I don’t know why I didn’t do this long ago, but I am done writing this:</p>  <div>   <pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">var val = (SomeEnum)Enum.Parse(<span style="color: #0000ff">typeof</span>(SomeEnum),”someString”);</pre>
</div>

<p></p>

<p>I have typed this too many times and it annoys me.&#160; </p>

<p>I wrote a small extension method on the string type to make this better:</p>

<div>
  <pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">class</span> StringExtensions
{
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> T ToEnum&lt;T&gt;(<span style="color: #0000ff">this</span> <span style="color: #0000ff">string</span> @<span style="color: #0000ff">string</span>)
    {
        <span style="color: #0000ff">return</span> (T)Enum.Parse(<span style="color: #0000ff">typeof</span> (T), @<span style="color: #0000ff">string</span>);
    }
}</pre>
</div>

<p>With this I can now write the previous line as:</p>

<div>
  <pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">var val = <span style="color: #006080">&quot;someString&quot;</span>.ToEnum&lt;SomeEnum&gt;()</pre>
</div>

<p></p>
It is a bit shorter and I think much more readable.<img src="http://blogs.msdn.com/aggbug.aspx?PostID=9847679" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://blogs.msdn.com/matt/archive/2009/07/24/i-finally-got-fed-up-with-enum-parse.aspx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DRY and Unit Tests don’t mix well</title>
		<link>http://blogs.msdn.com/matt/archive/2009/07/12/dry-and-unit-tests-don-t-mix-well.aspx</link>
		<comments>http://blogs.msdn.com/matt/archive/2009/07/12/dry-and-unit-tests-don-t-mix-well.aspx#comments</comments>
		<pubDate>Mon, 13 Jul 2009 06:08:50 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blogs.msdn.com/matt/archive/2009/07/12/dry-and-unit-tests-don-t-mix-well.aspx</guid>
		<description><![CDATA[When reading source code, I sometimes come across unappealing code(sometimes even my own).&#160; However, there is one kind of “bad code” I see quite frequently.&#160; It is a set of unit tests which have had the DRY (Don't Repeat Yourself) princip...]]></description>
			<content:encoded><![CDATA[<p>When reading<em> </em>source code, I sometimes come across unappealing code(sometimes even my own).&#160; However, there is one kind of “bad code” I see quite frequently.&#160; It is a set of unit tests which have had the <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself" >DRY (Don't Repeat Yourself)</a> principle unduly forced upon them.&#160; DRY is the idea that you shouldn’t have to write the same code over and over; abstract it in a function or a class and just call the abstraction.&#160; This is all well and good in most cases, but I find it misguided when applied to a test case.&#160; </p>  <p>A test case should be like a simple short story.&#160; The characters are introduced, action/conflict occurs and then resolution takes place (sometimes with a moral).&#160; This (kind of) corresponds to the 3 steps of a unit test: arrange, act and assert.&#160; You arrange and setup what you need for your test to run, you perform the action that you are trying to test and then you assert the results. The issue I find is that a coder, in attempting to apply DRY to his test cases, will abstract away all of the arrange step into a function often with a name like SetupExpectations or just Setup.&#160; This goes against the point of a test case. A test case needs to be concise and tell me everything I need to know about how that one bit of functionality works. I don’t want to jump around the test class trying to read one test case. To me, this is like reading a book that says, “If you want to learn about the characters in this book please open this other book.”&#160; This doesn’t stop you from understanding the test, but it slows you down…and is just annoying.</p>  <p>&#160;</p>  <p>That is why I will come out and say <strong>do not apply DRY haphazardly to test cases</strong>. </p><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9830902" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://blogs.msdn.com/matt/archive/2009/07/12/dry-and-unit-tests-don-t-mix-well.aspx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to teach your girlfriend Hexadecimal?</title>
		<link>http://blogs.msdn.com/matt/archive/2009/05/06/how-to-teach-your-girlfriend-hexadecimal.aspx</link>
		<comments>http://blogs.msdn.com/matt/archive/2009/05/06/how-to-teach-your-girlfriend-hexadecimal.aspx#comments</comments>
		<pubDate>Wed, 06 May 2009 23:49:00 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://blogs.msdn.com/matt/archive/2009/05/06/how-to-teach-your-girlfriend-hexadecimal.aspx</guid>
		<description><![CDATA[It is an age old question: How do you teach your girlfriend hex?   I encountered this problem when I was a web developer in college for a late night student activities program aptly named  Late Nite Binghamton.  My co-worker and girlfriend Mallory wa...]]></description>
			<content:encoded><![CDATA[<P>It is an age old question: How do you teach your girlfriend hex? </P>  <P>I encountered this problem when I was a web developer in college for a late night student activities program aptly named  Late Nite Binghamton.  My co-worker and girlfriend <A href="http://baconwrappedlife.com/" mce_href="http://baconwrappedlife.com/">Mallory</A> was a graduate assistant for the program and had many ideas for how to make the website better and more engaging.  While working with her she would often see me typing in the hexadecimal color codes in css such as:</P>  <P>color: #F24A7D</P>  <P>As I am inept with what color look good (I often say that I never learnt colors) I would often ask her for help with picking out colors and I decided that if she was able to give me these colors in their hex color codes it would make us more efficient :) I sat her down and described to her how they work but after talking for a bit I realized that although she understood everything that I said she wouldn’t gain a feel for what hex numbers related to what colors just from hearing me talk.</P>  <P>In order to help her gain this feel I created a simple game called <A href="http://mallory.jemts.com" mce_href="http://mallory.jemts.com">The Mallory Color Guessing Game</A>.  The game is a webpage which shows you a large colored box and it is your job to guess what the hex color code is.  </P>  <P><A href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/HowtoteachyourgirlfriendHexadecimal_EAD0/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/HowtoteachyourgirlfriendHexadecimal_EAD0/image_2.png"><IMG style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/HowtoteachyourgirlfriendHexadecimal_EAD0/image_thumb.png" mce_src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/HowtoteachyourgirlfriendHexadecimal_EAD0/image_thumb.png" width="634" height="484"></A> </P>  <P> </P>  <P>After you guess it tells you how close you were to the actual color:</P>  <P><A href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/HowtoteachyourgirlfriendHexadecimal_EAD0/image_4.png" mce_href="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/HowtoteachyourgirlfriendHexadecimal_EAD0/image_4.png"><IMG style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/HowtoteachyourgirlfriendHexadecimal_EAD0/image_thumb_1.png" mce_src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/HowtoteachyourgirlfriendHexadecimal_EAD0/image_thumb_1.png" width="638" height="484"></A> </P>  <P> </P>  <P>This game was a hit! Mallory loved it and she would compete with me to see who could guess the color the best.  Pretty quickly she gained a feel for what the hex digits meant and what color they represented. And that is how I taught my girlfriend hex!</P><P> </P><P>NOTE: Mallory consistently gets over 80% at the Mallory Color Guessing Game. </P><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9592379" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://blogs.msdn.com/matt/archive/2009/05/06/how-to-teach-your-girlfriend-hexadecimal.aspx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Snippet Designer in April’s MSDN Magazine!</title>
		<link>http://blogs.msdn.com/matt/archive/2009/04/14/snippet-designer-in-april-s-msdn-magazine.aspx</link>
		<comments>http://blogs.msdn.com/matt/archive/2009/04/14/snippet-designer-in-april-s-msdn-magazine.aspx#comments</comments>
		<pubDate>Wed, 15 Apr 2009 02:33:47 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Snippet Designer]]></category>

		<guid isPermaLink="false">http://blogs.msdn.com/matt/archive/2009/04/14/snippet-designer-in-april-s-msdn-magazine.aspx</guid>
		<description><![CDATA[I am excited to announce that the Snippet Designer is featured in the April issue of MSDN Magazine.&#160;     &#160;  &#160;  &#160;  &#160;  &#160;  &#160;  &#160;  &#160;  &#160;  It is featured in the Toolbox column where they highlight useful tools...]]></description>
			<content:encoded><![CDATA[<p>I am excited to announce that the <a href="http://snippetdesigner.codeplex.com/">Snippet Designer</a> is featured in the April issue of MSDN Magazine.&#160; </p>  <p><a href="http://msdn.microsoft.com/en-us/magazine/dd569763.aspx#id0080016"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="msdnMag" border="0" alt="msdnMag" align="left" src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/SnippetDesignerinAprilsMSDNMagazine_E895/msdnMag_3.gif" width="189" height="244" /></a></p>  <p>&#160;</p>  <p>&#160;</p>  <p>&#160;</p>  <p>&#160;</p>  <p>&#160;</p>  <p>&#160;</p>  <p>&#160;</p>  <p>&#160;</p>  <p>&#160;</p>  <p>It is featured in the <a href="http://msdn.microsoft.com/en-us/magazine/dd569763.aspx#id0080016">Toolbox column</a> where they highlight useful tools and blogs. Here is a snippet of what it says:</p>  <blockquote>   <p>Creating Code Snippets is a lot easier when using Snippet Designer (version 1.1), a free, open-source Add-In for Visual Studio 2008 for creating and editing Code Snippets directly within the IDE. Once you install it, creating a new Code Snippet is as easy as going to the File menu and creating a new Code Snippet File.</p> </blockquote>  <p>&#160;</p>  <p>That is so cool! If you are interested go and download the <a href="http://snippetdesigner.codeplex.com/">Snippet Designer</a> from the Codeplex website and give me more feedback.</p>  <p>&#160;</p>  <p>Also, in the same article my friend <a href="http://blogs.msdn.com/saraford/">Sara Ford</a> had her blog featured.&#160; When I found out the Snippet Designer and Sara’s blog were in the magazine I quickly emailed to ask Sara if she knew about it.&#160; She already did and also had an extra copy of the magazine for me!</p><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9549664" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://blogs.msdn.com/matt/archive/2009/04/14/snippet-designer-in-april-s-msdn-magazine.aspx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
