calyx 0.9.1 → 0.9.2

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: 870b438756c9199fdf30b72058d42ce178cf1b82
4
- data.tar.gz: 7c6b71e8512d6a26d3f2643dc5efa126a03212bf
3
+ metadata.gz: 96d0d3ad96525f74b2526c8ef7d2011655773cb4
4
+ data.tar.gz: e6c01ff177c34a1768e215fc2294494689cdf731
5
5
  SHA512:
6
- metadata.gz: 259a6fdcca7b525cbb6fa095e6d7b7be54248c145f34213d8f3a725716cebe93814a76cd054d6f5ef79fd694cf5e2679242289e195510360dba881775d0b95fa
7
- data.tar.gz: 5773c867c7364309c162aa5c0de4a02dd72663aea2ff5444a67fad59dcb09cd2afbb9faef0719312ff51642f1e8196e63e7937a6a1c40d8ff08ec8dd2f8270d0
6
+ metadata.gz: 9ac277b2883c2e2e68ac44bdae1387d2c61ad55353fc0c227f38f70f551916e6a9d3987f40e4ef0815af5eec19082de19596671d516d00593e6884be9ed7057c
7
+ data.tar.gz: ab1d40f0c27cabf7064fe39e1c6775e85a6e78592b3c74467fdd43780db4f69c39f4e631442761834f63a297b59d2c0f8f21ce07abc23fd67bcb67e082a8ccbe
@@ -0,0 +1,15 @@
1
+ require "calyx"
2
+
3
+ tiny_woodland = Calyx::Grammar.new do
4
+ start :field
5
+ field (0..7).map { "{row}{br}" }.join
6
+ row (0..18).map { "{point}" }.join
7
+ point [:trees, 0.2], [:foliage, 0.25], [:flowers, 0.05], [:space, 0.5]
8
+ trees "🌲", "🌳"
9
+ foliage "🌿", "🌱"
10
+ flowers "🌷", "🌻", "🌼"
11
+ space " "
12
+ br "\n"
13
+ end
14
+
15
+ puts tiny_woodland.generate
data/lib/calyx.rb CHANGED
@@ -1,11 +1,11 @@
1
- require_relative 'calyx/version'
2
- require_relative 'calyx/grammar'
3
- require_relative 'calyx/file_converter'
4
- require_relative 'calyx/grammar/registry'
5
- require_relative 'calyx/grammar/production/memo'
6
- require_relative 'calyx/grammar/production/choices'
7
- require_relative 'calyx/grammar/production/concat'
8
- require_relative 'calyx/grammar/production/expression'
9
- require_relative 'calyx/grammar/production/non_terminal'
10
- require_relative 'calyx/grammar/production/terminal'
11
- require_relative 'calyx/grammar/production/weighted_choices'
1
+ require 'calyx/version'
2
+ require 'calyx/grammar'
3
+ require 'calyx/file_converter'
4
+ require 'calyx/grammar/registry'
5
+ require 'calyx/grammar/production/memo'
6
+ require 'calyx/grammar/production/choices'
7
+ require 'calyx/grammar/production/concat'
8
+ require 'calyx/grammar/production/expression'
9
+ require 'calyx/grammar/production/non_terminal'
10
+ require 'calyx/grammar/production/terminal'
11
+ require 'calyx/grammar/production/weighted_choices'
@@ -2,7 +2,7 @@ module Calyx
2
2
  class Grammar
3
3
  module Production
4
4
  class Concat
5
- EXPRESSION = /(\{[A-Za-z0-9_\.]+\})/.freeze
5
+ EXPRESSION = /(\{[A-Za-z0-9_@\.]+\})/.freeze
6
6
  START_TOKEN = '{'.freeze
7
7
  END_TOKEN = '}'.freeze
8
8
  DEREF_TOKEN = '.'.freeze
@@ -12,7 +12,11 @@ module Calyx
12
12
  if atom.is_a?(String)
13
13
  if atom.chars.first == START_TOKEN && atom.chars.last == END_TOKEN
14
14
  head, *tail = atom.slice(1, atom.length-2).split(DEREF_TOKEN)
15
- rule = NonTerminal.new(head, registry)
15
+ if head[0] == Memo::SIGIL
16
+ rule = Memo.new(head, registry)
17
+ else
18
+ rule = NonTerminal.new(head, registry)
19
+ end
16
20
  unless tail.empty?
17
21
  Expression.new(rule, tail)
18
22
  else
@@ -21,8 +25,6 @@ module Calyx
21
25
  else
22
26
  Terminal.new(atom)
23
27
  end
24
- elsif atom.is_a?(Symbol)
25
- NonTerminal.new(atom, registry)
26
28
  end
27
29
  end
28
30
 
@@ -10,7 +10,7 @@ module Calyx
10
10
  end
11
11
 
12
12
  def evaluate
13
- @result ||= [@symbol, @registry.expand(@symbol).evaluate]
13
+ [@symbol, @registry.memoize_expansion(@symbol)]
14
14
  end
15
15
  end
16
16
  end
@@ -1,10 +1,11 @@
1
1
  module Calyx
2
2
  class Grammar
3
3
  class Registry
4
- attr_reader :rules
4
+ attr_reader :rules, :memos
5
5
 
6
6
  def initialize
7
7
  @rules = {}
8
+ @memos = {}
8
9
  end
9
10
 
10
11
  def method_missing(name, *arguments)
@@ -19,6 +20,10 @@ module Calyx
19
20
  @rules[symbol] || @context[symbol]
20
21
  end
21
22
 
23
+ def memoize_expansion(symbol)
24
+ memos[symbol] ||= expand(symbol).evaluate
25
+ end
26
+
22
27
  def combine(registry)
23
28
  @rules = rules.merge(registry.rules)
24
29
  end
data/lib/calyx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Calyx
2
- VERSION = '0.9.1'.freeze
2
+ VERSION = '0.9.2'.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.9.1
4
+ version: 0.9.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-04-12 00:00:00.000000000 Z
11
+ date: 2016-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,6 +67,7 @@ files:
67
67
  - LICENSE
68
68
  - README.md
69
69
  - calyx.gemspec
70
+ - examples/tiny_woodland.rb
70
71
  - lib/calyx.rb
71
72
  - lib/calyx/file_converter.rb
72
73
  - lib/calyx/grammar.rb