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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3e641762dd894b48936eb9e945531b94be732b4
4
- data.tar.gz: 0875b1def9d94ae12c2685f92a1fabd418b27853
3
+ metadata.gz: 679eb1cd31045fb4f4603dc28566d7d833486c62
4
+ data.tar.gz: ba1a2640bc31bfc67d5b354576444e901eb1280f
5
5
  SHA512:
6
- metadata.gz: 735ff80c2e8c154c07aa3344c4717c91212a5734ae79c03289d7b741b87e0b60a1c813fa5294733db6697e96fb443b2dce7938565893ab9744bbfb721aebd00b
7
- data.tar.gz: abcfc630585f97fb81753f9fd77fbba90e3cc1399a396626c468d3ab30fe50dcb70829525962e527212ee174f60005aa2dc3fed440f5c82934f8b9dd4de4d823
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: This feature is still experimental, and the API may morph and change a bit as we try to figure out the best patterns for merging and combining grammars.__
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/generate, with to_s being separate |
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 |
@@ -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
- @registry.evaluate(start_symbol, rules_map).flatten.reject do |obj|
47
- obj.is_a?(Symbol)
48
- end.join(''.freeze)
62
+ [start_symbol, rules_map]
49
63
  end
50
64
  end
51
65
  end
@@ -1,3 +1,3 @@
1
1
  module Calyx
2
- VERSION = '0.8.3'.freeze
2
+ VERSION = '0.9.0'.freeze
3
3
  end
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.8.3
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-07 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler