yoga 0.2.1 → 0.3.0
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/.travis.yml +0 -1
- data/lib/yoga/scanner.rb +26 -14
- data/lib/yoga/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: c9d32e62917dfcbbdd0993469ee617970ab77073
|
4
|
+
data.tar.gz: 5646e21cfdd27da322f1fad4de9af2e71a9474c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9577807b96c3475d6c7848db1e91bd3946d2216f3a9f2d525f5f95e47a6e97fefc7ab0db501feb5c47f68c056d2841b3bc006fdf5f2edc18e9040011f12f31c6
|
7
|
+
data.tar.gz: fb11c522ff6206c6ff75f9c03f301b76f30aab93e19bb891b87cda1ebb89757b0d12e20247237ef4372560717715f5ed20e5ee9ed9ec723aa1bffae1bf4d068b
|
data/.travis.yml
CHANGED
data/lib/yoga/scanner.rb
CHANGED
@@ -91,6 +91,11 @@ module Yoga
|
|
91
91
|
Token.new(kind.freeze, source.freeze, location(source.length))
|
92
92
|
end
|
93
93
|
|
94
|
+
# A regular expression to match all kinds of lines. All of them.
|
95
|
+
#
|
96
|
+
# @return [::Regexp]
|
97
|
+
LINE_MATCHER = /\r\n|\n\r|\n|\r/
|
98
|
+
|
94
99
|
# Attempts to match the given token. The first argument can be a string,
|
95
100
|
# a symbol, or a regular expression. If the matcher is a symbol, it's
|
96
101
|
# coerced into a regular expression, with a forward negative assertion for
|
@@ -98,7 +103,9 @@ module Yoga
|
|
98
103
|
# {#symbol_negative_assertion}). If the matcher is a regular expression,
|
99
104
|
# it is left alone. Otherwise, `#to_s` is called and passed to
|
100
105
|
# `Regexp.escape`. If the text is matched at the current position, a token
|
101
|
-
# is returned; otherwise, nil is returned.
|
106
|
+
# is returned; otherwise, nil is returned. If a newline is matched within
|
107
|
+
# a match, the scanner automatically updates the line and column
|
108
|
+
# information.
|
102
109
|
#
|
103
110
|
# @param matcher [::Symbol, ::Regexp, #to_s]
|
104
111
|
# @param kind [::Symbol] The kind of token to emit. This defaults to a
|
@@ -111,25 +118,18 @@ module Yoga
|
|
111
118
|
else /#{::Regexp.escape(matcher.to_s)}/
|
112
119
|
end
|
113
120
|
|
114
|
-
|
115
|
-
end
|
121
|
+
return unless @scanner.scan(matcher)
|
116
122
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
LINE_MATCHER = /\r\n|\n\r|\n|\r/
|
123
|
+
update_line_information
|
124
|
+
((kind && emit(kind)) || true)
|
125
|
+
end
|
121
126
|
|
122
127
|
# Matches a line. This is separate in order to allow internal logic,
|
123
128
|
# such as line counting and caching, to be performed.
|
124
129
|
#
|
125
130
|
# @return [Boolean] If the line was matched.
|
126
|
-
def match_line(kind
|
127
|
-
|
128
|
-
(required ? (fail UnexpectedCharacterError, location: location) : return) \
|
129
|
-
unless result
|
130
|
-
@line += 1
|
131
|
-
@last_line_at = @scanner.charpos
|
132
|
-
(kind && emit(kind)) || true
|
131
|
+
def match_line(kind = false)
|
132
|
+
match(LINE_MATCHER, kind)
|
133
133
|
end
|
134
134
|
|
135
135
|
# Returns the number of lines that have been covered so far in the scanner.
|
@@ -160,5 +160,17 @@ module Yoga
|
|
160
160
|
def eof_token
|
161
161
|
emit(:EOF, "")
|
162
162
|
end
|
163
|
+
|
164
|
+
# Updates the line information for the scanner. This is called for any
|
165
|
+
# successful matches.
|
166
|
+
#
|
167
|
+
# @api private
|
168
|
+
# @return [void]
|
169
|
+
def update_line_information
|
170
|
+
return unless (lines = @scanner[0].scan(LINE_MATCHER)).any?
|
171
|
+
@line += lines.size
|
172
|
+
@last_line_at =
|
173
|
+
@scanner.string.rindex(LINE_MATCHER, @scanner.charpos) + 1
|
174
|
+
end
|
163
175
|
end
|
164
176
|
end
|
data/lib/yoga/version.rb
CHANGED