fictive 0.0.4 → 0.0.5
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 +62 -2
- 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: bbcae9d32392a059f5bd147d25d81c8777107831
|
4
|
+
data.tar.gz: 149c43598f3649abd697c29a1ba87b3de1b0365f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0097631f0c9eade4357be2c8ea70859de55c93a4d069c5a8a0dad7f3ee2a88776dfc97b97c756b269db534c20f252162d0aefff2b6e714672a0377e9fd8fe11b
|
7
|
+
data.tar.gz: 61185da18fb82a7650ad29ab17e85528382067a9a2828f6819fd489a2687825ae17c27e4b4e310233aec4441bd7ec75813882812836517b8c6c44749ac72bf3b
|
@@ -1,8 +1,68 @@
|
|
1
|
+
require 'strscan'
|
2
|
+
|
1
3
|
module Fictive
|
2
4
|
module Text
|
3
5
|
class Compiler
|
4
|
-
def initialize(
|
5
|
-
@
|
6
|
+
def initialize(input)
|
7
|
+
@input = input
|
8
|
+
end
|
9
|
+
|
10
|
+
def process
|
11
|
+
@scanner = StringScanner.new(@input)
|
12
|
+
|
13
|
+
Fictive::Text::Node.new(*parse_fragment)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :scanner
|
19
|
+
|
20
|
+
def parse_fragment
|
21
|
+
concat_fragment = scanner.scan_until(/{/)
|
22
|
+
|
23
|
+
if concat_fragment
|
24
|
+
[Fictive::Text::TextNode.new(concat_fragment.gsub(/{/, '')), parse_delimiter]
|
25
|
+
else
|
26
|
+
fragment = scanner.scan(/.+/)
|
27
|
+
Fictive::Text::TextNode.new(fragment)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_delimiter
|
32
|
+
if scanner.scan(/{/)
|
33
|
+
parse_tag
|
34
|
+
else
|
35
|
+
parse_substitution
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_tag
|
40
|
+
scanner.skip(/\s+/)
|
41
|
+
|
42
|
+
parse_conditional if scanner.scan(/if/)
|
43
|
+
end
|
44
|
+
|
45
|
+
def parse_conditional
|
46
|
+
raise 'missing whitespace in conditional tag' unless scanner.scan(/\s+/)
|
47
|
+
|
48
|
+
expression = parse_expression
|
49
|
+
scanner.skip(/}}/)
|
50
|
+
consequent = scanner.scan_until(/{{\/if}}/).gsub(/{{\/if}}/, '')
|
51
|
+
|
52
|
+
Fictive::Text::ConditionalNode.new(
|
53
|
+
Fictive::Text::ExpressionNode.new(
|
54
|
+
expression
|
55
|
+
),
|
56
|
+
Fictive::Text::TextNode.new(consequent)
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse_expression
|
61
|
+
Fictive::Text::TrueNode.new if scanner.scan(/true/)
|
62
|
+
end
|
63
|
+
|
64
|
+
def parse_substitution
|
65
|
+
|
6
66
|
end
|
7
67
|
end
|
8
68
|
|
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.5
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|