rebus 0.0.1 → 0.0.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/rebus/compiler.rb +60 -43
- data/lib/rebus/version.rb +1 -1
- data/lib/rebus.rb +4 -5
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c84a583cff147a9d67e9d05c36ad6128c2817bdf7005928027d3b7471bf423a4
|
4
|
+
data.tar.gz: e92be149abc13dfb31cbe5a852fe0931fa1f27a58e17fdc1d35b111410a19416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa6c687117524b028b77d0669001444c0cba83ee660adf3116a68ff1282c8400a30b2c1c23661fd3b279cce8b0f254a503437bf7702830913418da668ac650ea
|
7
|
+
data.tar.gz: 49fb0000f1b1486540b3c3bfa4466b7b03bb284ad8355ca1ff53f4e1b61de78664795625fef490846f65b858103d7ace1db4e97a291c84cb408ca4713694a6e2
|
data/lib/rebus/compiler.rb
CHANGED
@@ -4,24 +4,25 @@ require 'modeling'
|
|
4
4
|
module Rebus
|
5
5
|
class Compiler
|
6
6
|
|
7
|
-
model :code_prefix, :comment_prefix, :context do
|
7
|
+
model :code_prefix, :comment_prefix, :strip_lines, :context do
|
8
8
|
@code_prefix ||= Rebus.code_prefix
|
9
9
|
@comment_prefix ||= Rebus.comment_prefix
|
10
|
-
|
10
|
+
@strip_lines ||= @strip_lines.nil? && Rebus.strip_lines
|
11
11
|
end
|
12
|
-
|
13
|
-
def
|
14
|
-
@
|
15
|
-
@
|
12
|
+
|
13
|
+
def reset
|
14
|
+
@code_mode = true
|
15
|
+
@text_line_begin = "yield <<-\"#{@code_prefix}\".chomp!.chomp\n"
|
16
|
+
@text_line_end = "#{code_prefix}\n"
|
16
17
|
end
|
17
18
|
|
18
19
|
def compile source
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
# yield to ether if no block given
|
21
|
+
return compile(source){} unless block_given?
|
22
|
+
reset
|
22
23
|
parsed = parse source
|
23
24
|
error = nil
|
24
|
-
|
25
|
+
|
25
26
|
begin
|
26
27
|
if source.is_a? File
|
27
28
|
context.instance_eval parsed, source.path
|
@@ -32,7 +33,7 @@ module Rebus
|
|
32
33
|
error = err
|
33
34
|
end
|
34
35
|
if error
|
35
|
-
raise prepare_error error
|
36
|
+
raise prepare_error error, parsed
|
36
37
|
end
|
37
38
|
self
|
38
39
|
end
|
@@ -46,48 +47,51 @@ module Rebus
|
|
46
47
|
else
|
47
48
|
raise "Unsupported source #{source.class}"
|
48
49
|
end
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
result = source
|
51
|
+
.each_line
|
52
|
+
.lazy
|
53
|
+
.map{ parse_line _1 }
|
54
|
+
.compact
|
55
|
+
.reduce{|acc, line| "#{acc}\n#{line}" }
|
56
|
+
result + "\n" + code("")
|
53
57
|
end
|
54
58
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
@string_lines << @current_line + 1
|
66
|
-
@current_line += 3
|
67
|
-
return "yield <<-\"#{@code_prefix}\".chop\n#{$3}\n#{@code_prefix}"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
else # blank line
|
71
|
-
@current_line += 1
|
72
|
-
return "yield ''"
|
59
|
+
private
|
60
|
+
|
61
|
+
def parse_line line
|
62
|
+
stripped = line.strip
|
63
|
+
if stripped.start_with?(@code_prefix) || stripped == @code_prefix.strip
|
64
|
+
code stripped[@code_prefix.length..] || ""
|
65
|
+
elsif stripped.start_with?(@comment_prefix) || stripped == @comment_prefix.strip
|
66
|
+
nil
|
67
|
+
else
|
68
|
+
text @strip_lines ? stripped : line.chomp
|
73
69
|
end
|
74
70
|
end
|
75
71
|
|
76
|
-
|
72
|
+
def text line
|
73
|
+
return line unless @code_mode
|
74
|
+
@code_mode = false
|
75
|
+
"#{@text_line_begin}#{line}"
|
76
|
+
end
|
77
77
|
|
78
|
-
def
|
79
|
-
|
78
|
+
def code line
|
79
|
+
return line if @code_mode
|
80
|
+
@code_mode = true
|
81
|
+
"\n#{@text_line_end}#{line}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def prepare_error error, parsed
|
85
|
+
first_line, lines = *error.message.split("\n", 2)
|
80
86
|
path_regexp = /^(.*:)(\d+):(.*)/
|
81
|
-
if
|
82
|
-
lineno = $2.to_i
|
83
|
-
lineno -= @string_lines.map{ (lineno <=> _1) + 1 }.sum
|
87
|
+
if first_line =~ path_regexp
|
88
|
+
lineno = reduce_error_lineno $2.to_i, parsed
|
84
89
|
backtrace = [$1 + lineno.to_s, *error.backtrace]
|
85
|
-
message = "#{$3}\n#{lines
|
90
|
+
message = "#{$3}\n#{lines}"
|
86
91
|
elsif error.backtrace[0] =~ path_regexp
|
87
|
-
lineno = $2.to_i
|
88
|
-
lineno -= @string_lines.map{ _1 <= lineno ? _1 < lineno ? 2 : 1 : 0 }.sum
|
92
|
+
lineno = reduce_error_lineno $2.to_i, parsed
|
89
93
|
backtrace = [$1 + lineno.to_s, *error.backtrace[1..]]
|
90
|
-
message =
|
94
|
+
message = error.message
|
91
95
|
else
|
92
96
|
backtrace = error.backtrace
|
93
97
|
message = error.message
|
@@ -96,5 +100,18 @@ module Rebus
|
|
96
100
|
new_error.set_backtrace backtrace
|
97
101
|
return new_error
|
98
102
|
end
|
103
|
+
|
104
|
+
def reduce_error_lineno error_lineno, parsed
|
105
|
+
lineno = 0
|
106
|
+
parsed.each_line.each_with_index do |line, i|
|
107
|
+
break if i >= error_lineno
|
108
|
+
if line == @text_line_end
|
109
|
+
lineno -= 1
|
110
|
+
elsif line != @text_line_begin
|
111
|
+
lineno += 1
|
112
|
+
end
|
113
|
+
end
|
114
|
+
lineno
|
115
|
+
end
|
99
116
|
end
|
100
117
|
end
|
data/lib/rebus/version.rb
CHANGED
data/lib/rebus.rb
CHANGED
@@ -3,9 +3,7 @@ require_relative 'rebus/context'
|
|
3
3
|
|
4
4
|
module Rebus
|
5
5
|
class << self
|
6
|
-
attr_accessor :code_prefix
|
7
|
-
attr_accessor :comment_prefix
|
8
|
-
attr_accessor :home
|
6
|
+
attr_accessor :code_prefix, :comment_prefix, :strip_lines, :home
|
9
7
|
|
10
8
|
def compile_file filename, context = nil, **na, &block
|
11
9
|
if !File.absolute_path? filename
|
@@ -45,6 +43,7 @@ module Rebus
|
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
48
|
-
self.code_prefix = "
|
49
|
-
self.comment_prefix = "#
|
46
|
+
self.code_prefix = "$ "
|
47
|
+
self.comment_prefix = "# "
|
48
|
+
self.strip_lines = false
|
50
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rebus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Łukasz Pomietło
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: modeling
|
@@ -16,16 +16,17 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0
|
19
|
+
version: 0.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0
|
27
|
-
description:
|
28
|
-
|
26
|
+
version: 0.1.0
|
27
|
+
description: |
|
28
|
+
Rebus template language compiler based on Ruby dynamic evaluation.
|
29
|
+
Minimalistic and customizable.
|
29
30
|
email: oficjalnyadreslukasza@gmail.com
|
30
31
|
executables: []
|
31
32
|
extensions: []
|
@@ -56,8 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
57
|
- !ruby/object:Gem::Version
|
57
58
|
version: '0'
|
58
59
|
requirements: []
|
59
|
-
rubygems_version: 3.5.
|
60
|
+
rubygems_version: 3.5.23
|
60
61
|
signing_key:
|
61
62
|
specification_version: 4
|
62
|
-
summary:
|
63
|
+
summary: Ruby stencil compiler
|
63
64
|
test_files: []
|