fictive 0.0.5 → 0.0.6
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/lib/fictive/text/compiler.rb +43 -19
- data/lib/fictive/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: 07df70dcf2a31222db91cd582c21addbee6b877e
|
4
|
+
data.tar.gz: 14edd07192ae1f6bba9fd48046da469c28e03b03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82c12bd352ef15873184cea36a65a7d4af81c03c227b705d4b6e978314152b615531cbe630f6bbc89fc10c19955f87a9301a00472a24e68f83bf6bbd15a7bc96
|
7
|
+
data.tar.gz: ed8fc5bd88d84960eca09dcf941f974c1fbe5c0f5f4c199eea6bb0f58b875c5d47a769429ccbf3567f5472808bf86267ab7e7672bfbb39ec6908a2fc456a2400
|
@@ -10,44 +10,61 @@ module Fictive
|
|
10
10
|
def process
|
11
11
|
@scanner = StringScanner.new(@input)
|
12
12
|
|
13
|
-
Fictive::Text::Node.new(*
|
13
|
+
Fictive::Text::Node.new(*parse_fragments)
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
18
|
attr_reader :scanner
|
19
19
|
|
20
|
+
def parse_fragments
|
21
|
+
fragments = []
|
22
|
+
fragments << parse_fragment while !scanner.eos?
|
23
|
+
fragments
|
24
|
+
end
|
25
|
+
|
20
26
|
def parse_fragment
|
21
27
|
concat_fragment = scanner.scan_until(/{/)
|
22
28
|
|
23
29
|
if concat_fragment
|
24
|
-
|
30
|
+
Fictive::Text::Node.new(Fictive::Text::TextNode.new(concat_fragment.gsub(/{/, '')), parse_substitution)
|
25
31
|
else
|
26
|
-
|
27
|
-
|
32
|
+
concat_before_directive = scanner.scan_until(/~/)
|
33
|
+
|
34
|
+
if concat_before_directive
|
35
|
+
Fictive::Text::Node.new(Fictive::Text::TextNode.new(concat_before_directive.gsub(/~/, '')), parse_directive)
|
36
|
+
else
|
37
|
+
fragment = scanner.scan(/.+/)
|
38
|
+
Fictive::Text::TextNode.new(fragment)
|
39
|
+
end
|
28
40
|
end
|
29
41
|
end
|
30
42
|
|
31
|
-
def
|
32
|
-
if scanner.scan(/
|
33
|
-
|
34
|
-
|
35
|
-
parse_substitution
|
36
|
-
end
|
43
|
+
def parse_directive
|
44
|
+
return parse_conditional if scanner.scan(/if/)
|
45
|
+
|
46
|
+
raise 'Invalid syntax'
|
37
47
|
end
|
38
48
|
|
39
|
-
def
|
40
|
-
scanner.skip(/\s
|
49
|
+
def parse_substitution
|
50
|
+
scanner.skip(/\s/)
|
41
51
|
|
42
|
-
|
52
|
+
if reference = scanner.scan(/[A-Za-z0-9_\-!]/)
|
53
|
+
Fictive::Text::ReferenceNode.new(reference, {})
|
54
|
+
else
|
55
|
+
raise 'Invalid syntax'
|
56
|
+
end
|
57
|
+
|
58
|
+
scanner.skip(/\s*}/)
|
43
59
|
end
|
44
60
|
|
45
61
|
def parse_conditional
|
46
62
|
raise 'missing whitespace in conditional tag' unless scanner.scan(/\s+/)
|
47
63
|
|
48
64
|
expression = parse_expression
|
49
|
-
scanner.skip(
|
50
|
-
|
65
|
+
scanner.skip(/:/)
|
66
|
+
scanner.skip(/\s/)
|
67
|
+
consequent = scanner.scan_until(/~/).gsub(/~/, '')
|
51
68
|
|
52
69
|
Fictive::Text::ConditionalNode.new(
|
53
70
|
Fictive::Text::ExpressionNode.new(
|
@@ -60,10 +77,6 @@ module Fictive
|
|
60
77
|
def parse_expression
|
61
78
|
Fictive::Text::TrueNode.new if scanner.scan(/true/)
|
62
79
|
end
|
63
|
-
|
64
|
-
def parse_substitution
|
65
|
-
|
66
|
-
end
|
67
80
|
end
|
68
81
|
|
69
82
|
class Node
|
@@ -88,6 +101,17 @@ module Fictive
|
|
88
101
|
end
|
89
102
|
end
|
90
103
|
|
104
|
+
class ReferenceNode
|
105
|
+
def initialize(reference, symbol_table)
|
106
|
+
@reference = reference
|
107
|
+
@symbol_table = symbol_table
|
108
|
+
end
|
109
|
+
|
110
|
+
def evaluate
|
111
|
+
@symbol_table.fetch(@reference)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
91
115
|
class ConditionalNode
|
92
116
|
# TODO: decide on array or explicit parameter convention
|
93
117
|
# eg: initialize(condition, consequent, alternative)
|
data/lib/fictive/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fictive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
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-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|