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 +4 -4
- data/examples/tiny_woodland.rb +15 -0
- data/lib/calyx.rb +11 -11
- data/lib/calyx/grammar/production/concat.rb +6 -4
- data/lib/calyx/grammar/production/memo.rb +1 -1
- data/lib/calyx/grammar/registry.rb +6 -1
- data/lib/calyx/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96d0d3ad96525f74b2526c8ef7d2011655773cb4
|
4
|
+
data.tar.gz: e6c01ff177c34a1768e215fc2294494689cdf731
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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_
|
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
|
-
|
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
|
|
@@ -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
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.
|
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-
|
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
|