kotodama 1.2.2 → 1.2.3
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/lib/kotodama.rb +1 -1
- data/lib/kotodama_grammar.rb +1 -1
- data/lib/kotodama_grammar.rb~ +181 -0
- metadata +5 -16
data/lib/kotodama.rb
CHANGED
data/lib/kotodama_grammar.rb
CHANGED
@@ -0,0 +1,181 @@
|
|
1
|
+
module Kotodama
|
2
|
+
GRAMMAR = Kaiseki::Grammar.new do
|
3
|
+
starting :document
|
4
|
+
skipping :WS | :COMMENT
|
5
|
+
|
6
|
+
rule :document do
|
7
|
+
parses proc { @language = Language.new } & :options_block.optional & :content_block.zero_or_more & :EOF.skip
|
8
|
+
filter { @language }
|
9
|
+
end
|
10
|
+
|
11
|
+
rule :options_block do
|
12
|
+
parses 'options'.skip & '{'.skip & :option.zero_or_more & '}'.skip
|
13
|
+
end
|
14
|
+
|
15
|
+
rule :option do
|
16
|
+
parses :LITERAL & '=>'.skip & (:ATOM | :INT) & ';'.skip
|
17
|
+
node [:key, :value]
|
18
|
+
action do
|
19
|
+
@language.options[@key] = @value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
rule :content_block do
|
24
|
+
parses :type_block | :rule_block | :change_block | :spelling_rule | :zipf_block
|
25
|
+
end
|
26
|
+
|
27
|
+
rule :type_block do
|
28
|
+
parses 'type'.skip & :ATOM.set(:id) & :get_type & '{'.skip & :symbol_declaration.zero_or_more & '}'.skip
|
29
|
+
end
|
30
|
+
|
31
|
+
action :get_type do
|
32
|
+
if @language.types.key? @id
|
33
|
+
@type = @language.types[@id]
|
34
|
+
else
|
35
|
+
@type = @language.types[@id] = Type.new(@language)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
rule :symbol_declaration do
|
40
|
+
parses :LIST & :WEIGHT.optional & ';'.skip
|
41
|
+
node [:symbols, :weight]
|
42
|
+
action do
|
43
|
+
@symbols.each {|n| @type.add n, @weight }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
rule :rule_block do
|
48
|
+
parses 'rule'.skip & :ATOM.set(:id) & :get_rule & '{'.skip & (:exclude_expression | :rule_expression).zero_or_more & '}'.skip
|
49
|
+
end
|
50
|
+
|
51
|
+
action :get_rule do
|
52
|
+
if @language.rules.key? @id
|
53
|
+
@rule = @language.rules[@id]
|
54
|
+
else
|
55
|
+
@rule = @language.rules[@id] = Rule.new(@language)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
rule :exclude_expression do
|
60
|
+
parses 'exclude'.skip & :ID.one_or_more & ';'.skip
|
61
|
+
action { @rule.excludes << @result.join }
|
62
|
+
end
|
63
|
+
|
64
|
+
rule :rule_expression do
|
65
|
+
parses :ATOM.one_or_more & :WEIGHT.optional & ';'.skip
|
66
|
+
node [:expression, :weight]
|
67
|
+
action { @rule.add @expression, @weight }
|
68
|
+
end
|
69
|
+
|
70
|
+
rule :change_block do
|
71
|
+
parses 'change'.skip & :ATOM.set(:id) & :get_change & '{'.skip & (:ATOM.set(:id).action { @change.add [:load, @id, nil] } | :sound_change).zero_or_more & '}'.skip
|
72
|
+
end
|
73
|
+
|
74
|
+
action :get_change do
|
75
|
+
if @language.changes.key? @id
|
76
|
+
@change = @language.changes[@id]
|
77
|
+
else
|
78
|
+
@change = @language.changes[@id] = Change.new(@language)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
rule :sound_change do
|
83
|
+
parses (:insert_change | :delete_change | :convert_change) & :change_env.optional & ';'.skip
|
84
|
+
node [:type, :env]
|
85
|
+
action do
|
86
|
+
@type[2] = @env
|
87
|
+
@change.add @type
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
rule :insert_change do
|
92
|
+
parses 'insert'.skip & :ATOM.one_or_more
|
93
|
+
filter { [:insert, (@result.is_a?(Array) ? @result : [@result]), nil] }
|
94
|
+
end
|
95
|
+
|
96
|
+
rule :delete_change do
|
97
|
+
parses 'delete'.skip & :ATOM.one_or_more
|
98
|
+
filter { [:delete, (@result.is_a?(Array) ? @result : [@result]), nil] }
|
99
|
+
end
|
100
|
+
|
101
|
+
rule :convert_change do
|
102
|
+
parses :ATOM.one_or_more & '>'.skip & :ATOM.one_or_more
|
103
|
+
node [:from, :to]
|
104
|
+
filter { [:convert, [@from, @to], nil] }
|
105
|
+
end
|
106
|
+
|
107
|
+
rule :change_env do
|
108
|
+
parses '/'.skip & '#'.optional & :ATOM.zero_or_more & '_'.skip & :ATOM.zero_or_more & '#'.optional
|
109
|
+
end
|
110
|
+
|
111
|
+
rule :spelling_rule do
|
112
|
+
parses 'spell'.skip & :ID & 'as'.skip & :LITERAL & ';'.skip
|
113
|
+
node [:symbol, :spelling]
|
114
|
+
action do
|
115
|
+
@language.spellings[@symbol] = @spelling[1..-1]
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
rule :zipf_block do
|
120
|
+
parses 'zipf'.skip & :FLOAT.set(:float) & '{'.skip & (:LIST & ';'.skip).one_or_more.set(:lists) & '}'.skip
|
121
|
+
action do
|
122
|
+
zipf_list = []
|
123
|
+
@lists.each {|list1| list1.each {|n| zipf_list << n } }
|
124
|
+
zipf_list.length.times do |i|
|
125
|
+
value = 1.0 / (i + 1) ** @float
|
126
|
+
value = (value * 100).to_i
|
127
|
+
@language.zipf[zipf_list[i]] = value
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
rule :ID do
|
133
|
+
parses /[a-zA-Z][0-9]?/
|
134
|
+
filter do
|
135
|
+
if @result.length == 1
|
136
|
+
@result + '0'
|
137
|
+
else
|
138
|
+
@result
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
rule :LIST do
|
144
|
+
parses (:ID & (','.skip & :ID).zero_or_more).merge
|
145
|
+
end
|
146
|
+
|
147
|
+
rule :LITERAL do
|
148
|
+
parses /\"([^"]*)\"/ | /\'([^']*)\'/
|
149
|
+
simplify false
|
150
|
+
filter do
|
151
|
+
'$' + @result.captures[0]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
rule :ATOM do
|
156
|
+
parses :ID | :LITERAL
|
157
|
+
end
|
158
|
+
|
159
|
+
rule :WEIGHT do
|
160
|
+
parses '('.skip & :INT & ')'.skip
|
161
|
+
end
|
162
|
+
|
163
|
+
rule :INT do
|
164
|
+
parses /\d+/
|
165
|
+
cast Integer
|
166
|
+
end
|
167
|
+
|
168
|
+
rule :FLOAT do
|
169
|
+
parses /\d+\.\d+/
|
170
|
+
cast Float
|
171
|
+
end
|
172
|
+
|
173
|
+
rule :WS do
|
174
|
+
parses /\s+/
|
175
|
+
end
|
176
|
+
|
177
|
+
rule :COMMENT do
|
178
|
+
parses /%[^\n]*\n/
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kotodama
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 2
|
8
|
-
- 2
|
9
|
-
version: 1.2.2
|
4
|
+
prerelease:
|
5
|
+
version: 1.2.3
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- William Hamilton-Levi
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-21 00:00:00 -05:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,10 +21,6 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ">="
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 1
|
30
|
-
- 1
|
31
|
-
- 1
|
32
24
|
version: 1.1.1
|
33
25
|
type: :runtime
|
34
26
|
version_requirements: *id001
|
@@ -46,6 +38,7 @@ files:
|
|
46
38
|
- lib/change.rb
|
47
39
|
- lib/rule.rb
|
48
40
|
- lib/mod_array.rb
|
41
|
+
- lib/kotodama_grammar.rb~
|
49
42
|
- lib/language.rb
|
50
43
|
- lib/kotodama.rb
|
51
44
|
- lib/kotodama_grammar.rb
|
@@ -65,21 +58,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
58
|
requirements:
|
66
59
|
- - ">="
|
67
60
|
- !ruby/object:Gem::Version
|
68
|
-
segments:
|
69
|
-
- 0
|
70
61
|
version: "0"
|
71
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
63
|
none: false
|
73
64
|
requirements:
|
74
65
|
- - ">="
|
75
66
|
- !ruby/object:Gem::Version
|
76
|
-
segments:
|
77
|
-
- 0
|
78
67
|
version: "0"
|
79
68
|
requirements: []
|
80
69
|
|
81
70
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.
|
71
|
+
rubygems_version: 1.5.2
|
83
72
|
signing_key:
|
84
73
|
specification_version: 3
|
85
74
|
summary: A programable word generator
|