calyx 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +2 -2
- data/lib/calyx.rb +8 -9
- data/lib/calyx/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e0af61453ee9d96b61daf9255a322023510eda0
|
4
|
+
data.tar.gz: 1beb02a6c87b667587fc3cae9e05852e52d253b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d844ef847d5a1e7fa00f75d252f666ad183740a39537ff0441df3def2e2768c2daff09399364e794a08c64e03ded3b06ddb1b9fce14fd72d8ec2edfe40b4ea39
|
7
|
+
data.tar.gz: e10899e3abac20855a2a10f616d53ffe75b2f72d9751503cf9e6a17d2e19595c28924ed289b01c1734f7d32e9d53065f83c391842e3680af7784acbb88aec6f2
|
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2015
|
3
|
+
Copyright (c) 2015-2016 Editorial Technology <http://editorial.technology>
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -114,7 +114,7 @@ end
|
|
114
114
|
|
115
115
|
### Random Sampling
|
116
116
|
|
117
|
-
By default, the outcomes of generated rules are selected with Ruby’s built-in pseudorandom number generator (as seen in methods like `Kernel.rand` and `Array.sample`). To seed the random number generator, pass in
|
117
|
+
By default, the outcomes of generated rules are selected with Ruby’s built-in pseudorandom number generator (as seen in methods like `Kernel.rand` and `Array.sample`). To seed the random number generator, pass in an integer seed value as the first argument to the constructor:
|
118
118
|
|
119
119
|
```ruby
|
120
120
|
MyGrammar.new(12345)
|
@@ -259,6 +259,6 @@ Rough plan for stabilising the API and features for a `1.0` release.
|
|
259
259
|
|
260
260
|
## License
|
261
261
|
|
262
|
-
Calyx is open source and provided under the terms of the MIT license. Copyright (c) 2015
|
262
|
+
Calyx is open source and provided under the terms of the MIT license. Copyright (c) 2015-2016 [Editorial Technology](http://editorial.technology/).
|
263
263
|
|
264
264
|
See the `LICENSE` file [included with the project distribution](https://github.com/maetl/calyx/blob/master/LICENSE) for more information.
|
data/lib/calyx.rb
CHANGED
@@ -7,8 +7,8 @@ module Calyx
|
|
7
7
|
@rules = {}
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def method_missing(name, *arguments)
|
11
|
+
rule(name, *arguments)
|
12
12
|
end
|
13
13
|
|
14
14
|
def rule(name, *productions, &production)
|
@@ -23,7 +23,7 @@ module Calyx
|
|
23
23
|
@rules = rules.merge(registry.rules)
|
24
24
|
end
|
25
25
|
|
26
|
-
def evaluate(context={})
|
26
|
+
def evaluate(start_symbol=:start, context={})
|
27
27
|
duplicate_registry = Marshal.load(Marshal.dump(self))
|
28
28
|
duplicate_rules = duplicate_registry.rules
|
29
29
|
context.each do |key, value|
|
@@ -38,7 +38,7 @@ module Calyx
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
duplicate_rules[
|
41
|
+
duplicate_rules[start_symbol].evaluate
|
42
42
|
end
|
43
43
|
|
44
44
|
private
|
@@ -58,7 +58,7 @@ module Calyx
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def start(*productions, &production)
|
61
|
-
registry.start
|
61
|
+
registry.rule(:start, *productions)
|
62
62
|
end
|
63
63
|
|
64
64
|
def rule(name, *productions, &production)
|
@@ -203,20 +203,19 @@ module Calyx
|
|
203
203
|
end
|
204
204
|
|
205
205
|
def initialize(seed=nil, &block)
|
206
|
-
@seed = seed
|
207
|
-
@seed = Time.new.to_i unless @seed
|
206
|
+
@seed = seed || Random.new_seed
|
208
207
|
srand(@seed)
|
209
208
|
|
210
209
|
if block_given?
|
211
210
|
@registry = Registry.new
|
212
211
|
@registry.instance_eval(&block)
|
213
212
|
else
|
214
|
-
@registry = self.class.registry
|
213
|
+
@registry = self.class.registry
|
215
214
|
end
|
216
215
|
end
|
217
216
|
|
218
217
|
def generate(context={})
|
219
|
-
@registry.evaluate(context)
|
218
|
+
@registry.evaluate(:start, context)
|
220
219
|
end
|
221
220
|
end
|
222
221
|
end
|
data/lib/calyx/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calyx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rickerby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|