nrser 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nrser/mean_streak/document.rb +40 -5
- data/lib/nrser/mean_streak.rb +25 -5
- data/lib/nrser/rspex/example_group/describe_called_with.rb +1 -1
- data/lib/nrser/rspex.rb +2 -0
- data/lib/nrser/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6738d85c4a157986e23fb51cac830faf2998666
|
4
|
+
data.tar.gz: b8a22cdcdd8b36a3ae2026440b8b4844d28fb9af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cc98bc014b43e51379d2efb4e51bc50268f97db230fdc3c606e350e27b4666398069c07a35fd2efcfbd52b96097a2e3d82de4ab7ac63273276db5b1293b1482
|
7
|
+
data.tar.gz: 6fa17fd7b7f57e24da23e2807a3d25c0cff307f84e9c7f793b3ece06eff5f92e7b5592aa5a630525890163c75860f13c96946d21f8180edf981ca546320a3483
|
@@ -32,6 +32,16 @@ class NRSER::MeanStreak::Document
|
|
32
32
|
# ======================================================================
|
33
33
|
|
34
34
|
|
35
|
+
# Classes
|
36
|
+
# ============================================================================
|
37
|
+
|
38
|
+
# A position in a source.
|
39
|
+
#
|
40
|
+
class SourcePosition
|
41
|
+
# def initialize source,
|
42
|
+
end
|
43
|
+
|
44
|
+
|
35
45
|
# Class Methods
|
36
46
|
# ======================================================================
|
37
47
|
|
@@ -56,7 +66,6 @@ class NRSER::MeanStreak::Document
|
|
56
66
|
singleton_class.send :alias_method, :from_s, :parse
|
57
67
|
|
58
68
|
|
59
|
-
|
60
69
|
# Attributes
|
61
70
|
# ======================================================================
|
62
71
|
|
@@ -114,17 +123,35 @@ class NRSER::MeanStreak::Document
|
|
114
123
|
end
|
115
124
|
|
116
125
|
|
126
|
+
# @return [Hash<Symbol, Hash<Symbol, Integer>>]
|
127
|
+
# Looks like:
|
128
|
+
#
|
129
|
+
# {
|
130
|
+
# first_byte: {
|
131
|
+
# line: Non-negative Integer,
|
132
|
+
# column: Non-negative Integer,
|
133
|
+
# index: Non-negative Integer,
|
134
|
+
# },
|
135
|
+
# last_byte: {
|
136
|
+
# line: Non-negative Integer,
|
137
|
+
# column: Non-negative Integer,
|
138
|
+
# index: Non-negative Integer,
|
139
|
+
# },
|
140
|
+
# }
|
141
|
+
#
|
142
|
+
# All integers are zero-indexed byte array indexes.
|
143
|
+
#
|
117
144
|
def source_byte_indexes node
|
118
145
|
pos = node.sourcepos
|
119
146
|
|
120
147
|
indexes = {
|
121
148
|
first_byte: {
|
122
|
-
line: pos[:start_line] - 1,
|
123
|
-
column: pos[:start_column] - 1,
|
149
|
+
line: [0, pos[:start_line] - 1].max,
|
150
|
+
column: [0, pos[:start_column] - 1].max,
|
124
151
|
},
|
125
152
|
last_byte: {
|
126
|
-
line: pos[:end_line] - 1,
|
127
|
-
column: pos[:end_column] - 1,
|
153
|
+
line: [0, pos[:end_line] - 1].max,
|
154
|
+
column: [0, pos[:end_column] - 1].max,
|
128
155
|
},
|
129
156
|
}
|
130
157
|
|
@@ -136,7 +163,15 @@ class NRSER::MeanStreak::Document
|
|
136
163
|
end
|
137
164
|
|
138
165
|
|
166
|
+
# Computes the *byte* index for a `line` and `column` in the source, both
|
167
|
+
# of which *are in bytes*.
|
168
|
+
#
|
169
|
+
# @param [Integer] line:
|
170
|
+
#
|
171
|
+
#
|
139
172
|
def source_byte_index line:, column:
|
173
|
+
t.hash_(keys: t.sym, values: t.non_neg_int?).check( line: line, column: column)
|
174
|
+
|
140
175
|
# source_lines[0...line].map( &:bytesize ).reduce( column, :+ )
|
141
176
|
byte_index = column
|
142
177
|
if line > 0
|
data/lib/nrser/mean_streak.rb
CHANGED
@@ -106,14 +106,34 @@ class NRSER::MeanStreak
|
|
106
106
|
end # #parse
|
107
107
|
|
108
108
|
|
109
|
+
# Render a {NRSER::MeanStreak::Document} or a source string.
|
110
|
+
#
|
111
|
+
# @param [NRSER::MeanStreak::Document | String] doc_or_source
|
112
|
+
# Document or source to render.
|
113
|
+
#
|
114
|
+
# @return [String]
|
115
|
+
# Rendered string.
|
116
|
+
#
|
109
117
|
def render doc_or_source
|
110
|
-
|
111
|
-
|
118
|
+
case doc_or_source
|
119
|
+
when NRSER::MeanStreak::Document
|
120
|
+
doc_or_source.render
|
121
|
+
|
122
|
+
when ''
|
123
|
+
# Short-circuit for empty strings because CommonMark's document
|
124
|
+
# node for empty strings returns a weird `#sourcepos` that ends before it
|
125
|
+
# begins (start: line 1, column 1; end: line 0, column 0).
|
126
|
+
#
|
127
|
+
# Going to protect against line 0 / column 0 in
|
128
|
+
# {NRSER::MeanStreak::Document#source_byte_indexes} too but since the
|
129
|
+
# empty strings just renders the empty string we can just return that
|
130
|
+
# here.
|
131
|
+
#
|
132
|
+
''
|
133
|
+
|
112
134
|
else
|
113
|
-
parse doc_or_source
|
135
|
+
parse( doc_or_source ).render
|
114
136
|
end
|
115
|
-
|
116
|
-
doc.render
|
117
137
|
end
|
118
138
|
|
119
139
|
|
data/lib/nrser/rspex.rb
CHANGED
data/lib/nrser/version.rb
CHANGED