4
4

More than 5 years have passed since last update.

【個人メモ】CoffeeScriptのinitial commitの環境を動かしてみる

Last updated at Posted at 2014-07-21

CoffeeScriptの一番始めのコミットの状態を再現

できるのかな、と思ったのでやってみる。

CoffeeScriptのinitial commitの状態

2009年が初回コミットの状態とのこと。
だいぶ昔だな。

Rubyのバージョンは2.1.2で試している。
bundlerはインストール済み。

作業の流れ

initial commitの状態に戻す

リポジトリをcloneして、initial commitの状態に戻す。

> git clone git@github.com:jashkenas/coffeescript.git
> cd coffeescript
> git checkout -b initial-commit 8e9d637985d2dc9b44922076ad54ffef7fa8e9c2

当時のソースを修正する

grammer.yのrequireを変更する。

diff --git a/grammar.y b/grammar.y
index 580ca76..1c3e09b 100644
--- a/grammar.y
+++ b/grammar.y
@@ -190,8 +190,8 @@ rule
 end

 ---- header
-  require "lexer"
-  require "nodes"
+  require "./lexer"
+  require "./nodes"

parser_test.rbのrequireを変更する

diff --git a/parser_test.rb b/parser_test.rb
index c383224..8880b1a 100644
--- a/parser_test.rb
+++ b/parser_test.rb
@@ -3,7 +3,7 @@
 `racc -o parser.rb grammar.y`

 # Parse and print "code.jaa".
-require "parser.rb"
+require "./parser"
 js = Parser.new.parse(File.read('code.jaa')).compile
 puts "\n\n"
 puts js

Gemfileを追加する

raccというツールを使って構文解析を行っている。
インストールをするために、Gemfileを追加する。

Gemfile
source 'https://rubygems.org/'

gem 'racc'

bundle installを行う

> bundle ins --path vendor/bundle

parser_test.rbを実行する

> bundle ex ruby parser_test.rb

parser_test.rbはcode.jaaの中身をパースしている

code.jaaの中身

これがいっちばん最初のCoffeeScript

# I'm a comment and I'm ok.
# Return
# Case

square: x => x * x.

sum: x, y => x + y.

odd: x => x % 2 is 0.

even: x => x % 2 aint 0.

object_literal: {one: 1, two: 2, three: 3}

multiline_object: {
  pi: 3.14159
  list: [1, 2, 3, 4]
  three: 3
  inner_obj: {
    freedom: => _.freedom().
  }
}

run_loop: =>
  fire_events(e => e.stopPropagation().)
  listen()
  wait().

if submarine.shields_up
  full_speed_ahead()
  weapons.fire_torpedos()
else
  run_away().

eldest: if 25 > 21 then liz else marge.

code.jaaをコンパイルした結果

parse_test.rbを実行した結果。

var square = function(x) {
  return (x * x);
};
var sum = function(x, y) {
  return (x + y);
};
var odd = function(x) {
  return ((x % 2) === 0);
};
var even = function(x) {
  return ((x % 2) !== 0);
};
var object_literal = {                                                
  one: 1,
  two: 2,
  three: 3
};
var multiline_object = {
  pi: 3.14159,
  list: [1, 2, 3, 4],
  three: 3,
  inner_obj: {
    freedom: function() {
      return _.freedom();
    }
  }
};
var run_loop = function() {
  fire_events(function(e) {
    return e.stopPropagation();
  });
  listen();
  return wait();
};
if (submarine.shields_up) {
  full_speed_ahead();
  weapons.fire_torpedos();
} else {
  run_away();
}
var eldest = (25 > 21) ? liz : marge;

所感

5年前のコードがちょこっとの修正で
Ruby 2.1.2の環境で動くの、とても良い。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4