linguify 0.5.2 → 0.6.0
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/README.md +27 -0
- data/VERSION +1 -1
- data/lib/linguify/linguified.rb +19 -4
- data/lib/linguify/sexp.rb +48 -0
- data/linguify.gemspec +3 -3
- metadata +4 -4
data/README.md
CHANGED
@@ -168,6 +168,33 @@ end
|
|
168
168
|
# "
|
169
169
|
```
|
170
170
|
|
171
|
+
There is also the inline keyword:
|
172
|
+
|
173
|
+
``` ruby
|
174
|
+
require 'linguify'
|
175
|
+
|
176
|
+
reduce /inlined code/ => 'code' do
|
177
|
+
something.each do |foobar| # life is not worth living without psedo foobars
|
178
|
+
pp foobar
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
reduce /execute ({code:[^}]*})/ do |code|
|
183
|
+
pp "hey mum"
|
184
|
+
inline code
|
185
|
+
code
|
186
|
+
pp "you will never know what I just did"
|
187
|
+
end
|
188
|
+
|
189
|
+
"execute inlined code".linguify.to_ruby
|
190
|
+
# => "code = lambda do
|
191
|
+
# (pp(\"hey mum\")
|
192
|
+
# (something.each { |foobar| pp(foobar) })
|
193
|
+
# pp(\"you will never know what I just did\"))
|
194
|
+
# end
|
195
|
+
# "
|
196
|
+
```
|
197
|
+
|
171
198
|
## License
|
172
199
|
|
173
200
|
(The MIT License)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/lib/linguify/linguified.rb
CHANGED
@@ -42,6 +42,7 @@ module Linguify
|
|
42
42
|
#
|
43
43
|
@sentence = str.dup
|
44
44
|
@bind = bind
|
45
|
+
@stack = [ str ]
|
45
46
|
loop do
|
46
47
|
rule = find_rule(str)
|
47
48
|
|
@@ -52,6 +53,8 @@ module Linguify
|
|
52
53
|
:args => rule[:match].match(str).to_a
|
53
54
|
|
54
55
|
str = Linguified.reduce_string(str,rule[:match],reduction.to_rexp)
|
56
|
+
@stack << str
|
57
|
+
|
55
58
|
break if /^{:[0-9]*}$/ =~ str
|
56
59
|
end
|
57
60
|
|
@@ -63,6 +66,8 @@ module Linguify
|
|
63
66
|
|
64
67
|
code = Reduction::parse(str).compile
|
65
68
|
|
69
|
+
Sexp.inline_keyword_inlined!(code)
|
70
|
+
|
66
71
|
#if @dispatch_exceptions
|
67
72
|
# @sexy = Sexp.debug_envelope(code)
|
68
73
|
#else
|
@@ -142,13 +147,20 @@ module Linguify
|
|
142
147
|
def self.has_needle_on_word_boundary? splitted
|
143
148
|
return true if splitted.size == 1 and splitted.first == :needle
|
144
149
|
|
150
|
+
prev_ends_with_space = true
|
151
|
+
following_needle = true
|
152
|
+
|
145
153
|
splitted.each_with_index do |split,i|
|
146
154
|
if split.kind_of? String
|
147
|
-
|
148
|
-
|
155
|
+
return true if following_needle and prev_ends_with_space and split[0] == ' '
|
156
|
+
|
157
|
+
prev_ends_with_space = (split[-1] == ' ')
|
158
|
+
following_needle = false
|
159
|
+
else # :needle
|
160
|
+
following_needle = true
|
149
161
|
end
|
150
162
|
end
|
151
|
-
|
163
|
+
following_needle && prev_ends_with_space
|
152
164
|
end
|
153
165
|
|
154
166
|
# Find a reduction rule for the string
|
@@ -166,7 +178,10 @@ module Linguify
|
|
166
178
|
false
|
167
179
|
end
|
168
180
|
end
|
169
|
-
|
181
|
+
if found.size == 0
|
182
|
+
pp @stack
|
183
|
+
raise "no step definition for #{str}"
|
184
|
+
end
|
170
185
|
found[0]
|
171
186
|
end
|
172
187
|
|
data/lib/linguify/sexp.rb
CHANGED
@@ -145,6 +145,54 @@ class Sexp < Array
|
|
145
145
|
# Sexp.new(:call, Sexp.new(:const, :Linguify), :exception, Sexp.new(:arglist, Sexp.new(:lvar, :e))))))))
|
146
146
|
#end
|
147
147
|
|
148
|
+
def find needle
|
149
|
+
res = []
|
150
|
+
res << self if sexp_type == needle
|
151
|
+
case sexp_type
|
152
|
+
when :lasgn
|
153
|
+
self[1] == needle
|
154
|
+
when :lvar
|
155
|
+
self[1] == needle
|
156
|
+
when :call
|
157
|
+
self[2] == needle
|
158
|
+
when :lvar
|
159
|
+
self[1] == needle
|
160
|
+
else
|
161
|
+
self[1..-1].each do |h|
|
162
|
+
if h && h.kind_of?(Sexp)
|
163
|
+
res += h.find(needle)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
res
|
168
|
+
end
|
169
|
+
|
170
|
+
def self.inline_keyword_inlined! code
|
171
|
+
inlines = Sexp.from_array(code).find(:call).select{ |call| call[1] == nil && call[2] == :inline }
|
172
|
+
inlines.each do |inline|
|
173
|
+
raise "Im lost, dont know what this is (yet)" unless inline[3].sexp_type == :arglist
|
174
|
+
raise "Im lost, dont know what this is (yet)" unless inline[3].size == 2
|
175
|
+
raise "Im lost, dont know what this is (yet)" unless inline[3][1].sexp_type == :lvar
|
176
|
+
var = inline[3][1][1]
|
177
|
+
|
178
|
+
assignments = []
|
179
|
+
code.each_with_index do |expression,n|
|
180
|
+
if expression.sexp_type == :lasgn and expression[1] == var
|
181
|
+
assignments << n
|
182
|
+
end
|
183
|
+
end
|
184
|
+
raise "this should never happen (yes, really!)" unless assignments.size == 1
|
185
|
+
|
186
|
+
code_block = code[assignments.first]
|
187
|
+
code.delete_at(assignments.first)
|
188
|
+
|
189
|
+
# now inject code
|
190
|
+
inline.clear
|
191
|
+
inline[0] = code_block[0]
|
192
|
+
inline[1] = code_block[1]
|
193
|
+
inline[2] = code_block[2]
|
194
|
+
end
|
195
|
+
end
|
148
196
|
|
149
197
|
end
|
150
198
|
|
data/linguify.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "linguify"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Patrick Hanevold"]
|
12
|
-
s.date = "2012-01-
|
12
|
+
s.date = "2012-01-29"
|
13
13
|
s.description = "Linguify is a linguistic compiler allowing you to compile and execute plain english."
|
14
14
|
s.email = "patrick.hanevold@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
s.homepage = "http://github.com/patrickhno/linguify"
|
36
36
|
s.licenses = ["MIT"]
|
37
37
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = "1.8.
|
38
|
+
s.rubygems_version = "1.8.15"
|
39
39
|
s.summary = "Linguify, the linguistic compiler."
|
40
40
|
|
41
41
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: linguify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.6.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Patrick Hanevold
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-01-
|
13
|
+
date: 2012-01-29 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sourcify
|
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
hash:
|
118
|
+
hash: 4095864458397770704
|
119
119
|
segments:
|
120
120
|
- 0
|
121
121
|
version: "0"
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
requirements: []
|
129
129
|
|
130
130
|
rubyforge_project:
|
131
|
-
rubygems_version: 1.8.
|
131
|
+
rubygems_version: 1.8.15
|
132
132
|
signing_key:
|
133
133
|
specification_version: 3
|
134
134
|
summary: Linguify, the linguistic compiler.
|