calyx 0.8.3 → 0.9.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.
- checksums.yaml +4 -4
- data/README.md +21 -2
- data/lib/calyx/grammar.rb +17 -3
- 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: 679eb1cd31045fb4f4603dc28566d7d833486c62
|
4
|
+
data.tar.gz: ba1a2640bc31bfc67d5b354576444e901eb1280f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ad76734b34a1e5483b8da959ec2b8d9658c20e174f86cf1f000d2db0a958e7261519731b2bc46059406d38b540c372f278b619fb78c2cc6c77e288a38d059e1
|
7
|
+
data.tar.gz: 85d7f3bfd3236406c0a27c075a427527c8dc48c7d2c212187b5af386227ff39138215b58d7b9284959838461a2d5d37d4cfacbe24d633b040f142641474f424d
|
data/README.md
CHANGED
@@ -236,7 +236,26 @@ greeting = AppGreeting.new
|
|
236
236
|
greeting.generate(context)
|
237
237
|
```
|
238
238
|
|
239
|
-
__Note:
|
239
|
+
__Note: The API may morph and change a bit as we try to figure out the best patterns for merging and combining grammars.__
|
240
|
+
|
241
|
+
### Accessing the Raw Generated Tree
|
242
|
+
|
243
|
+
Calling `#evaluate` on the grammar instance will give you access to the raw generated tree structure before it gets flattened into a string.
|
244
|
+
|
245
|
+
The tree is encoded as an array of nested arrays, with the leading symbols labeling the choices and rules selected, and the trailing terminal leaves encoding string values.
|
246
|
+
|
247
|
+
This may not make a lot of sense unless you’re familiar with the concept of [s-expressions](https://en.wikipedia.org/wiki/S-expression). It’s a fairly speculative feature at this stage, but it leads to some interesting possibilities.
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
grammar = Calyx::Grammar.new do
|
251
|
+
start 'Riddle me ree.'
|
252
|
+
end
|
253
|
+
|
254
|
+
grammar.evaluate
|
255
|
+
# => [:start, [:term, "Riddle me ree."]]
|
256
|
+
```
|
257
|
+
|
258
|
+
__Note: This feature is still experimental. The tree structure is likely to change so it’s probably best not to rely on it for anything big at this stage.__
|
240
259
|
|
241
260
|
## Roadmap
|
242
261
|
|
@@ -247,7 +266,7 @@ Rough plan for stabilising the API and features for a `1.0` release.
|
|
247
266
|
| `0.6` | ~~block constructor~~ |
|
248
267
|
| `0.7` | ~~support for template context map passed to generate~~ |
|
249
268
|
| `0.8` | ~~method missing metaclass API~~ |
|
250
|
-
| `0.9` | return grammar tree from evaluate
|
269
|
+
| `0.9` | ~~return grammar tree from `#evaluate`, with flattened string from `#generate` being separate~~ |
|
251
270
|
| `0.10` | inject custom string functions for parameterised rules, transforms and mappings |
|
252
271
|
| `0.11` | support YAML format (and JSON?) |
|
253
272
|
| `1.0` | API documentation |
|
data/lib/calyx/grammar.rb
CHANGED
@@ -35,6 +35,22 @@ module Calyx
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def generate(*args)
|
38
|
+
start_symbol, rules_map = map_default_args(*args)
|
39
|
+
|
40
|
+
@registry.evaluate(start_symbol, rules_map).flatten.reject do |obj|
|
41
|
+
obj.is_a?(Symbol)
|
42
|
+
end.join(''.freeze)
|
43
|
+
end
|
44
|
+
|
45
|
+
def evaluate(*args)
|
46
|
+
start_symbol, rules_map = map_default_args(*args)
|
47
|
+
|
48
|
+
@registry.evaluate(start_symbol, rules_map)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def map_default_args(*args)
|
38
54
|
start_symbol = :start
|
39
55
|
rules_map = {}
|
40
56
|
|
@@ -43,9 +59,7 @@ module Calyx
|
|
43
59
|
rules_map = arg if arg.class == Hash
|
44
60
|
end
|
45
61
|
|
46
|
-
|
47
|
-
obj.is_a?(Symbol)
|
48
|
-
end.join(''.freeze)
|
62
|
+
[start_symbol, rules_map]
|
49
63
|
end
|
50
64
|
end
|
51
65
|
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.
|
4
|
+
version: 0.9.0
|
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-04-
|
11
|
+
date: 2016-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|