speculate_about 1.0.2 → 1.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/debugging.rb +18 -0
- data/lib/speculate_about.rb +1 -0
- data/lib/speculations/cli.rb +4 -2
- data/lib/speculations/parser/state/candidate.rb +24 -8
- data/lib/speculations/parser/state/in.rb +6 -2
- data/lib/speculations/parser/state/includes.rb +4 -1
- data/lib/speculations/parser/state/out.rb +5 -1
- data/lib/speculations/parser.rb +12 -7
- data/lib/speculations/version.rb +4 -1
- data/lib/speculations.rb +10 -4
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3be4eb68d6f767c2a376eaf6e7f680b1f0705fff031648c9e700d5f3000280ed
|
4
|
+
data.tar.gz: a9d1aea62f48b208252b0afbc4dab2cf3a3a01bdea7c349ac7e4bca35a110d63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37e09ca45b41fe4e2226fb95e14057b1d8e30b16417ed93af74364bbf4d292977c32cfd8cf0545308a704ef8c36e88fe20d1b80076114e79d4341e0aa8192763
|
7
|
+
data.tar.gz: e4c9988e54c0987af9122252c0cfbd10496dc425dd21c5cdd7df91a672cb4fdeaef2e26301a7c5a132eb841591005d54749fce15f3cb757dbf2c55ce7387d9d8
|
data/lib/debugging.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
puts "defining debug__"
|
5
|
+
def debug__(subject=nil, msg: nil, rtrn: nil, debug:)
|
6
|
+
return rtrn || subject unless debug
|
7
|
+
|
8
|
+
$stderr.puts(msg) if msg
|
9
|
+
$stderr.puts(subject.inspect) if subject
|
10
|
+
rtrn || subject
|
11
|
+
end
|
12
|
+
|
13
|
+
def dbg_match(msg, lnb, debug:)
|
14
|
+
designation = name.split("::").last.downcase
|
15
|
+
debug__(msg: "#{lnb.succ}: #{msg} match in :#{designation}", debug:)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
# SPDX-License-Identifier: Apache-2.0
|
data/lib/speculate_about.rb
CHANGED
data/lib/speculations/cli.rb
CHANGED
@@ -8,6 +8,8 @@ module Speculations
|
|
8
8
|
_usage
|
9
9
|
when "-v", "--version"
|
10
10
|
_version
|
11
|
+
when "-d", "--debug"
|
12
|
+
return _compile_and_maybe_run(args.drop(1), debug: true)
|
11
13
|
else
|
12
14
|
return _compile_and_maybe_run args
|
13
15
|
end
|
@@ -16,11 +18,11 @@ module Speculations
|
|
16
18
|
|
17
19
|
private
|
18
20
|
|
19
|
-
def _compile_and_maybe_run
|
21
|
+
def _compile_and_maybe_run(args, debug: false)
|
20
22
|
require_relative "../speculations"
|
21
23
|
args = Dir.glob(["*.md", "speculations/**/*.md"]) if args.empty?
|
22
24
|
args.each do |input_file|
|
23
|
-
Speculations.compile(input_file)
|
25
|
+
Speculations.compile(input_file, debug:)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -2,31 +2,47 @@ module Speculations
|
|
2
2
|
class Parser
|
3
3
|
module State
|
4
4
|
module Candidate extend self
|
5
|
-
def parse line, lnb, node, ctxt
|
5
|
+
def parse line, lnb, node, ctxt, debug: false
|
6
6
|
case
|
7
7
|
when State.blank_line(line)
|
8
|
+
dbg_match("blank_line", lnb, debug:)
|
8
9
|
[:candidate, node, ctxt]
|
9
10
|
when match = State.context_match(line)
|
10
|
-
|
11
|
-
|
12
|
-
node = new_parent.new_context(title: match[2], lnb: lnb, level: level)
|
13
|
-
[:out, node]
|
11
|
+
dbg_match("context", lnb, debug:)
|
12
|
+
_parse_context(match, lnb:, node:)
|
14
13
|
when match = State.maybe_include(line)
|
14
|
+
dbg_match("maybe_include", lnb, debug:)
|
15
15
|
[:candidate, node, :inc]
|
16
16
|
when match = State.maybe_example(line)
|
17
|
+
dbg_match("maybe_example", lnb, debug:)
|
17
18
|
[:candidate, node, match[:title]]
|
18
19
|
when match = State.ruby_code_block(line)
|
20
|
+
dbg_match("ruby_code_block", lnb, debug:)
|
21
|
+
_parse_ruby_code_block(match, ctxt:, lnb:, node:)
|
22
|
+
else
|
23
|
+
[:out, node]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def _parse_context(match, lnb:, node:)
|
30
|
+
level = match[1].size
|
31
|
+
new_parent = node.parent_of_level(level.pred)
|
32
|
+
node = new_parent.new_context(title: match[2], lnb: lnb, level: level)
|
33
|
+
[:out, node]
|
34
|
+
end
|
35
|
+
|
36
|
+
def _parse_ruby_code_block(match, ctxt:, lnb:, node:)
|
19
37
|
if ctxt == :inc
|
20
38
|
node = node.new_include(lnb: lnb)
|
21
39
|
else
|
22
40
|
node = node.new_example(title: ctxt, lnb: lnb)
|
23
41
|
end
|
24
42
|
[:in, node, (ctxt == :inc ? :includes : :out)]
|
25
|
-
else
|
26
|
-
[:out, node]
|
27
|
-
end
|
28
43
|
end
|
29
44
|
end
|
30
45
|
end
|
31
46
|
end
|
32
47
|
end
|
48
|
+
# SPDX-License-Identifier: Apache-2.0
|
@@ -1,11 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Speculations
|
2
4
|
class Parser
|
3
5
|
module State
|
4
6
|
module In extend self
|
5
|
-
|
6
|
-
def parse line,
|
7
|
+
include State
|
8
|
+
def parse line, lnb, node, ctxt, debug: true
|
7
9
|
case
|
8
10
|
when State.eoblock_match(line)
|
11
|
+
dbg_match("eblock", lnb, debug:)
|
9
12
|
[ctxt, node.parent]
|
10
13
|
else
|
11
14
|
[:in, node.add_line(line), ctxt]
|
@@ -15,3 +18,4 @@ module Speculations
|
|
15
18
|
end
|
16
19
|
end
|
17
20
|
end
|
21
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
@@ -5,13 +5,16 @@ module Speculations
|
|
5
5
|
module Includes extend self
|
6
6
|
include ContextMaker
|
7
7
|
|
8
|
-
def parse line, lnb, node, _ctxt
|
8
|
+
def parse line, lnb, node, _ctxt, debug: true
|
9
9
|
case
|
10
10
|
when match = State.context_match(line)
|
11
|
+
dbg_match("context", lnb, debug:)
|
11
12
|
make_new_context(lnb: lnb, node: node, match: match)
|
12
13
|
when match = State.maybe_include(line)
|
14
|
+
dbg_match("maybe_include", lnb, debug:)
|
13
15
|
[:candidate, node, :inc]
|
14
16
|
when match = State.maybe_example(line)
|
17
|
+
dbg_match("maybe_example", lnb, debug:)
|
15
18
|
[:candidate, node, match[:title]]
|
16
19
|
else
|
17
20
|
[:includes, node]
|
@@ -5,13 +5,17 @@ module Speculations
|
|
5
5
|
module Out extend self
|
6
6
|
include ContextMaker
|
7
7
|
|
8
|
-
def parse line, lnb, node, _ctxt
|
8
|
+
def parse line, lnb, node, _ctxt, debug: false
|
9
|
+
# debug__(msg: "out #{lnb}: #{line}", debug:)
|
9
10
|
case
|
10
11
|
when match = State.context_match(line)
|
12
|
+
dbg_match("context", lnb, debug:)
|
11
13
|
make_new_context(lnb: lnb, node: node, match: match)
|
12
14
|
when match = State.maybe_example(line)
|
15
|
+
dbg_match("maybe_example", lnb, debug:)
|
13
16
|
[:candidate, node, match[:title]]
|
14
17
|
when match = State.maybe_include(line)
|
18
|
+
dbg_match("maybe_include", lnb, debug:)
|
15
19
|
[:candidate, node, :inc]
|
16
20
|
else
|
17
21
|
[:out, node]
|
data/lib/speculations/parser.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../debugging'
|
4
|
+
require_relative './parser/context'
|
5
|
+
require_relative './parser/state'
|
1
6
|
module Speculations
|
2
7
|
class Parser
|
3
|
-
require_relative './parser/context'
|
4
|
-
require_relative './parser/state'
|
5
|
-
|
6
8
|
|
7
9
|
def self.parsers
|
8
10
|
@__parsers__ ||= {
|
@@ -13,13 +15,13 @@ module Speculations
|
|
13
15
|
}
|
14
16
|
end
|
15
17
|
|
16
|
-
def parse_from_file
|
18
|
+
def parse_from_file(file, debug: false)
|
17
19
|
@filename = file
|
18
20
|
@input = File
|
19
21
|
.new(file)
|
20
22
|
.each_line(chomp: true)
|
21
23
|
.lazy
|
22
|
-
parse!
|
24
|
+
parse!(debug:)
|
23
25
|
end
|
24
26
|
|
25
27
|
private
|
@@ -28,14 +30,17 @@ module Speculations
|
|
28
30
|
@state = :out
|
29
31
|
end
|
30
32
|
|
31
|
-
def parse!
|
33
|
+
def parse!(debug:)
|
32
34
|
root = node = Context.new(filename: @filename)
|
33
35
|
ctxt = nil
|
34
36
|
@input.each_with_index do |line, lnb|
|
35
37
|
parser = self.class.parsers.fetch(@state)
|
36
|
-
|
38
|
+
old_state = @state
|
39
|
+
@state, node, ctxt = parser.parse(line, lnb.succ, node, ctxt, debug:)
|
40
|
+
debug__(msg: "#{lnb}: #{old_state}-> #{@state}", debug:) if @state != old_state
|
37
41
|
end
|
38
42
|
root
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
46
|
+
# AGPL-3.0-or-later
|
data/lib/speculations/version.rb
CHANGED
data/lib/speculations.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require_relative 'debugging'
|
2
3
|
require_relative 'speculations/parser'
|
3
4
|
module Speculations extend self
|
4
5
|
|
@@ -7,17 +8,21 @@ module Speculations extend self
|
|
7
8
|
# This file was generated from FILENAME with the speculate_about gem, if you modify this file
|
8
9
|
# one of two bad things will happen
|
9
10
|
# - your documentation specs are not correct
|
10
|
-
# - your modifications will be overwritten by the speculate
|
11
|
+
# - your modifications will be overwritten by the speculate command line
|
11
12
|
# YOU HAVE BEEN WARNED
|
12
13
|
EOD
|
13
14
|
|
14
|
-
def compile(infile, outfile=nil)
|
15
|
+
def compile(infile, outfile=nil, debug: false)
|
15
16
|
raise ArgumentError, "#{infile} not found" unless File.readable? infile
|
16
17
|
outfile ||= _speculation_path(infile)
|
17
18
|
if _out_of_date?(outfile, infile)
|
18
|
-
|
19
|
+
debug__(msg: "recompiling #{infile} -> #{outfile}", debug:)
|
20
|
+
|
21
|
+
ast = Speculations::Parser.new.parse_from_file(infile, debug:)
|
19
22
|
code = _decorated_ast_code ast, infile
|
20
23
|
File.write(outfile, code.join("\n"))
|
24
|
+
else
|
25
|
+
debug__(msg: "#{infile} ignored as it is upto date", debug:)
|
21
26
|
end
|
22
27
|
outfile
|
23
28
|
end
|
@@ -30,7 +35,7 @@ module Speculations extend self
|
|
30
35
|
end
|
31
36
|
|
32
37
|
def _out_of_date?(outf, inf)
|
33
|
-
return true unless File.
|
38
|
+
return true unless File.exist? outf
|
34
39
|
return File.lstat(outf).mtime <= File.lstat(inf).mtime
|
35
40
|
end
|
36
41
|
|
@@ -42,3 +47,4 @@ module Speculations extend self
|
|
42
47
|
File.join(dest_dir, "#{rspec}_spec.rb")
|
43
48
|
end
|
44
49
|
end
|
50
|
+
# SPDX-License-Identifier: Apache-2.0
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: speculate_about
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Allows Markdown or other text files to be used as literal specs, à la
|
14
|
-
|
14
|
+
Elixir doctest, but from any file.
|
15
15
|
email: robert.dober@gmail.com
|
16
16
|
executables:
|
17
17
|
- speculate
|
@@ -19,6 +19,7 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- bin/speculate
|
22
|
+
- lib/debugging.rb
|
22
23
|
- lib/speculate_about.rb
|
23
24
|
- lib/speculations.rb
|
24
25
|
- lib/speculations/cli.rb
|
@@ -34,9 +35,9 @@ files:
|
|
34
35
|
- lib/speculations/parser/state/out.rb
|
35
36
|
- lib/speculations/parser/state/triggers.rb
|
36
37
|
- lib/speculations/version.rb
|
37
|
-
homepage: https://
|
38
|
+
homepage: https://codeberg.org/lab419/speculate_about
|
38
39
|
licenses:
|
39
|
-
-
|
40
|
+
- AGPL-3.0-or-later
|
40
41
|
metadata: {}
|
41
42
|
post_install_message:
|
42
43
|
rdoc_options: []
|
@@ -46,14 +47,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
47
|
requirements:
|
47
48
|
- - ">="
|
48
49
|
- !ruby/object:Gem::Version
|
49
|
-
version: 3.
|
50
|
+
version: 3.3.0
|
50
51
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
53
|
- - ">="
|
53
54
|
- !ruby/object:Gem::Version
|
54
55
|
version: '0'
|
55
56
|
requirements: []
|
56
|
-
rubygems_version: 3.
|
57
|
+
rubygems_version: 3.5.6
|
57
58
|
signing_key:
|
58
59
|
specification_version: 4
|
59
60
|
summary: Extract RSpecs from Markdown
|