lab42_speculate 0.0.3 → 0.0.4
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/speculate/parser.rb +41 -5
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ae8fccbf72391d3ec45a9470262785573cc80b7b7282f4b684018b60d0c62383
|
|
4
|
+
data.tar.gz: ec022144c0496bd3d10a39f667381cc30350d8e4bee7e47fc940707ea9df6b14
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f386d26706ce373c5f5725275707d2d8c4710deade8062a5decd284dfaaebf08ce79758b6d398a5f46117f2dadc11a0043771f6f852df690aa685a869585266
|
|
7
|
+
data.tar.gz: eb927a6c6b7d7d6eb7f5c94876953ea8138f05e662cd31d1564ec87f5b8ebb38eab58ff60d56af0dfdd489ac8f7a9770286a96e3067d1b150f1afbed53e7fab2
|
data/lib/speculate/parser.rb
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
class Speculate::Parser
|
|
2
2
|
Error = Class.new RuntimeError
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
AROUND_END_RGX = %r{\A\s{0,3}(?:```|~~~)\s*\z}
|
|
5
|
+
AROUND_PLACEHOLDER_RGX = %r{\A\s*\.\.\.+\s*\z}
|
|
6
|
+
AROUND_START_RGX = %r{\A\s{0,3}(?:```|~~~)(.*)\baround}
|
|
7
|
+
SPECULATION_END_RGX = %r{\A\s{0,3}(?:```|~~~)\s*\z}
|
|
8
|
+
SPECULATION_START_RGX = %r{\A\s{0,3}(?:```|~~~)(.*)\bspeculate}
|
|
6
9
|
|
|
7
10
|
attr_reader :state, :stream
|
|
8
11
|
|
|
9
12
|
def parse
|
|
10
13
|
@state = :outer
|
|
11
14
|
_parse
|
|
12
|
-
lines
|
|
15
|
+
before + lines + after
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
|
|
@@ -25,16 +28,26 @@ class Speculate::Parser
|
|
|
25
28
|
|
|
26
29
|
# Memos
|
|
27
30
|
# =====
|
|
31
|
+
def after
|
|
32
|
+
@__after__ ||= []
|
|
33
|
+
end
|
|
34
|
+
def before
|
|
35
|
+
@__before__ ||= []
|
|
36
|
+
end
|
|
28
37
|
def lines
|
|
29
38
|
@__lines__ ||= []
|
|
30
39
|
end
|
|
31
40
|
|
|
32
|
-
|
|
33
41
|
# Parser
|
|
34
42
|
# ======
|
|
35
43
|
def _parse
|
|
36
44
|
stream.each do |line|
|
|
45
|
+
# puts ":#{state} #{line}"
|
|
37
46
|
case state
|
|
47
|
+
when :after
|
|
48
|
+
_parse_after line
|
|
49
|
+
when :before
|
|
50
|
+
_parse_before line
|
|
38
51
|
when :outer
|
|
39
52
|
_parse_outer line
|
|
40
53
|
when :inner
|
|
@@ -45,6 +58,26 @@ class Speculate::Parser
|
|
|
45
58
|
end
|
|
46
59
|
end
|
|
47
60
|
|
|
61
|
+
def _parse_after line
|
|
62
|
+
case line
|
|
63
|
+
when AROUND_END_RGX
|
|
64
|
+
@state = :outer
|
|
65
|
+
else
|
|
66
|
+
after << line
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def _parse_before line
|
|
71
|
+
case line
|
|
72
|
+
when AROUND_PLACEHOLDER_RGX
|
|
73
|
+
@state = :after
|
|
74
|
+
when AROUND_END_RGX
|
|
75
|
+
@state = :outer
|
|
76
|
+
else
|
|
77
|
+
before << line
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
48
81
|
def _parse_inner line
|
|
49
82
|
if SPECULATION_END_RGX =~ line
|
|
50
83
|
@state = :outer
|
|
@@ -54,7 +87,10 @@ class Speculate::Parser
|
|
|
54
87
|
end
|
|
55
88
|
|
|
56
89
|
def _parse_outer line
|
|
57
|
-
|
|
90
|
+
case line
|
|
91
|
+
when AROUND_START_RGX
|
|
92
|
+
@state = :before
|
|
93
|
+
when SPECULATION_START_RGX
|
|
58
94
|
@state = :inner
|
|
59
95
|
end
|
|
60
96
|
end
|