oedipus_lex 2.3.2 → 2.4.0

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
  SHA1:
3
- metadata.gz: 2d1d4969de9074724f4c4491ba4ed4e11c49625d
4
- data.tar.gz: db2fff4a5947473754ff79c4b0ea7bce982496d6
3
+ metadata.gz: 61adb0e46462bf1c5bc415fdc1654e216ab490b4
4
+ data.tar.gz: 04be5ee4d10e6b8829af5af8ddb01f8fd2592bcd
5
5
  SHA512:
6
- metadata.gz: 03883e37fc06e56850ded37019c6b500e54d30ee0d455f529d4f5b9fbfe4f31baf053305bd503fa7bbf69ac4bacb11fe0c832128fe1d024d6e7d4c2d7d374f8f
7
- data.tar.gz: ff54b5cb64e1ca96a20c3a6f094ed925dfb845dba5a6e66de5e73925e24a6c5655fa4cb78d283e46f9bb2649ae2b9361377d891b657ee99c2d2dbc27fec977d1
6
+ metadata.gz: 6a622ea8f3751c1408c5775c47dea719e43da6a5d296cd65ce39ef6b4a0fbf80135de1a290d862eb9d689c93748bb84fb8fc42b5881a67bbf0f065734282e173
7
+ data.tar.gz: e81ff0a38cb4fbf6e3cac5d6babb3d8652bdc2be385e7995cb2426670aa6f65a52aa5cfb900757045d77c476ce7012cfe01e2f20f247cdb700a557cb30536ee6
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,13 @@
1
+ === 2.4.0 / 2014-08-29
2
+
3
+ * 1 minor enhancement:
4
+
5
+ * Added column option & accessor.
6
+
7
+ * 1 bug fix:
8
+
9
+ * lineno shouldn't be visible at all if the option isn't on.
10
+
1
11
  === 2.3.2 / 2014-08-06
2
12
 
3
13
  * 1 bug fix:
@@ -4,7 +4,7 @@ require "erb"
4
4
  require "oedipus_lex.rex"
5
5
 
6
6
  class OedipusLex
7
- VERSION = "2.3.2"
7
+ VERSION = "2.4.0"
8
8
 
9
9
  attr_accessor :class_name
10
10
  attr_accessor :header
@@ -20,6 +20,7 @@ class OedipusLex
20
20
  :debug => false,
21
21
  :do_parse => false,
22
22
  :lineno => false,
23
+ :column => false,
23
24
  :stub => false,
24
25
  }
25
26
 
@@ -266,7 +267,9 @@ class OedipusLex
266
267
  % end
267
268
  class ScanError < StandardError ; end
268
269
 
270
+ % if option[:lineno] then
269
271
  attr_accessor :lineno
272
+ % end
270
273
  attr_accessor :filename
271
274
  attr_accessor :ss
272
275
  attr_accessor :state
@@ -283,6 +286,15 @@ class OedipusLex
283
286
  yield
284
287
  end
285
288
 
289
+ % if option[:column] then
290
+ attr_accessor :old_pos
291
+
292
+ def column
293
+ idx = ss.string.rindex("\n", old_pos) || -1
294
+ old_pos - idx - 1
295
+ end
296
+ % end
297
+
286
298
  % if option[:do_parse] then
287
299
  def do_parse
288
300
  while token = next_token do
@@ -299,7 +311,9 @@ class OedipusLex
299
311
 
300
312
  def parse str
301
313
  self.ss = scanner_class.new str
314
+ % if option[:lineno] then
302
315
  self.lineno = 1
316
+ % end
303
317
  self.state ||= nil
304
318
 
305
319
  do_parse
@@ -322,6 +336,9 @@ class OedipusLex
322
336
  until ss.eos? or token do
323
337
  % if option[:lineno] then
324
338
  self.lineno += 1 if ss.peek(1) == "\n"
339
+ % end
340
+ % if option[:column] then
341
+ self.old_pos = ss.pos
325
342
  % end
326
343
  token =
327
344
  case state
@@ -382,7 +399,8 @@ class OedipusLex
382
399
  begin
383
400
  rex.parse_file path
384
401
  rescue
385
- $stderr.printf "%s:%d:%s\n", rex.filename, rex.lineno, $!.message
402
+ lineno = rex.respond_to?(:lineno) ? rex.lineno : -1
403
+ $stderr.printf "%s:%d:%s\n", rex.filename, lineno, $!.message
386
404
  exit 1
387
405
  end
388
406
  end
@@ -260,6 +260,30 @@ class TestOedipusLex < Minitest::Test
260
260
  assert_match "[:op, \"+\"]", out
261
261
  end
262
262
 
263
+ def test_column
264
+ src = <<-'REX'
265
+ class Calculator
266
+ rule
267
+ /\d+/ { [:number, text.to_i, lineno, column] }
268
+ /\s+/
269
+ /[+-]/ { [:op, text, lineno, column] }
270
+ end
271
+ REX
272
+
273
+ txt = "1 + 2\n+ 30"
274
+
275
+ exp = [[:number, 1, 1, 0],
276
+ [:op, "+", 1, 2],
277
+ [:number, 2, 1, 4],
278
+ [:op, "+", 2, 0],
279
+ [:number, 30, 2, 2]]
280
+
281
+ option[:column] = true
282
+ option[:lineno] = true
283
+
284
+ assert_lexer src, txt, exp
285
+ end
286
+
263
287
  def test_simple_scanner_debug_src
264
288
  src = <<-'REX'
265
289
  class Calculator
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oedipus_lex
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -29,7 +29,7 @@ cert_chain:
29
29
  Y4evBVezr3SjXz08vPqRO5YRdO3zfeMT8gBjRqZjWJGMZ2lD4XNfrs7eky74CyZw
30
30
  xx3n58i0lQkBE1EpKE0lFu/y
31
31
  -----END CERTIFICATE-----
32
- date: 2014-08-07 00:00:00.000000000 Z
32
+ date: 2014-08-30 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: minitest
metadata.gz.sig CHANGED
Binary file