phaad 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Rakefile +5 -0
- data/bin/phaad +4 -0
- data/lib/phaad/cli.rb +24 -0
- data/lib/phaad/generator.rb +61 -0
- data/lib/phaad/version.rb +3 -0
- data/lib/phaad.rb +3 -0
- data/phaad.gemspec +23 -0
- data/spec/generator/literal_spec.rb +37 -0
- data/spec/phaad_spec.rb +7 -0
- data/spec/spec_helper.rb +8 -0
- metadata +70 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/bin/phaad
ADDED
data/lib/phaad/cli.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Phaad
|
2
|
+
class CLI
|
3
|
+
def initialize(argv)
|
4
|
+
repl
|
5
|
+
end
|
6
|
+
|
7
|
+
##
|
8
|
+
# A very primitive repl. Only handles one lines.
|
9
|
+
def repl
|
10
|
+
puts "Type exit to exit."
|
11
|
+
print "> "
|
12
|
+
while (input = gets.chomp) != "exit"
|
13
|
+
begin
|
14
|
+
puts Phaad::Generator.new(input).emitted
|
15
|
+
rescue Exception => e
|
16
|
+
puts e
|
17
|
+
p e.message
|
18
|
+
puts e.backtrace
|
19
|
+
end
|
20
|
+
print "> "
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Phaad
|
2
|
+
NotImplementedError = Class.new(StandardError)
|
3
|
+
|
4
|
+
class Generator
|
5
|
+
attr_reader :emitted, :sexp
|
6
|
+
|
7
|
+
def initialize(str_or_sexp, &blk)
|
8
|
+
if block_given?
|
9
|
+
raise NotImplementedError, "blocks aren't implemented yet"
|
10
|
+
elsif str_or_sexp.is_a?(Array)
|
11
|
+
@sexp = str_or_sexp
|
12
|
+
else
|
13
|
+
@sexp = Ripper.sexp(str_or_sexp)
|
14
|
+
end
|
15
|
+
|
16
|
+
@emitted = ""
|
17
|
+
@sexp.last.each(&method(:process))
|
18
|
+
end
|
19
|
+
|
20
|
+
def emit(str)
|
21
|
+
@emitted << str
|
22
|
+
end
|
23
|
+
|
24
|
+
def process(sexp)
|
25
|
+
case sexp.first
|
26
|
+
when :@int, :@float
|
27
|
+
emit sexp[1]
|
28
|
+
when :@tstring_content
|
29
|
+
"\"#{sexp[1]}\""
|
30
|
+
when :string_content
|
31
|
+
process sexp[1]
|
32
|
+
when :string_literal
|
33
|
+
emit process(sexp[1])
|
34
|
+
when :regexp_literal
|
35
|
+
emit "\"/#{sexp[1][0][1]}#{process(sexp[2])}\""
|
36
|
+
when :@regexp_end
|
37
|
+
sexp[1]
|
38
|
+
when :symbol_literal
|
39
|
+
emit sexp[1][1][1].inspect
|
40
|
+
when :dyna_symbol
|
41
|
+
emit process(sexp[1][0])
|
42
|
+
when :var_ref
|
43
|
+
if sexp[1][0] == :@kw
|
44
|
+
case sexp[1][1]
|
45
|
+
when 'false', 'true'
|
46
|
+
emit sexp[1][1].upcase
|
47
|
+
when 'nil'
|
48
|
+
emit 'NULL'
|
49
|
+
else
|
50
|
+
raise NotImplementedError, sexp
|
51
|
+
end
|
52
|
+
else
|
53
|
+
# later
|
54
|
+
raise NotImplementedError, sexp
|
55
|
+
end
|
56
|
+
else
|
57
|
+
raise NotImplementedError, sexp.inspect
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/phaad.rb
ADDED
data/phaad.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "phaad/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "phaad"
|
7
|
+
s.version = Phaad::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Utkarsh Kukreti"]
|
10
|
+
s.email = ["utkarshkukreti@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{A beautiful way to write PHP}
|
13
|
+
s.description = %q{A beautiful way to write PHP}
|
14
|
+
|
15
|
+
s.rubyforge_project = "phaad"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency 'rspec', '~>2.6.0'
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Phaad::Generator, "Literals" do
|
4
|
+
it "should parse integers" do
|
5
|
+
compile("1").should == "1"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should parse floats" do
|
9
|
+
compile("1.0").should == "1.0"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should parse strings" do
|
13
|
+
compile('"foo bar"').should == '"foo bar"'
|
14
|
+
compile("'foo bar'").should == '"foo bar"'
|
15
|
+
compile('"foo\nbar"').should == '"foo\nbar"'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should parse regexes" do
|
19
|
+
compile("/ab/").should == '"/ab/"'
|
20
|
+
compile("/ab/i").should == '"/ab/i"'
|
21
|
+
compile('/a\b/i').should == '"/a\\b/i"'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should parse booleans" do
|
25
|
+
compile("true").should == "TRUE"
|
26
|
+
compile("false").should == "FALSE"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should parse nil" do
|
30
|
+
compile("nil").should == "NULL"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should parse symbols as strings" do
|
34
|
+
compile(":foo").should == '"foo"'
|
35
|
+
compile(':"foo"').should == '"foo"'
|
36
|
+
end
|
37
|
+
end
|
data/spec/phaad_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phaad
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Utkarsh Kukreti
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-05-26 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &78725830 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.6.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *78725830
|
25
|
+
description: A beautiful way to write PHP
|
26
|
+
email:
|
27
|
+
- utkarshkukreti@gmail.com
|
28
|
+
executables:
|
29
|
+
- phaad
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- .rspec
|
35
|
+
- Gemfile
|
36
|
+
- Rakefile
|
37
|
+
- bin/phaad
|
38
|
+
- lib/phaad.rb
|
39
|
+
- lib/phaad/cli.rb
|
40
|
+
- lib/phaad/generator.rb
|
41
|
+
- lib/phaad/version.rb
|
42
|
+
- phaad.gemspec
|
43
|
+
- spec/generator/literal_spec.rb
|
44
|
+
- spec/phaad_spec.rb
|
45
|
+
- spec/spec_helper.rb
|
46
|
+
homepage: ''
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project: phaad
|
66
|
+
rubygems_version: 1.8.4
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: A beautiful way to write PHP
|
70
|
+
test_files: []
|