<?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>My stuff &#187; Books</title>
	<atom:link href="http://michelhollands.net/blog/index.php/category/books/feed/" rel="self" type="application/rss+xml" />
	<link>http://michelhollands.net/blog</link>
	<description>Tech and travel tidbits</description>
	<lastBuildDate>Tue, 13 Dec 2011 09:59:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Using pyparsing</title>
		<link>http://michelhollands.net/blog/2007/10/24/using-pyparsing/</link>
		<comments>http://michelhollands.net/blog/2007/10/24/using-pyparsing/#comments</comments>
		<pubDate>Wed, 24 Oct 2007 14:37:10 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://michelhollands.net/blog/2007/10/24/using-pyparsing/</guid>
		<description><![CDATA[The day after I hyped the Getting Started with PyParsing book, I got to use it. Here&#8217;s the script : from pyparsing import SkipTo, Suppress, CaselessLiteral import glob &#160; # Example to match # delete from TABLENAME # where CUSTOMER_ID = 'INTERNAL'; &#160; table_name = SkipTo&#40;&#34;where&#34;&#41; where_clause = SkipTo&#40;';'&#41; &#160; delete_stmt = Suppress&#40;&#34;delete&#34;&#41; + Suppress&#40;&#34;from&#34;&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>The day after I hyped the <a href="http://www.oreilly.com/catalog/9780596514235/?CMP=ILC-2RQ886833906&#038;ATT=9780596514235">Getting Started with PyParsing</a> book, I got to use it. Here&#8217;s the script :</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">  <span style="color: #ff7700;font-weight:bold;">from</span> pyparsing <span style="color: #ff7700;font-weight:bold;">import</span> SkipTo, Suppress, CaselessLiteral
  <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">glob</span>
&nbsp;
  <span style="color: #808080; font-style: italic;"># Example to match</span>
  <span style="color: #808080; font-style: italic;"># delete from TABLENAME</span>
  <span style="color: #808080; font-style: italic;"># where       CUSTOMER_ID = 'INTERNAL';</span>
&nbsp;
  table_name = SkipTo<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;where&quot;</span><span style="color: black;">&#41;</span>
  where_clause = SkipTo<span style="color: black;">&#40;</span><span style="color: #483d8b;">';'</span><span style="color: black;">&#41;</span>
&nbsp;
  delete_stmt = Suppress<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;delete&quot;</span><span style="color: black;">&#41;</span> +  Suppress<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;from&quot;</span><span style="color: black;">&#41;</span> + table_name
     + Suppress<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;where&quot;</span><span style="color: black;">&#41;</span> + where_clause + Suppress<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;;&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">for</span> filename <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">glob</span>.<span style="color: #dc143c;">glob</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'*.sql'</span><span style="color: black;">&#41;</span>:
      f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'-- '</span>, filename, <span style="color: #483d8b;">':'</span>
      lines=f.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">for</span> tokens, start,end <span style="color: #ff7700;font-weight:bold;">in</span> delete_stmt.<span style="color: black;">scanString</span><span style="color: black;">&#40;</span>lines<span style="color: black;">&#41;</span>:
          <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'select * from '</span> + tokens<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> + <span style="color: #483d8b;">' where '</span> + tokens<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> + <span style="color: #483d8b;">';'</span>
      f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>This loops over all the files called *.sql in the current directory. Then it checks if there are any matches to the delete_stmt variable. So it has to match the literal &#8220;delete&#8221; and then the literal &#8220;from&#8221;. These are not put in the output, because they are in a Suppress() object.</p>
<p>After that we select everything up to &#8216;where&#8217; as the table_name. Then the literal &#8220;where&#8221; has to be present. Everything up to the semicolon is then read into the where_clause variable.</p>
<p>Lastly the table name and where clause are used to create a select statement.</p>
<p>PS : The code was changed so that this</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">  <span style="color: #ff7700;font-weight:bold;">from</span> pyparsing <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span></pre></div></div>

<p>became :</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">  <span style="color: #ff7700;font-weight:bold;">from</span> pyparsing <span style="color: #ff7700;font-weight:bold;">import</span> SkipTo, Suppress, CaselessLiteral</pre></div></div>

<p>This way we don&#8217;t pollute the current namespace.</p>
]]></content:encoded>
			<wfw:commentRss>http://michelhollands.net/blog/2007/10/24/using-pyparsing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyParsing</title>
		<link>http://michelhollands.net/blog/2007/10/22/pyparsing/</link>
		<comments>http://michelhollands.net/blog/2007/10/22/pyparsing/#comments</comments>
		<pubDate>Mon, 22 Oct 2007 16:51:53 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://michelhollands.net/blog/2007/10/22/pyparsing/</guid>
		<description><![CDATA[I just bought and read the Getting Started with Pyparsing PDF book. And it&#8217;s good. PyParsing is a way of building a parser using Python code. You should think Yacc/Lex, but readable. It can be used to parse text, and it can also handle HTML. This is the example from the PyParsing website : from [...]]]></description>
			<content:encoded><![CDATA[<p>I just bought and read the <a href="http://www.oreilly.com/catalog/9780596514235/?CMP=ILC-2RQ886833906&#038;ATT=9780596514235">Getting Started with Pyparsing</a> PDF book. And it&#8217;s good. <a href="http://pyparsing.wikispaces.com/">PyParsing</a> is a way of building a parser using Python code. You should think Yacc/Lex, but readable. It can be used to parse text, and it can also handle HTML.</p>
<p>This is the example from the <a href="http://pyparsing.wikispaces.com/">PyParsing website</a> :</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">  <span style="color: #ff7700;font-weight:bold;">from</span> pyparsing <span style="color: #ff7700;font-weight:bold;">import</span> Word, alphas
  greet = Word<span style="color: black;">&#40;</span> alphas <span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;,&quot;</span> + Word<span style="color: black;">&#40;</span> alphas <span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;!&quot;</span> <span style="color: #808080; font-style: italic;"># &lt;-- grammar defined here</span>
  hello = <span style="color: #483d8b;">&quot;Hello, World!&quot;</span>
  <span style="color: #ff7700;font-weight:bold;">print</span> hello, <span style="color: #483d8b;">&quot;-&gt;&quot;</span>, greet.<span style="color: black;">parseString</span><span style="color: black;">&#40;</span> hello <span style="color: black;">&#41;</span></pre></div></div>

<p><a href="http://www.onlamp.com">OnLamp.com</a> had a good article called <a href="http://www.onlamp.com/pub/a/python/2006/01/26/pyparsing.html">Building Recursive Descent Parsers with Python</a>, which is a good starting point. But the book is better.</p>
]]></content:encoded>
			<wfw:commentRss>http://michelhollands.net/blog/2007/10/22/pyparsing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Books</title>
		<link>http://michelhollands.net/blog/2007/10/19/books/</link>
		<comments>http://michelhollands.net/blog/2007/10/19/books/#comments</comments>
		<pubDate>Fri, 19 Oct 2007 09:00:19 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Books]]></category>

		<guid isPermaLink="false">http://michelhollands.net/blog/2007/10/19/books/</guid>
		<description><![CDATA[This is a book I want to read : The &#8216;Finding things&#8217; chapter, written by Tim Bray, was on the O&#8217;Reilly site before, but seems to have gone.]]></description>
			<content:encoded><![CDATA[<p>This is a book I want to read :</p>
<p><center><br />
<iframe src="http://rcm-uk.amazon.co.uk/e/cm?t=wwwmichelholl-21&#038;o=2&#038;p=8&#038;l=as1&#038;asins=0596510047&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe><br />
</center></p>
<p>The &#8216;Finding things&#8217; chapter, written by <a href="http://www.tbray.org/ongoing/">Tim Bray</a>, was on the <a href="http://oreilly.com">O&#8217;Reilly site</a> before, but seems to have gone.</p>
]]></content:encoded>
			<wfw:commentRss>http://michelhollands.net/blog/2007/10/19/books/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.562 seconds -->

