speculate_about 1.0.3 → 1.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/debugging.rb +17 -0
- data/lib/speculations/cli.rb +4 -2
- data/lib/speculations/parser/state/candidate.rb +6 -3
- 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 +7 -2
- 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: 3fbc552a8595414d6e1b7dbbe3db1ccd402a641994525e03c80d0ce012b26f61
|
4
|
+
data.tar.gz: 3bad757b061a13ee60055cdda247fb52becf060b5b2a039e6baf1e8ff6901b7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a782e9265dc4c020a49fe602662934fc13bbcffd8c3b101f91f1e3298bfaa66f87c2e215607ec6e59545b8a6a5fb463a5139ec23f019446fd2d2d31057de5d8e
|
7
|
+
data.tar.gz: 5bf85f65b7797da2a3a02e446c2515849d912a1e049166ee32e6c7e1711287694e0f11eaa5c51d3c4545d67314b1b750b90c72f650263a2321f9a252b8c4bf48
|
data/lib/debugging.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
def debug__(subject=nil, msg: nil, rtrn: nil, debug:)
|
5
|
+
return rtrn || subject unless debug
|
6
|
+
|
7
|
+
$stderr.puts(msg) if msg
|
8
|
+
$stderr.puts(subject.inspect) if subject
|
9
|
+
rtrn || subject
|
10
|
+
end
|
11
|
+
|
12
|
+
def dbg_match(msg, lnb, debug:)
|
13
|
+
designation = name.split("::").last.downcase
|
14
|
+
debug__(msg: "#{lnb.succ}: #{msg} match in :#{designation}", debug:)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
# SPDX-License-Identifier: Apache-2.0
|
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,17 +2,22 @@ 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)
|
11
|
+
dbg_match("context", lnb, debug:)
|
10
12
|
_parse_context(match, lnb:, node:)
|
11
13
|
when match = State.maybe_include(line)
|
14
|
+
dbg_match("maybe_include", lnb, debug:)
|
12
15
|
[:candidate, node, :inc]
|
13
16
|
when match = State.maybe_example(line)
|
17
|
+
dbg_match("maybe_example", lnb, debug:)
|
14
18
|
[:candidate, node, match[:title]]
|
15
19
|
when match = State.ruby_code_block(line)
|
20
|
+
dbg_match("ruby_code_block", lnb, debug:)
|
16
21
|
_parse_ruby_code_block(match, ctxt:, lnb:, node:)
|
17
22
|
else
|
18
23
|
[:out, node]
|
@@ -36,8 +41,6 @@ module Speculations
|
|
36
41
|
end
|
37
42
|
[:in, node, (ctxt == :inc ? :includes : :out)]
|
38
43
|
end
|
39
|
-
|
40
|
-
|
41
44
|
end
|
42
45
|
end
|
43
46
|
end
|
@@ -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
|
|
@@ -11,13 +12,17 @@ module Speculations extend self
|
|
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
|
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.5
|
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
|