speculate_about 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96e9eda6deb236573c353c92c89f44760d2999cba3125bf1e8649d65a4bc1b2f
4
- data.tar.gz: 332f43cee63d821d30fab5a6d55bdfb3e8f262c572ece94a5fedb32df76da35f
3
+ metadata.gz: 3be4eb68d6f767c2a376eaf6e7f680b1f0705fff031648c9e700d5f3000280ed
4
+ data.tar.gz: a9d1aea62f48b208252b0afbc4dab2cf3a3a01bdea7c349ac7e4bca35a110d63
5
5
  SHA512:
6
- metadata.gz: f94c4c30a750cc567462a3d07a54ffdadc96a2ab25ad7455841aca001e9d48d84b79a45d0c3aa814b3c2d43773c974d941cb54ffaf211963c9b7d91860529d69
7
- data.tar.gz: 28989add83923ef511532015ea95cddd91730e874a6fcd30381e3a8138841d4f8bb7b6fa35fe8dfde46495243e4e840f160a2678d910564700572e40af9b0d18
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
@@ -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 args
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, _lnb, node, ctxt
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]
@@ -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 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
- @state, node, ctxt = parser.parse(line, lnb.succ, node, ctxt)
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
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Speculations
2
- VERSION = "1.0.3"
4
+ VERSION = "1.0.4"
3
5
  end
6
+ # SPDX-License-Identifier: AGPL-3.0-or-later
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
- ast = Speculations::Parser.new.parse_from_file(infile)
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.3
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: 2023-08-29 00:00:00.000000000 Z
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
- Elixr doctest, but from any file.
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://github.com/robertdober/speculate
38
+ homepage: https://codeberg.org/lab419/speculate_about
38
39
  licenses:
39
- - Apache-2.0
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.1.0
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.4.19
57
+ rubygems_version: 3.5.6
57
58
  signing_key:
58
59
  specification_version: 4
59
60
  summary: Extract RSpecs from Markdown