<?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>Notes Log &#187; programming</title>
	<atom:link href="http://noteslog.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://noteslog.com</link>
	<description></description>
	<lastBuildDate>Tue, 15 May 2012 18:39:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Chili 2.2 Released Today</title>
		<link>http://noteslog.com/post/chili-22-released-today/</link>
		<comments>http://noteslog.com/post/chili-22-released-today/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 20:07:58 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Chili]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[highlight]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=217</guid>
		<description><![CDATA[Changes Added support for local line numbers plain starting from an offset automatically segmented Improved the PHP recipe for defaulting to PHP instead of HTML when no &#60;? is found Links download start page]]></description>
			<content:encoded><![CDATA[<h4>Changes</h4>
<ul>
<li>Added support for local line numbers
<ul>
<li>plain</li>
<li>starting from an offset</li>
<li>automatically segmented</li>
</ul>
</li>
<li>Improved the PHP recipe for defaulting to PHP instead of HTML when no &lt;? is found</li>
</ul>
<h4>Links</h4>
<ul>
<li><a href="http://code.google.com/p/jquery-chili-js/downloads/list">download</a></li>
<li><a href="http://noteslog.com/personal/projects/chili/" target="_blank">start page</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/chili-22-released-today/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Chili 2.1 Released Today</title>
		<link>http://noteslog.com/post/chili-21-released-today/</link>
		<comments>http://noteslog.com/post/chili-21-released-today/#comments</comments>
		<pubDate>Sun, 29 Jun 2008 16:39:29 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Chili]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[highlight]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=215</guid>
		<description><![CDATA[UPDATE: Chili 2.2 has been released Changes Added support for line numbers (boolean option: lineNumbers) Added a selection helper for Internet Explorer and Mozilla Improved the PHP recipe for working fine with Safari too Improved crossbrowser support Links download start page]]></description>
			<content:encoded><![CDATA[<h4><span><span style="color: #ff0000;"><strong>UPDATE</strong>: <a href="http://noteslog.com/post/chili-22-released-today" target="_self">Chili 2.2</a> has been released</span></span></h4>
<h4>Changes</h4>
<ul>
<li>Added support for line numbers (boolean option: lineNumbers)</li>
<li>Added a selection helper for Internet Explorer and Mozilla</li>
<li>Improved the PHP recipe for working fine with Safari too</li>
<li>Improved crossbrowser support</li>
</ul>
<h4>Links</h4>
<ul>
<li><a href="http://code.google.com/p/jquery-chili-js/downloads/list">download</a></li>
<li><a href="http://noteslog.com/personal/projects/chili/" target="_blank">start page</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/chili-21-released-today/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Chili 2.0 Released Today</title>
		<link>http://noteslog.com/post/chili-20-released-today/</link>
		<comments>http://noteslog.com/post/chili-20-released-today/#comments</comments>
		<pubDate>Tue, 13 May 2008 21:40:14 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Chili]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[highlight]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=207</guid>
		<description><![CDATA[UPDATE: Chili 2.1 has been released Changes added support for a much better recipe format optimized regular expressions for speed moved project hosting to Google Code: jquery-chili-js removed support for the previous recipe format removed support for metaobjects removed support for nearly obsolete features Links download start page A new recipe format Chili 2.0 supports [...]]]></description>
			<content:encoded><![CDATA[<h4><span style="color: #ff0000;"><strong>UPDATE</strong>: <a href="http://noteslog.com/post/chili-21-released-today" target="_self">Chili 2.1</a> has been released</span></h4>
<h4>Changes</h4>
<ul>
<li>added support for a much better recipe format</li>
<li>optimized regular expressions for speed</li>
<li>moved project hosting to Google Code: <a href="http://code.google.com/p/jquery-chili-js/" target="_blank">jquery-chili-js</a></li>
<li>removed support for the previous recipe format</li>
<li>removed support for metaobjects</li>
<li>removed support for nearly obsolete features<br />
<a href="http://code.google.com/p/jquery-chili-js/" target="_blank"></a></li>
</ul>
<h4>Links</h4>
<ul>
<li><a href="http://code.google.com/p/jquery-chili-js/downloads/list">download</a></li>
<li><a href="http://noteslog.com/personal/projects/chili/" target="_blank">start page</a></li>
</ul>
<h4>A new recipe format</h4>
<p>Chili 2.0 supports a new recipe format which is a bit more structured than the old one and will make hard-to-highlight languages a thing of the past. BTW, old recipes won&#8217;t be accepted by Chili 2.0. (although a simple manual conversion is possible)</p>
<h5>How to convert old recipes to the new format</h5>
<p>First of all let&#8217;s see an example of how to convert a recipe in the old format to the new one.</p>
<p>What follows is a piece of recipe (for JavaScript) in the old format</p>
<p><pre><code class="javascript">{
	  ignoreCase: false
	, steps: {
		  ml_comment: { 
			exp: /\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\//
		}
		, sl_comment: { 
			exp: /\/\/.*/
		}
		//...
	}
}</code></pre></p>
<p>And here is the same piece in the new format</p>
<p><pre><code class="javascript">{
	  _name: 'js'
	, _case: true
	, _main: {
		  ml_comment: { 
			  _match: /\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\//
			, _style: 'color: gray;'
		}
		, sl_comment: { 
			  _match: /\/\/.*/
			, _style: 'color: green;'
		}
		//...
	}
}</code></pre></p>
<p>As you see, they are very similar. Here are all the differences:</p>
<ol>
<li>property names beginning with an underscore are reserved words</li>
<li><span style="color: #333399;">_name</span> didn&#8217;t exist before</li>
<li><span style="color: #333399;">_case</span> replaces the old <span style="color: #333399;">ignoreCase<span style="color: #000000;">; <span style="color: #333399;">_case</span> is TRUE if the language is case sensitive, and FALSE otherwise; <span style="color: #333399;">_case</span> defaults to FALSE</span></span></li>
<li><span style="color: #333399;"><span style="color: #000000;"><span style="color: #333399;">_main</span> replaces the old <span style="color: #333399;">steps</span></span></span></li>
<li><span style="color: #333399;"><span style="color: #000000;"><span style="color: #333399;"><span style="color: #000000;"><span style="color: #333399;">_match</span> replaces the old <span style="color: #333399;">exp</span></span></span></span></span></li>
<li><span style="color: #333399;"><span style="color: #000000;"><span style="color: #333399;"><span style="color: #000000;"><span style="color: #333399;">_style</span> didn&#8217;t exist before</span></span></span></span></li>
</ol>
<p><span style="color: #333399;">_style</span> makes a big difference with respect to the past: CSS styles can now be embedded into the recipe. Separate stylesheets are no longer supported by the autoloading engine, but you can load them by yourself, if you prefer to keep them apart.</p>
<p>Another important difference about CSS is that now Chili builds the class associated to a step, by prefixing the <span style="color: #333399;">_name</span> to the step name, separated by <span style="color: #333399;">__</span> (a double underscore). So, for example, the class for the multiline comment will be <span style="color: #333399;">js__ml_comment</span>.</p>
<h4>More expressive power with the new recipe format</h4>
<p>Besides the minor changes described in the previous section, the new format is much more powerful thanks to the major improvement I&#8217;m going to describe here.</p>
<p>The old recipe format supported an optional <span style="color: #333399;">replacement</span> property of a step, by means of which you could customize how the highlighting was applied to the matched text. Such a feature was useful when you captured subexpressions and wanted to highlight them separately.</p>
<p><span style="color: #333399;"><span style="color: #000000;">Now </span>_replace</span> replaces <span style="color: #333399;">replacement</span> (sic) and it&#8217;s still optional.</p>
<p>As before, if you don&#8217;t specify a <span style="color: #333399;">_replace</span> property, Chili will default to <span style="color: #333399;">&lt;span class=&#8221;$0&#8243;&gt;$$&lt;/span&gt;</span>, where <span style="color: #333399;">$0</span> and <span style="color: #333399;">$$</span> refer to the name of the current step and the matched text respectively.</p>
<p>As before, <span style="color: #333399;">_replace</span> can also be a different string expression, like in the following step, extracted from the MySQL recipe</p>
<p><pre><code class="javascript">variable: { 
	  _match: /@([$.\w]+|([`\&quot;\'])(?:(?:[^\2\\\r\n]*?(?:\2\2|\\.))*[^\2\\\r\n]*?)\2)/
	, _replace: '&lt;span class=&quot;keyword&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;variable&quot;&gt;$1&lt;/span&gt;'
	, _style: { keyword: 'color: navy;', variable: 'color: blue;' }
}</code></pre></p>
<p>What to note in the above example:</p>
<ol>
<li>you can specify a style for each of the involved classes, by using properties of an object</li>
<li>you must use a span for applying style to a text run</li>
</ol>
<h5>A big improvement</h5>
<p>In Chili 2.0, <strong><span style="color: #333399;">_replace</span> can also be a function</strong>, like in the following step, extracted from the new HTML recipe</p>
<p><pre><code class="javascript">// matches a starting tag of an element (with attrs)
// like &quot;&lt;div ... &gt;&quot; or &quot;&lt;img ... /&gt;&quot;
, tag_start: { 
	  _match: /(&lt;\w+)((?:\w|[?%]&gt;|\W)*?)(\/&gt;|&gt;)/ 
	, _replace: function( all, open, content, close ) { 
		  return &quot;&lt;span class='tag_start'&gt;&quot; + this.x( open ) + &quot;&lt;/span&gt;&quot; 
			  + this.x( content, '/tag_attrs' ) 
			  + &quot;&lt;span class='tag_start'&gt;&quot; + this.x( close ) + &quot;&lt;/span&gt;&quot;;
	}
	, _style: &quot;color: navy; font-weight: bold;&quot;
}</code></pre></p>
<p>What to note in the above example:</p>
<ol>
<li><span style="color: #333399;"><span style="color: #000000;">when </span>_replace</span> is a function, it receives match and submatches as arguments, and inside</li>
<li>there is a valid <span style="color: #333399;">this</span> object which contains a magic <span style="color: #333399;">x</span> method, by which</li>
<li>a string can be escaped for HTML (like <span style="color: #333399;">open</span> and <span style="color: #333399;">close</span>), or</li>
<li>a string can be transformed by an expression (like <span style="color: #333399;">content</span>)</li>
</ol>
<h4>Chili 2.0 recipes are modular</h4>
<p>A Chili 2.0 recipe contains blocks (like <span style="color: #333399;">_main</span>), which contain steps (like <span style="color: #333399;">tag_start</span>). An expression can be built for referencing each module, be it a recipe, a block, or a step. For example, <span style="color: #333399;">/tag_attrs</span> is the <span style="color: #333399;">tag_attrs</span> block in the current recipe.</p>
<h5>One method to highlight them all</h5>
<p>The JavaScript code inside a <span style="color: #333399;">_replace</span> function can use the <span style="color: #333399;">x</span> method of <span style="color: #333399;">this</span>.</p>
<p><span style="color: #333399;">x</span> takes two arguments: a subject to process, and an optional module to use.</p>
<p><span style="color: #333399;">x</span> returns the subject escaped for HTML if no module is given, or the module is not available, else it returns the result of applying the module to the subject using Chili 2.0.</p>
<p>If the ChiliBook option <span style="color: #333399;">recipeLoading</span> is true, any unavailable module will be automatically loaded.</p>
<h5>The new HTML recipe</h5>
<p>As an example, here is the new HTML recipe</p>
<p><pre><code class="javascript">{
	  _name: 'html'
	, _case: false
	, _main: {
		  doctype: { 
			  _match: /&lt;!DOCTYPE\b(?:\w|\W)*?&gt;/ 
			, _style: &quot;color: #CC6600;&quot;
		}
		, ie_style: {
			  _match: /(&lt;!--\[[^\]]*\]&gt;)((?:\w|\W)*?)(&lt;!\[[^\]]*\]--&gt;)/
			, _replace: function( all, open, content, close ) {
				return &quot;&lt;span class='ie_style'&gt;&quot; + this.x( open ) + &quot;&lt;/span&gt;&quot; 
					  + this.x( content, '//style' ) 
					  + &quot;&lt;span class='ie_style'&gt;&quot; + this.x( close ) + &quot;&lt;/span&gt;&quot;;
			}
			, _style: &quot;color: DarkSlateGray; font-weight: bold;&quot;
		}
		, comment: { 
			  _match: /&lt;!--(?:\w|\W)*?--&gt;/ 
			, _style: &quot;color: #4040c2;&quot;
		}
		, script: { 
			  _match: /(&lt;script\s+[^&gt;]*&gt;)((?:\w|\W)*?)(&lt;\/script\s*&gt;)/
			, _replace: function( all, open, content, close ) { 
				  return this.x( open, '//tag_start' ) 
					  + this.x( content, 'js' ) 
					  + this.x( close, '//tag_end' );
			} 
		}
		, style: { 
			  _match: /(&lt;style\s+[^&gt;]*&gt;)((?:\w|\W)*?)(&lt;\/style\s*&gt;)/
			, _replace: function( all, open, content, close ) { 
				  return this.x( open, '//tag_start' ) 
					  + this.x( content, 'css' ) 
					  + this.x( close, '//tag_end' );
			} 
		}
		// matches a starting tag of an element (with attrs)
		// like &quot;&lt;div ... &gt;&quot; or &quot;&lt;img ... /&gt;&quot;
		, tag_start: { 
			  _match: /(&lt;\w+)((?:\w|[?%]&gt;|\W)*?)(\/&gt;|&gt;)/ 
			, _replace: function( all, open, content, close ) { 
				  return &quot;&lt;span class='tag_start'&gt;&quot; + this.x( open ) + &quot;&lt;/span&gt;&quot; 
					  + this.x( content, '/tag_attrs' ) 
					  + &quot;&lt;span class='tag_start'&gt;&quot; + this.x( close ) + &quot;&lt;/span&gt;&quot;;
			}
			, _style: &quot;color: navy; font-weight: bold;&quot;
		} 
		// matches an ending tag
		// like &quot;&lt;/div&gt;&quot;
		, tag_end: { 
			  _match: /&lt;\/\w+\s*&gt;|\/&gt;/ 
			, _style: &quot;color: navy;&quot;
		}
		, entity: { 
			  _match: /&amp;\w+?;/ 
			, _style: &quot;color: blue;&quot;
		}
	}
	, tag_attrs: {
		// matches a name/value pair
		attr: {
			// before in $1, name in $2, between in $3, value in $4
			  _match: /(\W*?)([\w-]+)(\s*=\s*)((?:\'[^\']*(?:\\.[^\']*)*\')|(?:\&quot;[^\&quot;]*(?:\\.[^\&quot;]*)*\&quot;))/ 
			, _replace: &quot;$1&lt;span class='attr_name'&gt;$2&lt;/span&gt;$3&lt;span class='attr_value'&gt;$4&lt;/span&gt;&quot;
			, _style: { attr_name:  &quot;color: green;&quot;, attr_value: &quot;color: maroon;&quot; }
		}
	}
}</code></pre></p>
<p>What to note in the above example:</p>
<ol>
<li>a <span style="color: #333399;">_replace</span> function can be used for applying a recipe to a text run inside another recipe, like the <span style="color: #333399;">script</span> an <span style="color: #333399;">style</span> steps, where highlighting of script and style elements is delegated to <span style="color: #333399;">js</span> and <span style="color: #333399;">css</span> recipes respectively</li>
<li>a <span style="color: #333399;">_replace</span> function can be used for isolating the parsing of a text run, like the <span style="color: #333399;">tag_attrs</span> step, where highlighting of name/value pairs happens only in the context of tag attributes</li>
</ol>
<h5>Module paths</h5>
<p>A module path is an expression that identifies a Chili 2.0 module. A path has three components (though some can be hidden) separated by a / (forward slash), each with a specific meaning: recipe / block / step. (white space added for clarity)</p>
<p>Here is a list of all the combinations in a module path:</p>
<ul>
<li>recipe<br />
a module path like <strong><span style="color: #333399;">css</span></strong> refers to the entire <span style="color: #333399;">css</span> recipe</li>
<li>recipe / block<br />
a module path like <strong><span style="color: #333399;">css/definition</span></strong> refers to the <span style="color: #333399;">definition</span> block of the <span style="color: #333399;">css</span> recipe</li>
<li>recipe / block / step<br />
a module path like <strong><span style="color: #333399;">css/definition/property</span></strong> refers to the <span style="color: #333399;">property</span> step of the <span style="color: #333399;">definition</span> block of the <span style="color: #333399;">css</span> recipe</li>
<li>/ block<br />
a module path like <strong><span style="color: #333399;">/definition</span></strong> refers to the <span style="color: #333399;">definition</span> block of the current recipe</li>
<li>/ block / step<br />
a module path like <strong><span style="color: #333399;">/definition/property</span></strong> refers to the <span style="color: #333399;">property</span> step of the <span style="color: #333399;">definition</span> block of the current recipe</li>
<li>/ / step<br />
a module path like <strong><span style="color: #333399;">//property</span></strong> refers to the <span style="color: #333399;">property</span> step of the current block of the current recipe</li>
</ul>
<p>As you see, leading slashes have a meaning.</p>
<h5>Remember</h5>
<ul>
<li>a recipe module invocation tries to match all the steps of the _main block</li>
<li>a block module invocation tries to match all its steps</li>
<li>a step module invocation tries to match just itself</li>
</ul>
<h4>Help request</h4>
<p>I think that Chili 2.0 is pretty good at highlighting, but it needs more fine recipes to succeed. For this release I&#8217;ve rewritten some from scratch, and converted some others. I&#8217;m not a good programmer in languages other than the ones for which I rewrote a recipe. But if you are and have time and will, then you could write a Chili 2.0 recipe for your favorite language, together with a couple of working samples, and send all to me. I&#8217;d be very happy to add your contributed recipes to the project as soon as they are available.</p>
<h5>Rewritten</h5>
<ul>
<li>CSS</li>
<li>HTML</li>
<li>JavaScript</li>
<li>PHP</li>
</ul>
<h5>Converted</h5>
<ul>
<li>C++</li>
<li>C#</li>
<li>Delphi</li>
<li>Java</li>
<li>LotusScript</li>
<li>MySQL</li>
</ul>
<h4>Setup and Examples</h4>
<p>Here is the <a href="http://noteslog.com/personal/projects/chili/2.0/" target="_blank">start page for Chili 2.0</a> where you&#8217;ll find setup instructions and some examples.</p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/chili-20-released-today/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

