speculate_about 0.1.1 → 0.1.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/lib/speculate_about.rb +3 -3
- data/lib/speculations/parser.rb +4 -3
- data/lib/speculations/parser/context.rb +10 -9
- data/lib/speculations/parser/context/example.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6c603b51bd04471204c4584fb1697f5a27dd7b578abd012c805046e7d9a49dc
|
4
|
+
data.tar.gz: 82f31cc63352e6d3c380b860a40a1f84a2f133b7b4f8a391363176f57d808415
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd30e3a46232a0d38b0d0725aa89df98f7d724faef50e350e3bacf106c552e279569087b830f93a656015dca03f5fe1e0ff0c511484a2c12ac3331ebb8e5c51a
|
7
|
+
data.tar.gz: f48a6400a5bd1d6971780e5c8261d957b64af79c96baa544dd21b4050240343da77bc48141b4d0097da32ee4ee4ff5d065c7d3aa0df65584a71caf99b4724d09
|
data/lib/speculate_about.rb
CHANGED
@@ -5,15 +5,15 @@ require 'speculations/parser'
|
|
5
5
|
module SpeculateAbout
|
6
6
|
def speculate_about file
|
7
7
|
path = _find_file(file, File.dirname( caller.first ))
|
8
|
-
code = _compile path
|
8
|
+
code = _compile path, file
|
9
9
|
ENV["SPECULATE_ABOUT_DEBUG"] ? puts(code) : instance_eval(code)
|
10
10
|
end
|
11
11
|
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
-
def _compile path
|
16
|
-
ast = Speculations::Parser.new.parse_from_file(path)
|
15
|
+
def _compile path, file
|
16
|
+
ast = Speculations::Parser.new.parse_from_file(path, file)
|
17
17
|
ast.to_code
|
18
18
|
end
|
19
19
|
def _find_file file, local_path
|
data/lib/speculations/parser.rb
CHANGED
@@ -3,7 +3,7 @@ class Speculations::Parser
|
|
3
3
|
require_relative './parser/context'
|
4
4
|
require_relative './parser/state'
|
5
5
|
|
6
|
-
attr_reader :filename, :input, :root, :state
|
6
|
+
attr_reader :filename, :input, :orig_filename, :root, :state
|
7
7
|
|
8
8
|
def self.parsers
|
9
9
|
@__parsers__ ||= {
|
@@ -14,8 +14,9 @@ class Speculations::Parser
|
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
17
|
-
def parse_from_file file
|
17
|
+
def parse_from_file file, orig_filename = nil
|
18
18
|
@filename = file
|
19
|
+
@orig_filename = orig_filename || file
|
19
20
|
@input = File
|
20
21
|
.new(file)
|
21
22
|
.each_line(chomp: true)
|
@@ -30,7 +31,7 @@ class Speculations::Parser
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def parse!
|
33
|
-
root = node = Context.new(name: "Speculations from #{@filename}", lnb: 0, filename: @filename, parent: nil)
|
34
|
+
root = node = Context.new(name: "Speculations from #{@filename}", lnb: 0, filename: @filename, orig_filename: orig_filename, parent: nil)
|
34
35
|
input.each_with_index do |line, lnb|
|
35
36
|
@state, node = self.class.parsers.fetch(@state).parse(line, lnb.succ, node)
|
36
37
|
end
|
@@ -3,7 +3,7 @@ class Speculations::Parser::Context
|
|
3
3
|
require_relative './context/example'
|
4
4
|
require_relative './context/setup'
|
5
5
|
|
6
|
-
attr_reader :filename, :level, :lnb, :name, :parent, :setup
|
6
|
+
attr_reader :filename, :level, :lnb, :name, :orig_filename, :parent, :setup
|
7
7
|
|
8
8
|
def add_child(name:, lnb:)
|
9
9
|
raise "Illegal nesting" if parent
|
@@ -55,21 +55,22 @@ class Speculations::Parser::Context
|
|
55
55
|
|
56
56
|
private
|
57
57
|
|
58
|
-
def initialize(lnb:, name:, filename: nil, parent: nil)
|
59
|
-
_init_from_parent filename, parent
|
60
|
-
@level
|
61
|
-
@lnb
|
62
|
-
@setup
|
63
|
-
@name
|
64
|
-
@parent
|
58
|
+
def initialize(lnb:, name:, filename: nil, orig_filename: nil, parent: nil)
|
59
|
+
_init_from_parent filename, orig_filename, parent
|
60
|
+
@level = parent ? parent.level.succ : 1
|
61
|
+
@lnb = lnb
|
62
|
+
@setup = nil
|
63
|
+
@name = name
|
64
|
+
@parent = parent
|
65
65
|
end
|
66
66
|
|
67
67
|
def _header
|
68
68
|
map_lines(%{context "#{name}" do}, indent: -1)
|
69
69
|
end
|
70
70
|
|
71
|
-
def _init_from_parent filename, parent
|
71
|
+
def _init_from_parent filename, orig_filename, parent
|
72
72
|
@filename = parent ? parent.filename : filename
|
73
|
+
@orig_filename = parent ? parent.orig_filename : orig_filename
|
73
74
|
raise ArgumentError, "no filename given in root context" unless @filename
|
74
75
|
end
|
75
76
|
|
@@ -34,9 +34,9 @@ class Speculations::Parser::Context::Example
|
|
34
34
|
_, name = NAMED_EXAMPLE.match(line).to_a
|
35
35
|
|
36
36
|
if name&.empty? == false # SIC
|
37
|
-
"#{name} (#{
|
37
|
+
"#{name} (#{parent.orig_filename}:#{lnb.succ})"
|
38
38
|
else
|
39
|
-
"Example from #{parent.
|
39
|
+
"Example from #{parent.orig_filename}:#{lnb.succ}"
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: speculate_about
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|