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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +10 -0
- data/lib/oedipus_lex.rb +20 -2
- data/test/test_oedipus_lex.rb +24 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61adb0e46462bf1c5bc415fdc1654e216ab490b4
|
4
|
+
data.tar.gz: 04be5ee4d10e6b8829af5af8ddb01f8fd2592bcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a622ea8f3751c1408c5775c47dea719e43da6a5d296cd65ce39ef6b4a0fbf80135de1a290d862eb9d689c93748bb84fb8fc42b5881a67bbf0f065734282e173
|
7
|
+
data.tar.gz: e81ff0a38cb4fbf6e3cac5d6babb3d8652bdc2be385e7995cb2426670aa6f65a52aa5cfb900757045d77c476ce7012cfe01e2f20f247cdb700a557cb30536ee6
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
data/lib/oedipus_lex.rb
CHANGED
@@ -4,7 +4,7 @@ require "erb"
|
|
4
4
|
require "oedipus_lex.rex"
|
5
5
|
|
6
6
|
class OedipusLex
|
7
|
-
VERSION = "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
|
-
|
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
|
data/test/test_oedipus_lex.rb
CHANGED
@@ -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.
|
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-
|
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
|