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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aac664b4901d0613248ba9cb7169931dfb135480
4
- data.tar.gz: 61185a381b8363cea814da9df4aa948464157523
3
+ metadata.gz: c9d32e62917dfcbbdd0993469ee617970ab77073
4
+ data.tar.gz: 5646e21cfdd27da322f1fad4de9af2e71a9474c9
5
5
  SHA512:
6
- metadata.gz: b7d22c7ba8033a31f4192486775bacbbde86471daca4d4e1ccec55a1b00505c91ed7b3f4f0bc6b02b5d7d7d0692dd2bc437e2a2d9fff8f6e5e65ffdc30a79079
7
- data.tar.gz: 6ee507d8d3e3f989ca55c81211b93c143e8f1a2233280200d6f4db231d2ddccdec97f9b1a3127145ab35b8c3a65904a0f001c8fd76dc56dc8a39cbbe576617a0
6
+ metadata.gz: 9577807b96c3475d6c7848db1e91bd3946d2216f3a9f2d525f5f95e47a6e97fefc7ab0db501feb5c47f68c056d2841b3bc006fdf5f2edc18e9040011f12f31c6
7
+ data.tar.gz: fb11c522ff6206c6ff75f9c03f301b76f30aab93e19bb891b87cda1ebb89757b0d12e20247237ef4372560717715f5ed20e5ee9ed9ec723aa1bffae1bf4d068b
data/.travis.yml CHANGED
@@ -2,7 +2,6 @@ language: ruby
2
2
  rvm:
3
3
  - 2.4.0
4
4
  - 2.2.2
5
- - 2.1.0
6
5
  before_install: gem install bundler
7
6
  install: bundle install
8
7
  script:
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
- ((kind && emit(kind)) || true) if @scanner.scan(matcher)
115
- end
121
+ return unless @scanner.scan(matcher)
116
122
 
117
- # A regular expression to match all kinds of lines. All of them.
118
- #
119
- # @return [::Regexp]
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: false, required: false)
127
- result = @scanner.scan(LINE_MATCHER)
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
@@ -5,5 +5,5 @@ module Yoga
5
5
  # The version of the module.
6
6
  #
7
7
  # @return [::String]
8
- VERSION = "0.2.1"
8
+ VERSION = "0.3.0"
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yoga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Rodi