Parsing Javascript Parser 6

Posted by Aaron Patterson on December 24, 2007

I’ve been working hard on RKelly lately. RKelly is a ruby implementation of Kelly. Kelly is a fictional project that I made up so that I could name my project RKelly. Anyway, RKelly is a javascript parser, and will be an interpreter someday. Today I was able to get RKelly to parse and produce a parse tree of prototype.js. I couldn’t get GraphViz to export the file, but you can download the dot file here.

Here is a parse tree of a function that calculates the fibonacci sequence:
fibonacci parse tree

Here is the javascript code:

function f(n) {
  var s = 0;
  if(n == 0) return(s);
  if(n == 1) {
    s += 1;
    return(s);
  } else {
    return(f(n - 1) + f(n - 2));
  }
}

And the ruby code that produced that graph:

require 'rkelly'

parser = RKelly::Parser.new
puts parser.parse(File.read(ARGV[0])).to_dots

I need a new computer….. It took 2 minutes to render the prototype graph! Ugh!

Road to Mechanize 0.7.0 4

Posted by Aaron Patterson on December 09, 2007

I’ve been refactoring Mechanize for an 0.7.0 release. Basically I’m trying to clean the code up and there are a few features that I think are unnecessary, but I would like to ask people first.

  1. REXML as a parser.
  2. I want to remove support for REXML. I don’t use it. Hpricot seems to do everything I need.

  3. 1.8.2 thru 1.8.4 support
  4. I’ve got a bunch of monkey patches for 1.8.2 thru 1.8.4. I’d like to remove these because I think most people are on 1.8.5 or up.

  5. WWW::Mechanize::Page#watch_for_set
  6. I am going to remove this method. It made sense when REXML was the main parser, since REXML was so slow. I think that Hpricot is fast enough that this method is not so useful.

I’m going to make 0.7.0 lazily build up form and link objects, which should give everyone a slight speed increase but makes watch_for_set obsolete (sort of).

I’m changing around the class names to be better organized, but they should all have the same methods. Also, if there are any feature requests, let me know!

Birthdays, and Congrats

Posted by Aaron Patterson on December 07, 2007

I need to post something because it seems like I’m only posting release announcements to my blog……

Today is my sister’s birthday, so I woke her up at 8 this morning to wish her a happy birthday. I wanted to make sure that I was the first person to congratulate her on her special day. Is it OK to say “congratulations” for a birthday? I know Pam doesn’t like to throw around that word without some sort of accomplishment occurring. For example, getting engaged. Should you really congratulate someone on getting engaged since they just made a decision? They didn’t really overcome any obstacles or adversity, they just decided to get married. Anyway, I think that surviving another year is worth congratulating someone.

We will be rollerskating for my birthday, and Pam sent out an evite with this image:

今週日本語のクラスで私とパムさんは「何々つもりだ」と「何々なる」を習いました。私は「パムは茸が好きになる」と言っていました。でも、パムさんは意地悪になりました。Oh well.

csspool version 0.2.4 has been released!

Posted by Aaron Patterson on December 06, 2007

CSSpool (pronounced “cesspool”) is a validating SAC parser for CSS. The parser
calls methods on a document handler depending on what it has found. CSSPool
currently only supports CSS 2.1. CSSPool will not yield invalid properties or
selectors.

Changes:

## 0.2.4

* Fixed error handling on at rules. Thanks Dan for tests!
* Made specificity an array
* Made StyleSheet::Rule comparable on specificity

*

csspool version 0.2.3 has been released!

Posted by Aaron Patterson on December 05, 2007

CSSpool (pronounced “cesspool”) is a validating SAC parser for CSS. The parser
calls methods on a document handler depending on what it has found. CSSPool
currently only supports CSS 2.1. CSSPool will not yield invalid properties or
selectors.

Changes:

## 0.2.3

* Fixed a bug where nil selectors on conditional selectors were being visited.

*

csspool version 0.2.2 has been released!

Posted by Aaron Patterson on December 04, 2007

CSSpool (pronounced “cesspool”) is a validating SAC parser for CSS. The parser
calls methods on a document handler depending on what it has found. CSSPool
currently only supports CSS 2.1. CSSPool will not yield invalid properties or
selectors.

Changes:

## 0.2.2

* I suck.

*

mechanize version 0.6.11 has been released!

Posted by Aaron Patterson on December 04, 2007

The Mechanize library is used for automating interaction with websites.
Mechanize automatically stores and sends cookies, follows redirects,
can follow links, and submit forms. Form fields can be populated and
submitted. Mechanize also keeps track of the sites that you have visited as
a history.

Changes:

# Mechanize CHANGELOG

## 0.6.11

* Detecting single quotes in meta redirects.
* Adding pretty inspect for ruby versions > 1.8.4 (Thanks Joel Kociolek)

http://rubyforge.org/tracker/index.php?func=detail&aid=13150&group_id=1453&atid=5709

* Fixed bug with file name in multipart posts

http://rubyforge.org/tracker/?func=detail&aid=15594&group_id=1453&atid=5709

* Posting forms relative to the originating page. Thanks Mortee.
* Added a FAQ

http://rubyforge.org/tracker/?func=detail&aid=15772&group_id=1453&atid=5709

*

Nerd Meeting 1

Posted by Aaron Patterson on December 03, 2007

I was put in charge of nerd meeting this week.

So, I made a special terminal theme for this week. You can get it here.

CSSPoolのドキュメンテーション

Posted by Aaron Patterson on December 01, 2007

日本語を練習していました。日本語のドキュメンテーションにCSSPoolを書くと思います。でも、日本語を書くのは難しで私は遅い!www!

csspool version 0.2.1 has been released! 3

Posted by Aaron Patterson on December 01, 2007

CSSpool (pronounced “cesspool”) is a validating SAC parser for CSS. The parser
calls methods on a document handler depending on what it has found. CSSPool
currently only supports CSS 2.1. CSSPool will not yield invalid properties or
selectors.

Changes:

## 0.2.1

* Recovering from unexpected tokens in the properties section.

*