<?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>Web 2.1 &#187; jParser</title>
	<atom:link href="http://web.2point1.com/tag/jparser/feed/" rel="self" type="application/rss+xml" />
	<link>http://web.2point1.com</link>
	<description>Tim Whitlock&#039;s home in the Blogohedron</description>
	<lastBuildDate>Thu, 13 May 2010 21:26:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jParser and jTokenizer released</title>
		<link>http://web.2point1.com/2009/11/14/jparser-and-jtokenizer-released/</link>
		<comments>http://web.2point1.com/2009/11/14/jparser-and-jtokenizer-released/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 17:24:52 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jParser]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rainy day]]></category>

		<guid isPermaLink="false">http://web.2point1.com/?p=243</guid>
		<description><![CDATA[After nearly two years I&#8217;ve finally gotten around to releasing my PHP JavaScript parser, although documentation is still thin on the ground.

Download jParser 1.0.0 (recommended)

Download jParser devel package (Full source and build scripts)
See the library examples running at timwhitlock.info/jparser

The library has been split in two:

jTokenizer &#8211; A JavaScript tokenizer designed to mimic the PHP tokenizer.
jParser [...]]]></description>
			<content:encoded><![CDATA[<p>After nearly two years I&#8217;ve <em>finally</em> gotten around to releasing my PHP JavaScript parser, although documentation is still thin on the ground.</p>
<ul>
<li><strong><a href="http://web.2point1.com/wp-content/uploads/2009/11/jparser-1-0-0.tgz">Download jParser 1.0.0</a> </strong><strong>(recommended)<br />
</strong></li>
<li><a href="http://web.2point1.com/wp-content/uploads/2009/11/jparser-devel-1-0-0.tgz">Download jParser devel package</a> (Full source and build scripts)</li>
<li>See the library examples running at <a href="http://timwhitlock.info/jparser/" target="_blank">timwhitlock.info/jparser</a></li>
</ul>
<p>The library has been split in two:</p>
<ol>
<li><strong>jTokenizer</strong> &#8211; A JavaScript tokenizer designed to mimic the <a href="http://www.php.net/manual/en/book.tokenizer.php" target="_blank">PHP tokenizer</a>.</li>
<li><strong>jParser </strong>- The fully blown JavaScript syntactical parser which generates a parse tree.</li>
</ol>
<p><span id="more-243"></span>The reason for the split is that for most purposes where you think you need a parser, you in fact just need a tokenizer. The tokenizer library is about 15KB, whereas the parser is over 700KB (minified), so you can see why you might not want to include it unnecessarily.</p>
<p>The library files <code>jparser.php</code> and <code>jtokenizer.php</code> are self-contained, minified files for production use. If you wish to inspect or modify the code you will need to download the devel package. This package provides a build script which collates the libraries into their distributable files.</p>
<h3>jTokenizer</h3>
<p>Possible uses for the tokenizer include code highlighting and simple manipulation of JavaScript source code.</p>
<p>The main function you will want to use is <code>j_token_get_all</code> which behaves the same as the PHP <a href="http://www.php.net/manual/en/function.token-get-all.php" target="_blank">token_get_all</a> function with the addition of a column number as well as a line number. Additionally there is the <code>j_token_name</code> as per the PHP <a href="http://www.php.net/manual/en/function.token-name.php" target="_blank">token_name</a> function.</p>
<h3>jParser</h3>
<p>This is a full, syntactical parser. On its own it simply generates a parse tree which can be traversed and manipulated. There is no proper documentation on this yet, but take a look at the node classes in the devel package if you are serious about doing something useful with this parser.</p>
<h3>Some other notes in no particular order</h3>
<p>The full parser uses a lot of juice. I recommend giving PHP loads of memory, and be careful what you throw at it if you&#8217;re going to run it on a production server.</p>
<p>A parser is not an interpreter or a JavaScript engine. If you want to develop such a thing in PHP you might be insane, but it could be done with this parser as a base.</p>
<p>The JParser parse tree is purposefully not a full tree, it collapses redundant nodes to save memory. If you want to see a full tree then take a look at the <code>JParserRaw</code> class. (devel package required)</p>
<p>Splitting the parsing process into two parts (tokenize/parse) is probably not the most efficient and probably uses more memory than it would another way. However, I figured it would be neat to mimic the PHP tokenizer functionality so that parsers could be built that take a stream of PHP tokens.</p>
]]></content:encoded>
			<wfw:commentRss>http://web.2point1.com/2009/11/14/jparser-and-jtokenizer-released/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>jParser grammar</title>
		<link>http://web.2point1.com/2009/02/26/jparser-grammar/</link>
		<comments>http://web.2point1.com/2009/02/26/jparser-grammar/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 10:54:39 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jParser]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://web.2point1.com/2009/02/26/jparser-grammar/</guid>
		<description><![CDATA[I&#8217;ve been asked how I generate the JavaScript parse table for jParser, so I&#8217;m posting the grammar file here for anyone else who&#8217;s interested.
↓ JavaScript grammar file for jParser
 This file is in a (probably non-standard) variant of BNF notation. I&#8217;m not generating the tables with a tool like ANTLR primarily because I don&#8217;t write [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been asked how I generate the JavaScript parse table for jParser, so I&#8217;m posting the grammar file here for anyone else who&#8217;s interested.</p>
<p><a href="/wp-content/uploads/2009/03/jas.bnf" target="_blank"><strong>↓ JavaScript grammar file for jParser</strong></a></p>
<p><span id="more-100"></span> This file is in a (probably non-standard) variant of <a href="http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form" target="_blank">BNF notation</a>. I&#8217;m not generating the tables with a tool like ANTLR primarily because I don&#8217;t write C. I should also point out that I don&#8217;t come from a formalized computer science background, so don&#8217;t expect this to be 100% conventional.</p>
<p>I&#8217;ve developed a native PHP parse table generator that in turn uses a parser (based on itself) to parse this BNF grammar into a table. If you understand grammar files like this you&#8217;ll notice something a bit odd &#8211; The terminal symbols don&#8217;t go right down to individual characters, the grammar expects the source code to already have been tokenized into significant chunks, such as <code>J_NUMBER</code> representing an already identified numeric token. This was done deliberately to be compatibile with PHP&#8217;s own <a href="http://uk.php.net/manual/en/ref.tokenizer.php" target="_blank">Tokenizer functions</a>. The underlying parser framework was designed such that PHP token based grammars could also be developed.</p>
]]></content:encoded>
			<wfw:commentRss>http://web.2point1.com/2009/02/26/jparser-grammar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jParser release in the pipeline</title>
		<link>http://web.2point1.com/2009/02/24/jparser-release-in-the-pipeline/</link>
		<comments>http://web.2point1.com/2009/02/24/jparser-release-in-the-pipeline/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 23:46:41 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jParser]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://web.2point1.com/2009/02/24/jparser-release-in-the-pipeline/</guid>
		<description><![CDATA[I&#8217;ve received quite a few emails recently asking me where the code is for jParser.
I&#8217;ve had to disappoint so far, because it&#8217;s not currently available for download. My web analytics also tells me that a lot of people are finding this blog by Googling &#8220;php javascript parser&#8220;. There&#8217;s clearly a need out there, so I&#8217;d [...]]]></description>
			<content:encoded><![CDATA[<p><strong>I&#8217;ve received quite a few emails recently asking me where the code is for <a href="http://web.2point1.com/2008/05/09/full-javascript-parser-for-php/">jParser</a>.</strong></p>
<p>I&#8217;ve had to disappoint so far, because it&#8217;s not currently available for download. My web analytics also tells me that a lot of people are finding this blog by Googling &#8220;<em>php javascript parser</em>&#8220;. There&#8217;s clearly a need out there, so I&#8217;d better do something about it.</p>
<p>I know why I want a JavaScript parser, but what kind of things might you need it for? What API features/functions would you like to see? Please post a comment and let me know. Watch this space for a release, and in the mean time here&#8217;s some food for thought &#8230;</p>
<p><span id="more-98"></span></p>
<h4>Do you really need a full parser?</h4>
<p>Perhaps all you really need is a <em>tokenizer</em>. Suppose you want to <a href="http://timwhitlock.info/plug/examples/JavaScript/j_token_html.php" target="_blank">highlight JavaScript code</a> &#8211; you don&#8217;t need a full parser; all you need to do is break the source code into meaningful chunks (strings, numbers etc..) . How these chunks work together to form <em>syntax </em>is not an issue. I envisage releasing a lighter-weight library containing just the tokenizer (<em>jTokenizer </em>I guess). This will work exactly the same as the <a href="http://www.php.net/manual/en/ref.tokenizer.php" target="_blank">PHP tokenizer functions</a>.</p>
<h4>Minifying, or obfuscating JavaScript</h4>
<p>If you&#8217;re after a minifier, there are lighter-weight PHP options available. However, I&#8217;ve released a command line version of my <a href="http://web.2point1.com/2008/09/07/jsfmt-and-jsobf-available-for-download/" target="_blank">JavaScript minifier and obfuscator</a> which is quite handy. It&#8217;s more powerful than most JavaScript minifiers, because it supports <a href="http://web.2point1.com/2008/06/01/jparser-now-with-automatic-semicolon-insertion/">automatic semicolon insertion</a>. This means it can reduce any code to a single line.</p>
]]></content:encoded>
			<wfw:commentRss>http://web.2point1.com/2009/02/24/jparser-release-in-the-pipeline/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
