[
  {
    "path": ".gitignore",
    "content": "*.rbc\n*.gem\n.bundle\nGemfile.lock\npkg/*\n"
  },
  {
    "path": "Gemfile",
    "content": "source \"http://rubygems.org\"\n\ngemspec\n\ngem \"rake\",   \">= 0.8.7\"\ngem \"kpeg\",   \"~> 0.8.2\"\ngem \"mspec\",  \"~> 1.5.17\"\n"
  },
  {
    "path": "LICENSE",
    "content": "Copyright (c) 2011 Brian Ford. All rights reserved.\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README",
    "content": "1. What is Poetics?\n\nA native implementation of CoffeeScript [1] that runs on the Rubinius VM [2].\n\n  Q. Whence comes the name Poetics?\n\n  A. Poetics is a partial anagram of the word CoffeeScript. It is also a nod\n     to Jeremy Ashkenas, the author of CoffeeScript, and his interest in code\n     as literature.\n\n  Q. Why a native implementation?\n\n  A. CoffeeScript is an interesting language in its own right. Rather than\n     merely being a syntax layer on top of Javascript, and bound to expressing\n     its semantics in those of Javascript, it deserves its own implementation.\n     Many of the reasons to use CoffeeScript in Node.js would also apply to\n     using this native implementation.\n\n\n2. License\n\nPoetics is MIT licensed. See the LICENSE file.\n\n\n3. Installation\n\nFirst, install Rubinius:\n\n  1. Using RVM (http://rvm.beginrescueend.com).\n\n    rvm install rbx\n\n  2. Or directly (http://rubini.us/doc/en/what-is-rubinius/).\n\nSecond, install Poetics:\n\n    rbx -S gem install poetics\n\n\n4. Running Poetics\n\nPoetics provides a REPL for exploratory programming or runs CoffeeScript\nscripts.\n\n    rbx -S poetics -h\n\nThe REPL presently just parses code and returns an S-Expression\nrepresentation:\n\n    $ rbx -S poetics\n    > 42\n    [:number, 42.0, 1, 1]\n    > \"hello, y'all\"\n    [:string, \"hello, y'all\", 1, 1]\n    >\n\nTo exit the REPL hit CTRL + d.\n\n\n5. Getting Help\n\nPoetics is a work in progress. If you encounter trouble, please file an issue\nat https://github.com/brixen/poetics/issues\n\n\n6. Contributing\n\nIf you find Poetics interesting and would like to help out, fork the project\non Github and submit a pull request.\n\n\n7. People\n\nPoetics was created by Brian Ford (brixen) to force him to really learn\nJavascript and CoffeeScript.\n\n<add your name here>\n\n\n8. Credits\n\nJeremy has created an very interesting language in CoffeeScript. This\nimplementation steals bits and pieces from other projects:\n\n* Rubinius (https://github.com/rubinius/rubinius/)\n* KPeg (https://github.com/evanphx/kpeg/)\n* Atomy (https://github.com/vito/atomy/)\n* Poison (https://github.com/brixen/poison/)\n* Talon (https://github.com/evanphx/talon/)\n\n\n[1] CoffeeScript (http://jashkenas.github.com/coffee-script/)\n[2] Rubinius (http://rubini.us)\n"
  },
  {
    "path": "Rakefile",
    "content": "require 'bundler'\nBundler::GemHelper.install_tasks\n\ntask :default => :spec\n\nbase = File.expand_path '../lib/poetics/parser', __FILE__\n\ngrammar = \"#{base}/poetics.kpeg\"\nparser  = \"#{base}/parser.rb\"\n\nfile parser => grammar do\n  sh \"rbx -S kpeg -f -s #{base}/poetics.kpeg -o #{base}/parser.rb\"\nend\n\ndesc \"Convert the grammar description to a parser\"\ntask :parser => parser\n\ndesc \"Run the specs (default)\"\ntask :spec => :parser do\n  sh \"mspec spec\"\nend\n"
  },
  {
    "path": "bin/poetics",
    "content": "#!/usr/bin/env rbx\n#\n# vim: filetype=ruby\n\n$:.unshift File.expand_path('../../lib', __FILE__)\n\nrequire 'readline'\nrequire 'poetics'\n\nclass Poetics::Script\n  HISTORY = File.expand_path \"~/.poetics_history\"\n\n  attr_accessor :prompt\n\n  def initialize\n    @evals = []\n    @script = nil\n    @history = []\n  end\n\n  def options(argv=ARGV)\n    options = Rubinius::Options.new \"Usage: poetics [options] [script]\", 20\n\n    options.on \"-\", \"Read and evaluate code from STDIN\" do\n      @evals << STDIN.read\n    end\n\n    options.on \"-c\", \"FILE\", \"Check the syntax of FILE\" do |f|\n      begin\n        begin\n          Poetics::Parser.parse_file f\n        rescue => e\n          e.render\n          exit 1\n        end\n\n        puts \"Syntax OK\"\n        exit 0\n      end\n    end\n\n    options.on \"-e\", \"CODE\", \"Execute CODE\" do |e|\n      @evals << e\n    end\n\n    options.on \"-v\", \"--version\", \"Display the version\" do\n      puts Poetics::COMMAND_VERSION\n    end\n\n    options.on \"-h\", \"--help\", \"Display this help\" do\n      puts options\n      exit 0\n    end\n\n    options.doc \"\"\n\n    rest = options.parse(argv)\n    @script ||= rest.first\n  end\n\n  def evals\n    return if @evals.empty?\n\n    Poetics::CodeLoader.evaluate @evals.join(\"\\n\")\n  end\n\n  def script\n    return unless @script\n\n    if File.exists? @script\n      Poetics::CodeLoader.execute_file @script\n    else\n      STDERR.puts \"Unable to find '#{@script}' to run\"\n      exit 1\n    end\n  end\n\n  def load_history\n    return unless File.exists? HISTORY\n\n    File.open HISTORY, \"r\" do |f|\n      f.each { |l| Readline::HISTORY << l }\n    end\n  end\n\n  def save_history\n    File.open HISTORY, \"w\" do |f|\n      @history.last(100).map { |s| f.puts s }\n    end\n  end\n\n  def record_history(str)\n    @history << str\n  end\n\n  def start_prompt\n    @prompt = \"> \"\n  end\n\n  def continue_prompt\n    @prompt = \". \"\n  end\n\n  def repl\n    return if @script\n    load_history\n    start_prompt\n\n    begin\n      snippet = \"\"\n      while str = Readline.readline(prompt)\n        break if str.nil? and snippet.empty?\n        next if str.empty?\n\n        snippet << str\n        begin\n          value = Poetics::CodeLoader.evaluate snippet\n          p value\n\n          record_history snippet\n          snippet = \"\"\n          start_prompt\n        rescue => e\n          STDERR.puts e\n        end\n      end\n    ensure\n      save_history\n    end\n  end\n\n  def main\n    options\n    evals\n    script\n    repl\n  end\nend\n\nPoetics::Script.new.main\n"
  },
  {
    "path": "lib/poetics/library/code_loader.rb",
    "content": "module Poetics\n  class CodeLoader\n    def self.evaluate(string)\n      # We're just parsing for now\n      Poetics::Parser.parse_to_sexp string\n    end\n\n    def self.execute_file(name)\n      value = Poetics::Parser.parse_to_sexp IO.read(name)\n      p value\n    end\n  end\nend\n"
  },
  {
    "path": "lib/poetics/library.rb",
    "content": "require 'poetics/library/code_loader'\n"
  },
  {
    "path": "lib/poetics/parser/parser.rb",
    "content": "class Poetics::Parser\n# STANDALONE START\n    def setup_parser(str, debug=false)\n      @string = str\n      @pos = 0\n      @memoizations = Hash.new { |h,k| h[k] = {} }\n      @result = nil\n      @failed_rule = nil\n      @failing_rule_offset = -1\n\n      setup_foreign_grammar\n    end\n\n    # This is distinct from setup_parser so that a standalone parser\n    # can redefine #initialize and still have access to the proper\n    # parser setup code.\n    #\n    def initialize(str, debug=false)\n      setup_parser(str, debug)\n    end\n\n    attr_reader :string\n    attr_reader :failing_rule_offset\n    attr_accessor :result, :pos\n\n    # STANDALONE START\n    def current_column(target=pos)\n      if c = string.rindex(\"\\n\", target-1)\n        return target - c - 1\n      end\n\n      target + 1\n    end\n\n    def current_line(target=pos)\n      cur_offset = 0\n      cur_line = 0\n\n      string.each_line do |line|\n        cur_line += 1\n        cur_offset += line.size\n        return cur_line if cur_offset >= target\n      end\n\n      -1\n    end\n\n    def lines\n      lines = []\n      string.each_line { |l| lines << l }\n      lines\n    end\n\n    #\n\n    def get_text(start)\n      @string[start..@pos-1]\n    end\n\n    def show_pos\n      width = 10\n      if @pos < width\n        \"#{@pos} (\\\"#{@string[0,@pos]}\\\" @ \\\"#{@string[@pos,width]}\\\")\"\n      else\n        \"#{@pos} (\\\"... #{@string[@pos - width, width]}\\\" @ \\\"#{@string[@pos,width]}\\\")\"\n      end\n    end\n\n    def failure_info\n      l = current_line @failing_rule_offset\n      c = current_column @failing_rule_offset\n\n      if @failed_rule.kind_of? Symbol\n        info = self.class::Rules[@failed_rule]\n        \"line #{l}, column #{c}: failed rule '#{info.name}' = '#{info.rendered}'\"\n      else\n        \"line #{l}, column #{c}: failed rule '#{@failed_rule}'\"\n      end\n    end\n\n    def failure_caret\n      l = current_line @failing_rule_offset\n      c = current_column @failing_rule_offset\n\n      line = lines[l-1]\n      \"#{line}\\n#{' ' * (c - 1)}^\"\n    end\n\n    def failure_character\n      l = current_line @failing_rule_offset\n      c = current_column @failing_rule_offset\n      lines[l-1][c-1, 1]\n    end\n\n    def failure_oneline\n      l = current_line @failing_rule_offset\n      c = current_column @failing_rule_offset\n\n      char = lines[l-1][c-1, 1]\n\n      if @failed_rule.kind_of? Symbol\n        info = self.class::Rules[@failed_rule]\n        \"@#{l}:#{c} failed rule '#{info.name}', got '#{char}'\"\n      else\n        \"@#{l}:#{c} failed rule '#{@failed_rule}', got '#{char}'\"\n      end\n    end\n\n    class ParseError < RuntimeError\n    end\n\n    def raise_error\n      raise ParseError, failure_oneline\n    end\n\n    def show_error(io=STDOUT)\n      error_pos = @failing_rule_offset\n      line_no = current_line(error_pos)\n      col_no = current_column(error_pos)\n\n      io.puts \"On line #{line_no}, column #{col_no}:\"\n\n      if @failed_rule.kind_of? Symbol\n        info = self.class::Rules[@failed_rule]\n        io.puts \"Failed to match '#{info.rendered}' (rule '#{info.name}')\"\n      else\n        io.puts \"Failed to match rule '#{@failed_rule}'\"\n      end\n\n      io.puts \"Got: #{string[error_pos,1].inspect}\"\n      line = lines[line_no-1]\n      io.puts \"=> #{line}\"\n      io.print(\" \" * (col_no + 3))\n      io.puts \"^\"\n    end\n\n    def set_failed_rule(name)\n      if @pos > @failing_rule_offset\n        @failed_rule = name\n        @failing_rule_offset = @pos\n      end\n    end\n\n    attr_reader :failed_rule\n\n    def match_string(str)\n      len = str.size\n      if @string[pos,len] == str\n        @pos += len\n        return str\n      end\n\n      return nil\n    end\n\n    def scan(reg)\n      if m = reg.match(@string[@pos..-1])\n        width = m.end(0)\n        @pos += width\n        return true\n      end\n\n      return nil\n    end\n\n    if \"\".respond_to? :getbyte\n      def get_byte\n        if @pos >= @string.size\n          return nil\n        end\n\n        s = @string.getbyte @pos\n        @pos += 1\n        s\n      end\n    else\n      def get_byte\n        if @pos >= @string.size\n          return nil\n        end\n\n        s = @string[@pos]\n        @pos += 1\n        s\n      end\n    end\n\n    def parse(rule=nil)\n      if !rule\n        _root ? true : false\n      else\n        # This is not shared with code_generator.rb so this can be standalone\n        method = rule.gsub(\"-\",\"_hyphen_\")\n        __send__(\"_#{method}\") ? true : false\n      end\n    end\n\n    class LeftRecursive\n      def initialize(detected=false)\n        @detected = detected\n      end\n\n      attr_accessor :detected\n    end\n\n    class MemoEntry\n      def initialize(ans, pos)\n        @ans = ans\n        @pos = pos\n        @uses = 1\n        @result = nil\n      end\n\n      attr_reader :ans, :pos, :uses, :result\n\n      def inc!\n        @uses += 1\n      end\n\n      def move!(ans, pos, result)\n        @ans = ans\n        @pos = pos\n        @result = result\n      end\n    end\n\n    def external_invoke(other, rule, *args)\n      old_pos = @pos\n      old_string = @string\n\n      @pos = other.pos\n      @string = other.string\n\n      begin\n        if val = __send__(rule, *args)\n          other.pos = @pos\n          other.result = @result\n        else\n          other.set_failed_rule \"#{self.class}##{rule}\"\n        end\n        val\n      ensure\n        @pos = old_pos\n        @string = old_string\n      end\n    end\n\n    def apply_with_args(rule, *args)\n      memo_key = [rule, args]\n      if m = @memoizations[memo_key][@pos]\n        m.inc!\n\n        prev = @pos\n        @pos = m.pos\n        if m.ans.kind_of? LeftRecursive\n          m.ans.detected = true\n          return nil\n        end\n\n        @result = m.result\n\n        return m.ans\n      else\n        lr = LeftRecursive.new(false)\n        m = MemoEntry.new(lr, @pos)\n        @memoizations[memo_key][@pos] = m\n        start_pos = @pos\n\n        ans = __send__ rule, *args\n\n        m.move! ans, @pos, @result\n\n        # Don't bother trying to grow the left recursion\n        # if it's failing straight away (thus there is no seed)\n        if ans and lr.detected\n          return grow_lr(rule, args, start_pos, m)\n        else\n          return ans\n        end\n\n        return ans\n      end\n    end\n\n    def apply(rule)\n      if m = @memoizations[rule][@pos]\n        m.inc!\n\n        prev = @pos\n        @pos = m.pos\n        if m.ans.kind_of? LeftRecursive\n          m.ans.detected = true\n          return nil\n        end\n\n        @result = m.result\n\n        return m.ans\n      else\n        lr = LeftRecursive.new(false)\n        m = MemoEntry.new(lr, @pos)\n        @memoizations[rule][@pos] = m\n        start_pos = @pos\n\n        ans = __send__ rule\n\n        m.move! ans, @pos, @result\n\n        # Don't bother trying to grow the left recursion\n        # if it's failing straight away (thus there is no seed)\n        if ans and lr.detected\n          return grow_lr(rule, nil, start_pos, m)\n        else\n          return ans\n        end\n\n        return ans\n      end\n    end\n\n    def grow_lr(rule, args, start_pos, m)\n      while true\n        @pos = start_pos\n        @result = m.result\n\n        if args\n          ans = __send__ rule, *args\n        else\n          ans = __send__ rule\n        end\n        return nil unless ans\n\n        break if @pos <= m.pos\n\n        m.move! ans, @pos, @result\n      end\n\n      @result = m.result\n      @pos = m.pos\n      return m.ans\n    end\n\n    class RuleInfo\n      def initialize(name, rendered)\n        @name = name\n        @rendered = rendered\n      end\n\n      attr_reader :name, :rendered\n    end\n\n    def self.rule_info(name, rendered)\n      RuleInfo.new(name, rendered)\n    end\n\n    #\n  def setup_foreign_grammar; end\n\n  # root = - value? - end\n  def _root\n\n    _save = self.pos\n    while true # sequence\n      _tmp = apply(:__hyphen_)\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      _save1 = self.pos\n      _tmp = apply(:_value)\n      unless _tmp\n        _tmp = true\n        self.pos = _save1\n      end\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      _tmp = apply(:__hyphen_)\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      _tmp = apply(:_end)\n      unless _tmp\n        self.pos = _save\n      end\n      break\n    end # end sequence\n\n    set_failed_rule :_root unless _tmp\n    return _tmp\n  end\n\n  # end = !.\n  def _end\n    _save = self.pos\n    _tmp = get_byte\n    _tmp = _tmp ? nil : true\n    self.pos = _save\n    set_failed_rule :_end unless _tmp\n    return _tmp\n  end\n\n  # - = (\" \" | \"\\t\" | \"\\n\")*\n  def __hyphen_\n    while true\n\n      _save1 = self.pos\n      while true # choice\n        _tmp = match_string(\" \")\n        break if _tmp\n        self.pos = _save1\n        _tmp = match_string(\"\\t\")\n        break if _tmp\n        self.pos = _save1\n        _tmp = match_string(\"\\n\")\n        break if _tmp\n        self.pos = _save1\n        break\n      end # end choice\n\n      break unless _tmp\n    end\n    _tmp = true\n    set_failed_rule :__hyphen_ unless _tmp\n    return _tmp\n  end\n\n  # value = (string | number | boolean)\n  def _value\n\n    _save = self.pos\n    while true # choice\n      _tmp = apply(:_string)\n      break if _tmp\n      self.pos = _save\n      _tmp = apply(:_number)\n      break if _tmp\n      self.pos = _save\n      _tmp = apply(:_boolean)\n      break if _tmp\n      self.pos = _save\n      break\n    end # end choice\n\n    set_failed_rule :_value unless _tmp\n    return _tmp\n  end\n\n  # boolean = position (true | false | null | undefined)\n  def _boolean\n\n    _save = self.pos\n    while true # sequence\n      _tmp = apply(:_position)\n      unless _tmp\n        self.pos = _save\n        break\n      end\n\n      _save1 = self.pos\n      while true # choice\n        _tmp = apply(:_true)\n        break if _tmp\n        self.pos = _save1\n        _tmp = apply(:_false)\n        break if _tmp\n        self.pos = _save1\n        _tmp = apply(:_null)\n        break if _tmp\n        self.pos = _save1\n        _tmp = apply(:_undefined)\n        break if _tmp\n        self.pos = _save1\n        break\n      end # end choice\n\n      unless _tmp\n        self.pos = _save\n      end\n      break\n    end # end sequence\n\n    set_failed_rule :_boolean unless _tmp\n    return _tmp\n  end\n\n  # true = \"true\" {true_value}\n  def _true\n\n    _save = self.pos\n    while true # sequence\n      _tmp = match_string(\"true\")\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      @result = begin; true_value; end\n      _tmp = true\n      unless _tmp\n        self.pos = _save\n      end\n      break\n    end # end sequence\n\n    set_failed_rule :_true unless _tmp\n    return _tmp\n  end\n\n  # false = \"false\" {false_value}\n  def _false\n\n    _save = self.pos\n    while true # sequence\n      _tmp = match_string(\"false\")\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      @result = begin; false_value; end\n      _tmp = true\n      unless _tmp\n        self.pos = _save\n      end\n      break\n    end # end sequence\n\n    set_failed_rule :_false unless _tmp\n    return _tmp\n  end\n\n  # null = \"null\" {null_value}\n  def _null\n\n    _save = self.pos\n    while true # sequence\n      _tmp = match_string(\"null\")\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      @result = begin; null_value; end\n      _tmp = true\n      unless _tmp\n        self.pos = _save\n      end\n      break\n    end # end sequence\n\n    set_failed_rule :_null unless _tmp\n    return _tmp\n  end\n\n  # undefined = \"undefined\" {undefined_value}\n  def _undefined\n\n    _save = self.pos\n    while true # sequence\n      _tmp = match_string(\"undefined\")\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      @result = begin; undefined_value; end\n      _tmp = true\n      unless _tmp\n        self.pos = _save\n      end\n      break\n    end # end sequence\n\n    set_failed_rule :_undefined unless _tmp\n    return _tmp\n  end\n\n  # number = position (real | hex | int)\n  def _number\n\n    _save = self.pos\n    while true # sequence\n      _tmp = apply(:_position)\n      unless _tmp\n        self.pos = _save\n        break\n      end\n\n      _save1 = self.pos\n      while true # choice\n        _tmp = apply(:_real)\n        break if _tmp\n        self.pos = _save1\n        _tmp = apply(:_hex)\n        break if _tmp\n        self.pos = _save1\n        _tmp = apply(:_int)\n        break if _tmp\n        self.pos = _save1\n        break\n      end # end choice\n\n      unless _tmp\n        self.pos = _save\n      end\n      break\n    end # end sequence\n\n    set_failed_rule :_number unless _tmp\n    return _tmp\n  end\n\n  # hexdigits = /[0-9A-Fa-f]/\n  def _hexdigits\n    _tmp = scan(/\\A(?-mix:[0-9A-Fa-f])/)\n    set_failed_rule :_hexdigits unless _tmp\n    return _tmp\n  end\n\n  # hex = \"0x\" < hexdigits+ > {hexadecimal(text)}\n  def _hex\n\n    _save = self.pos\n    while true # sequence\n      _tmp = match_string(\"0x\")\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      _text_start = self.pos\n      _save1 = self.pos\n      _tmp = apply(:_hexdigits)\n      if _tmp\n        while true\n          _tmp = apply(:_hexdigits)\n          break unless _tmp\n        end\n        _tmp = true\n      else\n        self.pos = _save1\n      end\n      if _tmp\n        text = get_text(_text_start)\n      end\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      @result = begin; hexadecimal(text); end\n      _tmp = true\n      unless _tmp\n        self.pos = _save\n      end\n      break\n    end # end sequence\n\n    set_failed_rule :_hex unless _tmp\n    return _tmp\n  end\n\n  # digits = (\"0\" | /[1-9]/ /[0-9]/*)\n  def _digits\n\n    _save = self.pos\n    while true # choice\n      _tmp = match_string(\"0\")\n      break if _tmp\n      self.pos = _save\n\n      _save1 = self.pos\n      while true # sequence\n        _tmp = scan(/\\A(?-mix:[1-9])/)\n        unless _tmp\n          self.pos = _save1\n          break\n        end\n        while true\n          _tmp = scan(/\\A(?-mix:[0-9])/)\n          break unless _tmp\n        end\n        _tmp = true\n        unless _tmp\n          self.pos = _save1\n        end\n        break\n      end # end sequence\n\n      break if _tmp\n      self.pos = _save\n      break\n    end # end choice\n\n    set_failed_rule :_digits unless _tmp\n    return _tmp\n  end\n\n  # int = < digits > {number(text)}\n  def _int\n\n    _save = self.pos\n    while true # sequence\n      _text_start = self.pos\n      _tmp = apply(:_digits)\n      if _tmp\n        text = get_text(_text_start)\n      end\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      @result = begin; number(text); end\n      _tmp = true\n      unless _tmp\n        self.pos = _save\n      end\n      break\n    end # end sequence\n\n    set_failed_rule :_int unless _tmp\n    return _tmp\n  end\n\n  # real = < digits \".\" digits (\"e\" /[-+]/? /[0-9]/+)? > {number(text)}\n  def _real\n\n    _save = self.pos\n    while true # sequence\n      _text_start = self.pos\n\n      _save1 = self.pos\n      while true # sequence\n        _tmp = apply(:_digits)\n        unless _tmp\n          self.pos = _save1\n          break\n        end\n        _tmp = match_string(\".\")\n        unless _tmp\n          self.pos = _save1\n          break\n        end\n        _tmp = apply(:_digits)\n        unless _tmp\n          self.pos = _save1\n          break\n        end\n        _save2 = self.pos\n\n        _save3 = self.pos\n        while true # sequence\n          _tmp = match_string(\"e\")\n          unless _tmp\n            self.pos = _save3\n            break\n          end\n          _save4 = self.pos\n          _tmp = scan(/\\A(?-mix:[-+])/)\n          unless _tmp\n            _tmp = true\n            self.pos = _save4\n          end\n          unless _tmp\n            self.pos = _save3\n            break\n          end\n          _save5 = self.pos\n          _tmp = scan(/\\A(?-mix:[0-9])/)\n          if _tmp\n            while true\n              _tmp = scan(/\\A(?-mix:[0-9])/)\n              break unless _tmp\n            end\n            _tmp = true\n          else\n            self.pos = _save5\n          end\n          unless _tmp\n            self.pos = _save3\n          end\n          break\n        end # end sequence\n\n        unless _tmp\n          _tmp = true\n          self.pos = _save2\n        end\n        unless _tmp\n          self.pos = _save1\n        end\n        break\n      end # end sequence\n\n      if _tmp\n        text = get_text(_text_start)\n      end\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      @result = begin; number(text); end\n      _tmp = true\n      unless _tmp\n        self.pos = _save\n      end\n      break\n    end # end sequence\n\n    set_failed_rule :_real unless _tmp\n    return _tmp\n  end\n\n  # string = position \"\\\"\" < /[^\\\\\"]*/ > \"\\\"\" {string_value(text)}\n  def _string\n\n    _save = self.pos\n    while true # sequence\n      _tmp = apply(:_position)\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      _tmp = match_string(\"\\\"\")\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      _text_start = self.pos\n      _tmp = scan(/\\A(?-mix:[^\\\\\"]*)/)\n      if _tmp\n        text = get_text(_text_start)\n      end\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      _tmp = match_string(\"\\\"\")\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      @result = begin; string_value(text); end\n      _tmp = true\n      unless _tmp\n        self.pos = _save\n      end\n      break\n    end # end sequence\n\n    set_failed_rule :_string unless _tmp\n    return _tmp\n  end\n\n  # line = { current_line }\n  def _line\n    @result = begin;  current_line ; end\n    _tmp = true\n    set_failed_rule :_line unless _tmp\n    return _tmp\n  end\n\n  # column = { current_column }\n  def _column\n    @result = begin;  current_column ; end\n    _tmp = true\n    set_failed_rule :_column unless _tmp\n    return _tmp\n  end\n\n  # position = line:l column:c { position(l, c) }\n  def _position\n\n    _save = self.pos\n    while true # sequence\n      _tmp = apply(:_line)\n      l = @result\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      _tmp = apply(:_column)\n      c = @result\n      unless _tmp\n        self.pos = _save\n        break\n      end\n      @result = begin;  position(l, c) ; end\n      _tmp = true\n      unless _tmp\n        self.pos = _save\n      end\n      break\n    end # end sequence\n\n    set_failed_rule :_position unless _tmp\n    return _tmp\n  end\n\n  Rules = {}\n  Rules[:_root] = rule_info(\"root\", \"- value? - end\")\n  Rules[:_end] = rule_info(\"end\", \"!.\")\n  Rules[:__hyphen_] = rule_info(\"-\", \"(\\\" \\\" | \\\"\\\\t\\\" | \\\"\\\\n\\\")*\")\n  Rules[:_value] = rule_info(\"value\", \"(string | number | boolean)\")\n  Rules[:_boolean] = rule_info(\"boolean\", \"position (true | false | null | undefined)\")\n  Rules[:_true] = rule_info(\"true\", \"\\\"true\\\" {true_value}\")\n  Rules[:_false] = rule_info(\"false\", \"\\\"false\\\" {false_value}\")\n  Rules[:_null] = rule_info(\"null\", \"\\\"null\\\" {null_value}\")\n  Rules[:_undefined] = rule_info(\"undefined\", \"\\\"undefined\\\" {undefined_value}\")\n  Rules[:_number] = rule_info(\"number\", \"position (real | hex | int)\")\n  Rules[:_hexdigits] = rule_info(\"hexdigits\", \"/[0-9A-Fa-f]/\")\n  Rules[:_hex] = rule_info(\"hex\", \"\\\"0x\\\" < hexdigits+ > {hexadecimal(text)}\")\n  Rules[:_digits] = rule_info(\"digits\", \"(\\\"0\\\" | /[1-9]/ /[0-9]/*)\")\n  Rules[:_int] = rule_info(\"int\", \"< digits > {number(text)}\")\n  Rules[:_real] = rule_info(\"real\", \"< digits \\\".\\\" digits (\\\"e\\\" /[-+]/? /[0-9]/+)? > {number(text)}\")\n  Rules[:_string] = rule_info(\"string\", \"position \\\"\\\\\\\"\\\" < /[^\\\\\\\\\\\"]*/ > \\\"\\\\\\\"\\\" {string_value(text)}\")\n  Rules[:_line] = rule_info(\"line\", \"{ current_line }\")\n  Rules[:_column] = rule_info(\"column\", \"{ current_column }\")\n  Rules[:_position] = rule_info(\"position\", \"line:l column:c { position(l, c) }\")\nend\n"
  },
  {
    "path": "lib/poetics/parser/poetics.kpeg",
    "content": "%% name = Poetics::Parser\n\nroot      = - value? - end\n\nend       = !.\n-         = (\" \" | \"\\t\" | \"\\n\")*\n\nvalue     = string\n          | number\n          | boolean\n\n\nboolean   = position (\n            true\n          | false\n          | null\n          | undefined)\n\ntrue      = \"true\" ~true_value\nfalse     = \"false\" ~false_value\nnull      = \"null\" ~null_value\nundefined = \"undefined\" ~undefined_value\n\n\nnumber    = position (\n            real\n          | hex\n          | int )\n\nhexdigits = /[0-9A-Fa-f]/\nhex       = '0x' < hexdigits+ > ~hexadecimal(text)\ndigits    = '0' | /[1-9]/ /[0-9]/*\nint       = < digits > ~number(text)\nreal      = < digits '.' digits ('e' /[-+]/? /[0-9]/+)? > ~number(text)\n\n\nstring    = position '\"' < /[^\\\\\"]*/ > '\"' ~string_value(text)\n\n# keep track of column and line\nline      = { current_line }\ncolumn    = { current_column }\nposition  = line:l column:c { position(l, c) }\n"
  },
  {
    "path": "lib/poetics/parser.rb",
    "content": "require 'poetics/parser/parser'\n\nclass Poetics::Parser\n  include Poetics::Syntax\n\n  def self.parse_to_sexp(string)\n    parser = new string\n    unless parser.parse\n      parser.raise_error\n    end\n\n    parser.result.to_sexp\n  end\n\n  attr_reader :line, :column\n\n  def position(line, column)\n    @line = line\n    @column = column\n  end\nend\n"
  },
  {
    "path": "lib/poetics/syntax/ast.rb",
    "content": "module Poetics\n  module Syntax\n    def number(value)\n      Number.new line, column, value\n    end\n\n    def hexadecimal(value)\n      Number.new line, column, value.to_i(16)\n    end\n\n    def true_value\n      True.new line, column\n    end\n\n    def false_value\n      False.new line, column\n    end\n\n    def null_value\n      Null.new line, column\n    end\n\n    def undefined_value\n      Undefined.new line, column\n    end\n\n    def string_value(value)\n      String.new line, column, value\n    end\n  end\nend\n"
  },
  {
    "path": "lib/poetics/syntax/literal.rb",
    "content": "module Poetics\n  module Syntax\n    class Value < Node\n      def to_sexp\n        [sexp_name, value, line, column]\n      end\n    end\n\n    class Number < Value\n      attr_accessor :value\n\n      def initialize(line, column, value)\n        super\n        @value = value.to_f\n      end\n\n      def sexp_name\n        :number\n      end\n    end\n\n    class Boolean < Node\n      def to_sexp\n        [sexp_name, line, column]\n      end\n    end\n\n    class True < Boolean\n      def sexp_name\n        :true\n      end\n    end\n\n    class False < Boolean\n      def sexp_name\n        :false\n      end\n    end\n\n    class Null < Boolean\n      def sexp_name\n        :null\n      end\n    end\n\n    class Undefined < Boolean\n      def sexp_name\n        :undefined\n      end\n    end\n\n    class String < Value\n      attr_accessor :value\n\n      def initialize(line, column, text)\n        super\n        @value = text\n      end\n\n      def sexp_name\n        :string\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/poetics/syntax/node.rb",
    "content": "module Poetics\n  module Syntax\n    class Node\n      attr_accessor :line, :column\n\n      def initialize(line, column, *)\n        @line = line\n        @column = column\n      end\n\n      def to_sexp\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/poetics/syntax.rb",
    "content": "require 'poetics/syntax/node'\nrequire 'poetics/syntax/literal'\nrequire 'poetics/syntax/ast'\n"
  },
  {
    "path": "lib/poetics/version.rb",
    "content": "module Poetics\n  VERSION = \"0.0.1\"\n  RELEASE_DATE = \"yyyy-mm-dd\"\n  COMMAND_VERSION = \"poetics #{VERSION} (1.1.0 #{RELEASE_DATE})\"\nend\n"
  },
  {
    "path": "lib/poetics.rb",
    "content": "require 'poetics/version'\nrequire 'poetics/syntax'\nrequire 'poetics/parser'\nrequire 'poetics/library'\n"
  },
  {
    "path": "poetics.gemspec",
    "content": "# -*- encoding: utf-8 -*-\n$:.push File.expand_path(\"../lib\", __FILE__)\nrequire \"poetics/version\"\n\nGem::Specification.new do |s|\n  s.name        = \"poetics\"\n  s.version     = Poetics::VERSION\n  s.platform    = Gem::Platform::RUBY\n  s.authors     = [\"Brian Ford\"]\n  s.email       = [\"brixen@gmail.com\"]\n  s.homepage    = \"https://github.com/brixen/poetics\"\n  s.summary     = %q{A native implementation of CoffeeScript on the Rubinius VM}\n  s.description =<<-EOD\nPoetics implements CoffeeScript (http://jashkenas.github.com/coffee-script/)\ndirectly on the Rubinius VM (http://rubini.us). It includes a REPL for\nexploratory programming, as well as executing CoffeeScript scripts directly.\n  EOD\n\n  s.files         = `git ls-files`.split(\"\\n\")\n  s.test_files    = Dir[\"spec/**/*.rb\"]\n  s.executables   = [\"poetics\"]\n  s.require_paths = [\"lib\"]\nend\n"
  },
  {
    "path": "spec/custom/matchers/parse_as.rb",
    "content": "class ParseAsMatcher\n  def initialize(expected)\n    @expected = expected\n  end\n\n  def matches?(actual)\n    @actual = Poetics::Parser.parse_to_sexp actual\n    @actual == @expected\n  end\n\n  def failure_message\n    [\"Expected:\\n#{@actual.inspect}\\n\",\n     \"to equal:\\n#{@expected.inspect}\"]\n  end\nend\n\nclass Object\n  def parse_as(sexp)\n    ParseAsMatcher.new sexp\n  end\nend\n"
  },
  {
    "path": "spec/custom/runner/relates.rb",
    "content": "# NOTE: Copied from Rubinius\n#\n# SpecDataRelation enables concise specs that involve several different forms\n# of the same data. This is specifically useful for the parser and compiler\n# specs where the output of each stage is essentially related to the input\n# Ruby source. Together with the #relates spec method, it enables specs like:\n#\n#   describe \"An If node\" do\n#     relates \"a if b\" do\n#       parse do\n#         # return the expected sexp\n#       end\n#\n#       compile do |g|\n#         # return the expected bytecode\n#       end\n#\n#       jit do |as|\n#         # return the expected asm/machine code\n#       end\n#     end\n#\n#     relates \"if a; b; end\" do\n#       # ...\n#     end\n#   end\n\nclass SpecDataRelation\n  # Provides a simple configurability so that any one or more of the possible\n  # processes can be run. See the custom options in custom/utils/options.rb.\n  def self.enable(process)\n    @processors ||= []\n    @processors << process\n  end\n\n  # Returns true if no process is specifically set or if +process+ is in the\n  # list of enabled processes. In other words, all processes are enabled by\n  # default, or any combination of them may be enabled.\n  def self.enabled?(process)\n    @processors.nil? or @processors.include?(process)\n  end\n\n  def initialize(ruby)\n    @ruby = ruby\n  end\n\n  # Formats the Ruby source code for reabable output in the -fs formatter\n  # option. If the source contains no newline characters, wraps the source in\n  # single quotes to set if off from the rest of the description string. If\n  # the source does contain newline characters, sets the indent level to four\n  # characters.\n  def format(ruby)\n    if /\\n/ =~ ruby\n      lines = ruby.rstrip.to_a\n      if /( *)/ =~ lines.first\n        if $1.size > 4\n          dedent = $1.size - 4\n          ruby = lines.map { |l| l[dedent..-1] }.join\n        else\n          indent = \" \" * (4 - $1.size)\n          ruby = lines.map { |l| \"#{indent}#{l}\" }.join\n        end\n      end\n      \"\\n#{ruby}\"\n    else\n      \"'#{ruby}'\"\n    end\n  end\n\n  # Creates spec example blocks if the compile process is enabled.\n  def compile(*plugins, &block)\n    return unless self.class.enabled? :compiler\n\n    ruby = @ruby\n    it \"is compiled from #{format ruby}\" do\n      generator = Rubinius::TestGenerator.new\n      generator.instance_eval(&block)\n\n      ruby.should compile_as(generator, *plugins)\n    end\n  end\n\n  def parse(&block)\n    return unless self.class.enabled? :parser\n\n    ruby = @ruby\n    it \"is parsed from #{format ruby}\" do\n      ruby.should parse_as(block.call)\n    end\n  end\nend\n\nclass Object\n  def relates(str, &block)\n    SpecDataRelation.new(str).instance_eval(&block)\n  end\nend\n"
  },
  {
    "path": "spec/custom/utils/options.rb",
    "content": "# Custom MSpec options\n#\nclass MSpecOptions\n  def compiler\n    # The require is inside the method because this file has to be able to be\n    # loaded in MRI and there are parts of the custom ensemble that are\n    # Rubinius specific (primarily iseq, which could potentially be fixed by\n    # better structuring the compiler).\n    require 'spec/custom/runner/relates'\n\n    on(\"--compiler\", \"Run only the compile part of the compiler specs\") do\n      SpecDataRelation.enable :compiler\n    end\n  end\n\n  def parser\n    on(\"--parser\", \"Run only the parse part of the compiler specs\") do\n      SpecDataRelation.enable :parser\n    end\n  end\nend\n"
  },
  {
    "path": "spec/custom/utils/script.rb",
    "content": "# Custom options for mspec-run\n#\nclass MSpecRun\n  def custom_options(options)\n    options.compiler\n    options.parser\n  end\nend\n\n# Custom options for mspec-ci\n#\nclass MSpecCI\n  def custom_options(options)\n    options.compiler\n    options.parser\n  end\nend\n\n# Custom options for mspec-tag\n#\nclass MSpecTag\n  def custom_options(options)\n    options.compiler\n    options.parser\n  end\nend\n"
  },
  {
    "path": "spec/custom.rb",
    "content": "require 'spec/custom/runner/relates'\nrequire 'spec/custom/matchers/parse_as'\nrequire 'spec/custom/utils/options'\nrequire 'spec/custom/utils/script'\n"
  },
  {
    "path": "spec/default.mspec",
    "content": "# vim: filetype=ruby\nrequire 'spec/custom'\n\nclass MSpecScript\n  set :target, 'rbx'\nend\n"
  },
  {
    "path": "spec/spec_helper.rb",
    "content": "$: << File.expand_path('../../lib', __FILE__)\n\nrequire 'poetics'\n"
  },
  {
    "path": "spec/syntax/literal_spec.rb",
    "content": "require 'spec/spec_helper'\n\ndescribe \"The Number node\" do\n  relates \"42\" do\n    parse { [:number, 42.0, 1, 1] }\n  end\n\n  relates \" 42\" do\n    parse { [:number, 42.0, 1, 2] }\n  end\n\n  relates \"42 \" do\n    parse { [:number, 42.0, 1, 1] }\n  end\n\n  relates \"1.23\" do\n    parse { [:number, 1.23, 1, 1] }\n  end\n\n  relates \"0x2a\" do\n    parse { [:number, 42.0, 1, 1] }\n  end\nend\n\ndescribe \"The True node\" do\n  relates \"true\" do\n    parse { [:true, 1, 1] }\n  end\nend\n\ndescribe \"The False node\" do\n  relates \"false\" do\n    parse { [:false, 1, 1] }\n  end\nend\n\ndescribe \"The Null node\" do\n  relates \"null\" do\n    parse { [:null, 1, 1] }\n  end\nend\n\ndescribe \"The Undefined node\" do\n  relates \"undefined\" do\n    parse { [:undefined, 1, 1] }\n  end\nend\n\ndescribe \"The String node\" do\n  relates '\"hello, world\"' do\n    parse { [:string, \"hello, world\", 1, 1] }\n  end\n\n  relates <<-ruby do\n      \"hello\"\n    ruby\n\n    parse { [:string, \"hello\", 1, 7] }\n  end\nend\n"
  }
]